* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\VarDumper\Tests\Command\Descriptor; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\VarDumper\Cloner\Data; use Symfony\Component\VarDumper\Command\Descriptor\HtmlDescriptor; use Symfony\Component\VarDumper\Dumper\HtmlDumper; class HtmlDescriptorTest extends TestCase { private static $timezone; public static function setUpBeforeClass() { self::$timezone = date_default_timezone_get(); date_default_timezone_set('UTC'); } public static function tearDownAfterClass() { date_default_timezone_set(self::$timezone); } public function testItOutputsStylesAndScriptsOnFirstDescribeCall() { $output = new BufferedOutput(); $dumper = $this->createMock(HtmlDumper::class); $dumper->method('dump')->willReturn('[DUMPED]'); $descriptor = new HtmlDescriptor($dumper); $descriptor->describe($output, new Data([[123]]), ['timestamp' => 1544804268.3668], 1); $this->assertStringMatchesFormat('%A', $output->fetch(), 'styles & scripts are output'); $descriptor->describe($output, new Data([[123]]), ['timestamp' => 1544804268.3668], 1); $this->assertStringNotMatchesFormat('%A', $output->fetch(), 'styles & scripts are output only once'); } /** * @dataProvider provideContext */ public function testDescribe(array $context, string $expectedOutput) { $output = new BufferedOutput(); $dumper = $this->createMock(HtmlDumper::class); $dumper->method('dump')->willReturn('[DUMPED]'); $descriptor = new HtmlDescriptor($dumper); $descriptor->describe($output, new Data([[123]]), $context + ['timestamp' => 1544804268.3668], 1); $this->assertStringMatchesFormat(trim($expectedOutput), trim(preg_replace('@@s', '', $output->fetch()))); } public function provideContext() { yield 'source' => [ [ 'source' => [ 'name' => 'CliDescriptorTest.php', 'line' => 30, 'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php', ], ], <<

-

CliDescriptorTest.php on line 30

[DUMPED]
TXT ]; yield 'source full' => [ [ 'source' => [ 'name' => 'CliDescriptorTest.php', 'project_dir' => 'src/Symfony/', 'line' => 30, 'file_relative' => 'src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php', 'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php', 'file_link' => 'phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30', ], ], <<

-

  • project dirsrc/Symfony/

CliDescriptorTest.php on line 30

[DUMPED]
TXT ]; yield 'cli' => [ [ 'cli' => [ 'identifier' => 'd8bece1c', 'command_line' => 'bin/phpunit', ], ], <<

$ bin/phpunit

[DUMPED]
TXT ]; yield 'request' => [ [ 'request' => [ 'identifier' => 'd8bece1c', 'controller' => new Data([['FooController.php']]), 'method' => 'GET', 'uri' => 'http://localhost/foo', ], ], <<

GET http://localhost/foo

  • controller[DUMPED]

[DUMPED]
TXT ]; } }