FunctionsTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\VarDumper\Tests\Dumper;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\VarDumper\Cloner\VarCloner;
  13. use Symfony\Component\VarDumper\Dumper\CliDumper;
  14. use Symfony\Component\VarDumper\VarDumper;
  15. class FunctionsTest extends TestCase
  16. {
  17. public function testDumpReturnsFirstArg()
  18. {
  19. $this->setupVarDumper();
  20. $var1 = 'a';
  21. ob_start();
  22. $return = dump($var1);
  23. $out = ob_get_clean();
  24. $this->assertEquals($var1, $return);
  25. }
  26. public function testDumpReturnsAllArgsInArray()
  27. {
  28. $this->setupVarDumper();
  29. $var1 = 'a';
  30. $var2 = 'b';
  31. $var3 = 'c';
  32. ob_start();
  33. $return = dump($var1, $var2, $var3);
  34. $out = ob_get_clean();
  35. $this->assertEquals([$var1, $var2, $var3], $return);
  36. }
  37. protected function setupVarDumper()
  38. {
  39. $cloner = new VarCloner();
  40. $dumper = new CliDumper('php://output');
  41. VarDumper::setHandler(function ($var) use ($cloner, $dumper) {
  42. $dumper->dump($cloner->cloneVar($var));
  43. });
  44. }
  45. }