Skip to content

Commit baa7273

Browse files
committed
Merge pull request #1 from clue-labs/process
ProcessLauncher now also accepts a Process instance
2 parents 8adcd13 + 49d9565 commit baa7273

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/ProcessLauncher.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ public function __construct(LoopInterface $loop)
2525
* If the command prints output to STDERR, make sure to redirect it to
2626
* STDOUT by appending " 2>&1".
2727
*
28-
* @param string $command
28+
* @param string|Process $process accepts either a command string to execute or a Process instance
2929
* @return DeferredShell
3030
*/
31-
public function createDeferredShell($command)
31+
public function createDeferredShell($process)
3232
{
33-
$process = new Process($command);
33+
if (!($process instanceof Process)) {
34+
$process = new Process($process);
35+
}
36+
3437
$process->start($this->loop);
3538

3639
$stream = new CompositeStream($process->stdout, $process->stdin);

tests/ProcessLauncherTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Clue\React\Shell\ProcessLauncher;
4+
5+
class ProcessLauncherTest extends TestCase
6+
{
7+
private $loop;
8+
private $processLauncher;
9+
10+
public function setUp()
11+
{
12+
$this->loop = $this->getMock('React\EventLoop\LoopInterface');
13+
$this->processLauncher = new ProcessLauncher($this->loop);
14+
}
15+
16+
public function testProcessWillBeStarted()
17+
{
18+
$process = $this->getMockBuilder('React\ChildProcess\Process')->disableOriginalConstructor()->getMock();
19+
$process->stdout = $this->getMock('React\Stream\ReadableStreamInterface');
20+
$process->stdin = $this->getMock('React\Stream\WritableStreamInterface');
21+
22+
$process->expects($this->once())->method('start');
23+
24+
$shell = $this->processLauncher->createDeferredShell($process);
25+
26+
$this->assertInstanceOf('Clue\React\Shell\DeferredShell', $shell);
27+
}
28+
}

0 commit comments

Comments
 (0)