Skip to content

Commit

Permalink
bug #52427 [Console][Process] do not let context classes extend the m…
Browse files Browse the repository at this point in the history
…essage classes (xabbuh)

This PR was merged into the 6.4 branch.

Discussion
----------

[Console][Process] do not let context classes extend the message classes

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

Commits
-------

d96479d do not let context classes extend the message classes
  • Loading branch information
nicolas-grekas committed Nov 2, 2023
2 parents 6c3d377 + d96479d commit 8b13301
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/Symfony/Component/Console/Messenger/RunCommandContext.php
Expand Up @@ -14,10 +14,12 @@
/**
* @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)
{
parent::__construct($message->input, $message->throwOnFailure, $message->catchExceptions);
public function __construct(
public readonly RunCommandMessage $message,
public readonly int $exitCode,
public readonly string $output,
) {
}
}
10 changes: 5 additions & 5 deletions src/Symfony/Component/Process/Messenger/RunProcessContext.php
Expand Up @@ -16,16 +16,16 @@
/**
* @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)
{
parent::__construct($message->command, $message->cwd, $message->env, $message->input, $message->timeout);

public function __construct(
public readonly RunProcessMessage $message,
Process $process,
) {
$this->exitCode = $process->getExitCode();
$this->output = $process->isOutputDisabled() ? null : $process->getOutput();
$this->errorOutput = $process->isOutputDisabled() ? null : $process->getErrorOutput();
Expand Down
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 8b13301

Please sign in to comment.