* * 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\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\VarDumper\Cloner\Data; use Symfony\Component\VarDumper\Command\Descriptor\CliDescriptor; use Symfony\Component\VarDumper\Dumper\CliDumper; class CliDescriptorTest extends TestCase { private static $timezone; private static $prevTerminalEmulator; public static function setUpBeforeClass() { self::$timezone = date_default_timezone_get(); date_default_timezone_set('UTC'); self::$prevTerminalEmulator = getenv('TERMINAL_EMULATOR'); putenv('TERMINAL_EMULATOR'); } public static function tearDownAfterClass() { date_default_timezone_set(self::$timezone); putenv('TERMINAL_EMULATOR'.(self::$prevTerminalEmulator ? '='.self::$prevTerminalEmulator : '')); } /** * @dataProvider provideContext */ public function testDescribe(array $context, string $expectedOutput, bool $decorated = false) { $output = new BufferedOutput(); $output->setDecorated($decorated); $descriptor = new CliDescriptor(new CliDumper(function ($s) { return $s; })); $descriptor->describe($output, new Data([[123]]), $context + ['timestamp' => 1544804268.3668], 1); $this->assertStringMatchesFormat(trim($expectedOutput), str_replace(PHP_EOL, "\n", trim($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', ], ], << [ [ 'source' => [ 'name' => 'CliDescriptorTest.php', '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', ], ], method_exists(OutputFormatterStyle::class, 'setHref') ? << [ [ 'source' => [ 'name' => 'CliDescriptorTest.php', 'line' => 30, 'file_relative' => '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', ], ], << [ [ 'cli' => [ 'identifier' => 'd8bece1c', 'command_line' => 'bin/phpunit', ], ], << [ [ 'request' => [ 'identifier' => 'd8bece1c', 'controller' => new Data([['FooController.php']]), 'method' => 'GET', 'uri' => 'http://localhost/foo', ], ], <<