123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * 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',
- ],
- ],
- <<<TXT
- Received from client #1
- -----------------------
- -------- ---------------------------------------------------------------------------------------------------
- date Fri, 14 Dec 2018 16:17:48 +0000
- source CliDescriptorTest.php on line 30
- file /Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php
- -------- ---------------------------------------------------------------------------------------------------
- TXT
- ];
- yield 'source full' => [
- [
- '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') ?
- <<<TXT
- Received from client #1
- -----------------------
- -------- --------------------------------------------------------------------------------
- date Fri, 14 Dec 2018 16:17:48 +0000
- source CliDescriptorTest.php on line 30
- file src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php
- -------- --------------------------------------------------------------------------------
- TXT
- :
- <<<TXT
- Received from client #1
- -----------------------
- -------- --------------------------------------------------------------------------------
- date Fri, 14 Dec 2018 16:17:48 +0000
- source CliDescriptorTest.php on line 30
- file src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php
- -------- --------------------------------------------------------------------------------
- Open source in your IDE/browser:
- phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30
- TXT
- ];
- if (method_exists(OutputFormatterStyle::class, 'setHref')) {
- yield 'source with hyperlink' => [
- [
- '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',
- ],
- ],
- <<<TXT
- %A
- source \033]8;;phpstorm://open?file=/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php&line=30\033\CliDescriptorTest.php on line 30\033]8;;\033%A
- %A
- TXT
- , true,
- ];
- }
- yield 'cli' => [
- [
- 'cli' => [
- 'identifier' => 'd8bece1c',
- 'command_line' => 'bin/phpunit',
- ],
- ],
- <<<TXT
- $ bin/phpunit
- -------------
- ------ ---------------------------------
- date Fri, 14 Dec 2018 16:17:48 +0000
- ------ ---------------------------------
- TXT
- ];
- yield 'request' => [
- [
- 'request' => [
- 'identifier' => 'd8bece1c',
- 'controller' => new Data([['FooController.php']]),
- 'method' => 'GET',
- 'uri' => 'http://localhost/foo',
- ],
- ],
- <<<TXT
- GET http://localhost/foo
- ------------------------
- ------------ ---------------------------------
- date Fri, 14 Dec 2018 16:17:48 +0000
- controller "FooController.php"
- ------------ ---------------------------------
- TXT
- ];
- }
- }
|