Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Messenger][Process] addfromShellCommandline toRunProcessMessage#59768

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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
[Messenger][Process] addfromShellCommandline toRunProcessMessage
Allows using the Process::fromShellCommandline when using a RunProcessMessage
  • Loading branch information
@Staormin
Staormin committedFeb 14, 2025
commite4485966c53c92be405ab13ff3b2c5d6d520c060
6 changes: 6 additions & 0 deletionssrc/Symfony/Component/Process/CHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========


7.3
---

* Add`RunProcessMessage::fromShellCommandline()` to instantiate a Process via the fromShellCommandline method

7.1
---

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,8 @@
*/
class RunProcessMessageimplements \Stringable
{
public ?string$commandLine =null;

publicfunction__construct(
publicreadonlyarray$command,
publicreadonly ?string$cwd =null,
Expand All@@ -27,6 +29,19 @@ public function __construct(

publicfunction__toString():string
{
returnimplode('',$this->command);
return$this->commandLine ??implode('',$this->command);
}

/**
* Create a process message instance that will instantiate a Process using the fromShellCommandline method.
*
* @see Process::fromShellCommandline
*/
publicstaticfunctionfromShellCommandline(string$command, ?string$cwd =null, ?array$env =null,mixed$input =null, ?float$timeout =60):self
{
$message =newself([],$cwd,$env,$input,$timeout);
$message->commandLine =$command;

return$message;
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,10 @@ final class RunProcessMessageHandler
{
public function __invoke(RunProcessMessage $message): RunProcessContext
{
$process = new Process($message->command, $message->cwd, $message->env, $message->input, $message->timeout);
$process = match ($message->commandLine) {
null => new Process($message->command, $message->cwd, $message->env, $message->input, $message->timeout),
default => Process::fromShellCommandline($message->commandLine, $message->cwd, $message->env, $message->input, $message->timeout),
};

try {
return new RunProcessContext($message, $process->mustRun());
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,4 +44,28 @@ public function testRunFailedProcess()

$this->fail('Exception not thrown');
}

public function testRunSuccessfulProcessFromShellCommandline()
{
$context = (new RunProcessMessageHandler())(RunProcessMessage::fromShellCommandline('ls | grep Test', cwd: __DIR__));

$this->assertSame('ls | grep Test', $context->message->commandLine);
$this->assertSame(0, $context->exitCode);
$this->assertStringContainsString(basename(__FILE__), $context->output);
}

public function testRunFailedProcessFromShellCommandline()
{
try {
(new RunProcessMessageHandler())(RunProcessMessage::fromShellCommandline('invalid'));
$this->fail('Exception not thrown');
} catch (RunProcessFailedException $e) {
$this->assertSame('invalid', $e->context->message->commandLine);
$this->assertContains(
$e->context->exitCode,
[null, '\\' === \DIRECTORY_SEPARATOR ? 1 : 127],
'Exit code should be 1 on Windows, 127 on other systems, or null',
);
}
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp