DumperTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Console\Tests\Helper;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Console\Helper\Dumper;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
  15. class DumperTest extends TestCase
  16. {
  17. use VarDumperTestTrait;
  18. public static function setUpBeforeClass(): void
  19. {
  20. putenv('DUMP_LIGHT_ARRAY=1');
  21. putenv('DUMP_COMMA_SEPARATOR=1');
  22. }
  23. public static function tearDownAfterClass(): void
  24. {
  25. putenv('DUMP_LIGHT_ARRAY');
  26. putenv('DUMP_COMMA_SEPARATOR');
  27. }
  28. /**
  29. * @dataProvider provideVariables
  30. */
  31. public function testInvoke($variable)
  32. {
  33. $output = $this->createMock(OutputInterface::class);
  34. $output->method('isDecorated')->willReturn(false);
  35. $dumper = new Dumper($output);
  36. $this->assertDumpMatchesFormat($dumper($variable), $variable);
  37. }
  38. public static function provideVariables()
  39. {
  40. return [
  41. [null],
  42. [true],
  43. [false],
  44. [1],
  45. [-1.5],
  46. ['string'],
  47. [[1, '2']],
  48. [new \stdClass()],
  49. ];
  50. }
  51. }