8000 [Console] Add a stream helper by louismariegaborit · Pull Request #53518 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Add a stream helper #53518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[VarDumper] Use stream helper and test server:debug command
  • Loading branch information
louismariegaborit committed Jan 15, 2024
commit 20e15938fefde2ba84831407292aae2bc7d5051c
29 changes: 22 additions & 7 deletions src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Cloner\Stub;
use Symfony\Component\VarDumper\Command\Descriptor\CliDescriptor;
use Symfony\Component\VarDumper\Command\Descriptor\DumpDescriptorInterface;
use Symfony\Component\VarDumper\Command\Descriptor\HtmlDescriptor;
Expand Down Expand Up @@ -86,16 +87,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$errorIo = $io->getErrorStyle();
$errorIo->title('Symfony Var Dumper Server');

$this->server->start();
$streamHelper = $this->getHelper('stream');

$errorIo->success(sprintf('Server listening on %s', $this->server->getHost()));
$errorIo->comment('Quit the server with CONTROL-C.');
$streamHelper->listen(
$input,
$output,
$this->server->getHost(),
function (int $clientId, string $message) use ($descriptor, $io) {
$payload = @unserialize(base64_decode($message), ['allowed_classes' => [Data::class, Stub::class]]);

$this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor, $io) {
$descriptor->describe($io, $data, $context, $clientId);
});
// Impossible to decode the message, give up.
if (false === $payload) {
return;
}

return 0;
if (!\is_array($payload) || \count($payload) < 2 || !$payload[0] instanceof Data || !\is_array($payload[1])) {
return;
}
[$data, $context] = $payload;

$descriptor->describe($io, $data, $context, $clientId);
}
);

return Command::SUCCESS;
}

public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
namespace Symfony\Component\VarDumper\Tests\Command;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\StreamHelper;
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Command\ServerDumpCommand;
use Symfony\Component\VarDumper\Server\DumpServer;

Expand All @@ -28,6 +32,24 @@ public function testComplete(array $input, array $expectedSuggestions)
$this->assertSame($expectedSuggestions, $tester->complete($input));
}

public function testServerDumpSuccess()
{
$command = $this->createCommand();
$commandTester = new CommandTester($command);

$data = new Data([['my dump']]);
$input = base64_encode(serialize([$data, ['timestamp' => time(), 'source' => ['name' => 'sourceName', 'line' => 222, 'file' => 'myFile']]]))."\n";

$commandTester->setInputs([$input]);

$commandTester->execute(['--format' => 'html']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this test, I can only use html because value of the dump doesn't be available in the command result. I seems that it be prompt in php stream not in the command.
@ogizanagi Could you help me to add cli format in this test ?


$commandTester->assertCommandIsSuccessful();

$output = $commandTester->getDisplay();
$this->assertStringContainsString('my dump', $output);
}

public static function provideCompletionSuggestions()
{
yield 'option --format' => [
Expand All @@ -38,6 +60,9 @@ public static function provideCompletionSuggestions()

private function createCommand(): ServerDumpCommand
{
return new ServerDumpCommand($this->createMock(DumpServer::class));
$command = new ServerDumpCommand($this->createMock(DumpServer::class));
$command->setHelperSet(new HelperSet([new StreamHelper()]));

return $command;
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/VarDumper/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
},
"require-dev": {
"ext-iconv": "*",
"symfony/console": "^6.4|^7.0",
"symfony/console": "^7.1",
"symfony/http-kernel": "^6.4|^7.0",
"symfony/process": "^6.4|^7.0",
"symfony/uid": "^6.4|^7.0",
"twig/twig": "^3.0.4|^4.0"
},
"conflict": {
"symfony/console": "<6.4"
"symfony/console": "<7.1"
},
"autoload": {
"files": [ "Resources/functions/dump.php" ],
Expand Down
0