Skip to content
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

[10.x] Standard Input can be applied to PendingProcess #46119

Merged
merged 7 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions src/Illuminate/Process/PendingProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class PendingProcess
*/
public $environment = [];

/**
* The standard input data that should be piped into the command.
*
* @var string|int|float|bool|resource|\Traversable|null
*/
public $input;

/**
* Indicates whether output should be disabled for the process.
*
Expand Down Expand Up @@ -170,6 +177,19 @@ public function env(array $environment)
return $this;
}

/**
* Set the standard input that should be provided when invoking the process.
*
* @param \Traversable|resource|string|int|float|bool|null $input
* @return $this
*/
public function input($input)
{
$this->input = $input;

return $this;
}

/**
* Disable output for the process.
*
Expand Down Expand Up @@ -281,6 +301,10 @@ protected function toSymfonyProcess(array|string|null $command)
$process->setIdleTimeout($this->idleTimeout);
}

if ($this->input) {
$process->setInput($this->input);
}

if ($this->quietly) {
$process->disableOutput();
}
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/Facades/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @method static \Illuminate\Process\PendingProcess quietly()
* @method static \Illuminate\Process\PendingProcess tty(bool $tty = true)
* @method static \Illuminate\Process\PendingProcess options(array $options)
* @method static \Illuminate\Process\PendingProcess input(\Traversable|resource|string|int|float|bool|null $input)
* @method static \Illuminate\Contracts\Process\ProcessResult run(array|string|null $command = null, callable|null $output = null)
* @method static \Illuminate\Process\InvokedProcess start(array|string|null $command = null, callable $output = null)
* @method static \Illuminate\Process\PendingProcess withFakeHandlers(array $fakeHandlers)
Expand Down
12 changes: 12 additions & 0 deletions tests/Process/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,18 @@ public function testRealProcessesDoesntThrowIfFalse()
$this->assertTrue(true);
}

public function testRealProcessesCanUseStandardInput()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$factory = new Factory();
$result = $factory->input('foobar')->run('cat');

$this->assertSame('foobar', $result->output());
}

public function testFakeInvokedProcessOutputWithLatestOutput()
{
$factory = new Factory;
Expand Down