8000 [Console] Remove `Process::fromShellCommandline()` detection by derrabus · Pull Request #51611 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Remove Process::fromShellCommandline() detection #51611

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

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Changes from all commits
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
[Console] Remove Process::fromShellCommandline() detection
  • Loading branch information
derrabus committed Sep 10, 2023
commit 12ee32db315aa8a89c4a3054beefac7310a1fc68
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class ProcessHelperTest extends TestCase
/**
* @dataProvider provideCommandsAndOutput
*/
public function testVariousProcessRuns($expected, $cmd, $verbosity, $error)
public function testVariousProcessRuns(string $expected, Process|string|array $cmd, int $verbosity, ?string $error)
{
if (\is_string($cmd)) {
$cmd = method_exists(Process::class, 'fromShellCommandline') ? Process::fromShellCommandline($cmd) : new Process($cmd);
$cmd = Process::fromShellCommandline($cmd);
}

$helper = new ProcessHelper();
Expand All @@ -49,7 +49,7 @@ public function testPassedCallbackIsExecuted()
$this->assertTrue($executed);
}

public static function provideCommandsAndOutput()
public static function provideCommandsAndOutput(): array
{
$successOutputVerbose = <<<'EOT'
RUN php -r "echo 42;"
Expand Down Expand Up @@ -99,7 +99,6 @@ public static function provideCommandsAndOutput()
$args = new Process(['php', '-r', 'echo 42;']);
$args = $args->getCommandLine();
$successOutputProcessDebug = str_replace("'php' '-r' 'echo 42;'", $args, $successOutputProcessDebug);
$fromShellCommandline = method_exists(Process::class, 'fromShellCommandline') ? [Process::class, 'fromShellCommandline'] : fn ($cmd) => new Process($cmd);

return [
['', 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERBOSE, null],
Expand All @@ -113,18 +112,18 @@ public static function provideCommandsAndOutput()
[$syntaxErrorOutputVerbose.$errorMessage.\PHP_EOL, 'php -r "fwrite(STDERR, \'error message\');usleep(50000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_VERY_VERBOSE, $errorMessage],
[$syntaxErrorOutputDebug.$errorMessage.\PHP_EOL, 'php -r "fwrite(STDERR, \'error message\');usleep(500000);fwrite(STDOUT, \'out message\');exit(252);"', StreamOutput::VERBOSITY_DEBUG, $errorMessage],
[$successOutputProcessDebug, ['php', '-r', 'echo 42;'], StreamOutput::VERBOSITY_DEBUG, null],
[$successOutputDebug, $fromShellCommandline('php -r "echo 42;"'), StreamOutput::VERBOSITY_DEBUG, null],
[$successOutputDebug, Process::fromShellCommandline('php -r "echo 42;"'), StreamOutput::VERBOSITY_DEBUG, null],
[$successOutputProcessDebug, [new Process(['php', '-r', 'echo 42;'])], StreamOutput::VERBOSITY_DEBUG, null],
[$successOutputPhp, [$fromShellCommandline('php -r '.$PHP), 'PHP' => 'echo 42;'], StreamOutput::VERBOSITY_DEBUG, null],
[$successOutputPhp, [Process::fromShellCommandline('php -r '.$PHP), 'PHP' => 'e 64C4 cho 42;'], StreamOutput::VERBOSITY_DEBUG, null],
];
}

private function getOutputStream($verbosity)
private function getOutputStream($verbosity): StreamOutput
{
return new StreamOutput(fopen('php://memory', 'r+', false), $verbosity, false);
}

private function getOutput(StreamOutput $output)
private function getOutput(StreamOutput $output): string
{
rewind($output->getStream());

Expand Down
0