DumperNativeFallbackTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Bridge\PhpUnit\ClassExistsMock;
  13. use Symfony\Component\Console\Helper\Dumper;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\VarDumper\Dumper\CliDumper;
  16. class DumperNativeFallbackTest extends TestCase
  17. {
  18. public static function setUpBeforeClass()
  19. {
  20. ClassExistsMock::register(Dumper::class);
  21. ClassExistsMock::withMockedClasses([
  22. CliDumper::class => false,
  23. ]);
  24. }
  25. public static function tearDownAfterClass()
  26. {
  27. ClassExistsMock::withMockedClasses([]);
  28. }
  29. /**
  30. * @dataProvider provideVariables
  31. */
  32. public function testInvoke($variable, $primitiveString)
  33. {
  34. $dumper = new Dumper($this->getMockBuilder(OutputInterface::class)->getMock());
  35. $this->assertSame($primitiveString, $dumper($variable));
  36. }
  37. public function provideVariables()
  38. {
  39. return [
  40. [null, 'null'],
  41. [true, 'true'],
  42. [false, 'false'],
  43. [1, '1'],
  44. [-1.5, '-1.5'],
  45. ['string', '"string"'],
  46. [[1, '2'], "Array\n(\n [0] => 1\n [1] => 2\n)"],
  47. [new \stdClass(), "stdClass Object\n(\n)"],
  48. ];
  49. }
  50. }