Skip to content

Commit

Permalink
do not let context classes extend the message classes
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Nov 2, 2023
1 parent 6c3d377 commit cfc2c65
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/Symfony/Component/Console/Messenger/RunCommandContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
final class RunCommandContext extends RunCommandMessage
final class RunCommandContext
{
public function __construct(RunCommandMessage $message, public readonly int $exitCode, public readonly string $output)
public function __construct(public readonly RunCommandMessage $message, public readonly int $exitCode, public readonly string $output)
{
parent::__construct($message->input, $message->throwOnFailure, $message->catchExceptions);
}
}
6 changes: 2 additions & 4 deletions src/Symfony/Component/Process/Messenger/RunProcessContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
final class RunProcessContext extends RunProcessMessage
final class RunProcessContext
{
public readonly ?int $exitCode;
public readonly ?string $output;
public readonly ?string $errorOutput;

public function __construct(RunProcessMessage $message, Process $process)
public function __construct(public readonly RunProcessMessage $message, Process $process)
{
parent::__construct($message->command, $message->cwd, $message->env, $message->input, $message->timeout);

$this->exitCode = $process->getExitCode();
$this->output = $process->isOutputDisabled() ? null : $process->getOutput();
$this->errorOutput = $process->isOutputDisabled() ? null : $process->getErrorOutput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testRunSuccessfulProcess()
{
$context = (new RunProcessMessageHandler())(new RunProcessMessage(['ls'], cwd: __DIR__));

$this->assertSame(['ls'], $context->command);
$this->assertSame(['ls'], $context->message->command);
$this->assertSame(0, $context->exitCode);
$this->assertStringContainsString(basename(__FILE__), $context->output);
}
Expand All @@ -32,7 +32,7 @@ public function testRunFailedProcess()
try {
(new RunProcessMessageHandler())(new RunProcessMessage(['invalid']));
} catch (RunProcessFailedException $e) {
$this->assertSame(['invalid'], $e->context->command);
$this->assertSame(['invalid'], $e->context->message->command);
$this->assertSame('\\' === \DIRECTORY_SEPARATOR ? 1 : 127, $e->context->exitCode);

return;
Expand Down

0 comments on commit cfc2c65

Please sign in to comment.