Skip to content

Commit

Permalink
[10.x] Standard Input can be applied to PendingProcess (#46119)
Browse files Browse the repository at this point in the history
* StdInput can be applied to PendingProcess

* Change test

* PHPdoc tags

* clean up

* added space for doc tag

* Fix styles

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
peterfox and taylorotwell authored Feb 15, 2023
1 parent d327eb9 commit a518fde
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
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

0 comments on commit a518fde

Please sign in to comment.