forked from clue/reactphp-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeferredShellTest.php
More file actions
64 lines (48 loc) · 1.67 KB
/
DeferredShellTest.php
File metadata and controls
64 lines (48 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
use Clue\React\Shell\DeferredShell;
class DeferredShellTest extends TestCase
{
private $stream;
public function setUp()
{
$this->stream = $this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock();
}
public function testExecuteWritesToStream()
{
$this->stream->expects($this->once())->method('write')->with($this->equalTo("echo asd\ndemo\necho asd\n"));
$shell = new DeferredShell($this->stream);
$shell->setEol("\n");
$shell->setBounding('echo asd', "asd\n");
$promise = $shell->execute('demo');
}
public function testEndWillClose()
{
$this->stream->expects($this->once())->method('close');
$shell = new DeferredShell($this->stream);
$shell->end();
return $shell;
}
/**
* @depends testEndWillClose
* @param DeferredShell $shell
*/
public function testEndedExecute(DeferredShell $shell)
{
$this->stream->expects($this->never())->method('write');
$promise = $shell->execute('demo');
$this->expectPromiseReject($promise);
}
public function testInteraction()
{
$this->stream->expects($this->once())->method('write')->with($this->equalTo("echo asd\ndemo\necho asd\n"));
$shell = new DeferredShell($this->stream);
$shell->setEol("\n");
$shell->setBounding('echo asd', "asd\n");
$shell->handleData('premature shell output');
$promise = $shell->execute('demo');
$this->expectPromiseResolveWith("output\n", $promise);
$shell->handleData("as");
$shell->handleData("d\nout");
$shell->handleData("put\nasd\nadditional");
}
}