Repository navigation
Expand file tree
/
Copy pathFunctionalExampleTest.php
More file actions
144 lines (108 loc) · 4.8 KB
/
Copy pathFunctionalExampleTest.php
File metadata and controls
144 lines (108 loc) · 4.8 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
namespace Clue\Tests\React\Stdio;
class FunctionalExampleTest extends TestCase
{
public function testPeriodicExampleWithPipedInputEndsBecauseInputEnds()
{
$output = $this->execExample('echo hello | php 01-periodic.php');
$this->assertContainsString('you just said: hello\n', $output);
}
public function testPeriodicExampleWithNullInputQuitsImmediately()
{
$output = $this->execExample('php 01-periodic.php < /dev/null');
$this->assertNotContainsString('you just said:', $output);
}
public function testPeriodicExampleWithNoInputQuitsImmediately()
{
$output = $this->execExample('true | php 01-periodic.php');
$this->assertNotContainsString('you just said:', $output);
}
public function testPeriodicExampleWithSleepNoInputQuitsOnEnd()
{
$output = $this->execExample('sleep 0.1 | php 01-periodic.php');
$this->assertNotContainsString('you just said:', $output);
}
public function testStubReportsStdinIsReadableByDefault()
{
$output = $this->execExample('php ../tests/stub/01-check-stdin.php');
$this->assertContainsString('YES', $output);
}
public function testStubReportsStdinIsNotReadableWithoutDescriptor()
{
if (PHP_VERSION_ID === 80108 || PHP_VERSION_ID === 80107 || PHP_VERSION_ID === 80020) {
$this->markTestSkipped('Skip bugged PHP version: https://github.com/php/php-src/issues/8827');
}
$output = $this->execExample('php ../tests/stub/01-check-stdin.php <&-');
// Closing STDIN frees file descriptor 0, which may then be reused by an
// internal stream descriptor so STDIN no longer refers to the console and
// is wrongly reported as readable. This is platform- and PHP-version
// dependent (see https://github.com/php/php-src/issues/8827). Skip here
// (and the dependent tests via @depends) when this platform does not
// report the closed STDIN as unreadable.
if (strpos($output, 'NO') === false) {
$this->markTestSkipped('Closed STDIN is not reliably detectable on this platform (file descriptor 0 reused)');
}
$this->assertContainsString('NO', $output);
}
/**
* @depends testStubReportsStdinIsNotReadableWithoutDescriptor
*/
public function testPeriodicExampleWithClosedInputQuitsImmediately()
{
$output = $this->execExample('php 01-periodic.php <&-');
$this->assertNotContainsString('you just said:', $output);
}
/**
* @depends testPeriodicExampleWithClosedInputQuitsImmediately
*/
public function testPeriodicExampleWithClosedInputAndOutputQuitsImmediatelyWithoutOutput()
{
$output = $this->execExample('php 01-periodic.php <&- >&- 2>&-');
$this->assertEquals('', $output);
}
public function testBindingsExampleWithPipedInputEndsBecauseInputEnds()
{
$output = $this->execExample('echo test | php 04-bindings.php');
$this->assertContainsString('you just said: test (4)' . PHP_EOL, $output);
}
public function testBindingsExampleWithPipedInputEndsWithSpecialBindingsReplacedBecauseInputEnds()
{
$output = $this->execExample('echo hello | php 04-bindings.php');
$this->assertContainsString('you just said: hellö (6)' . PHP_EOL, $output);
}
public function testStubCanCloseStdinAndIsNotReadable()
{
$output = $this->execExample('php ../tests/stub/02-close-stdin.php');
$this->assertContainsString('NO', $output);
}
public function testStubCanCloseStdoutAndIsNotWritable()
{
$output = $this->execExample('php ../tests/stub/03-close-stdout.php 2>&1');
$this->assertEquals('', $output);
}
public function testStubCanEndWithoutOutput()
{
$output = $this->execExample('php ../tests/stub/04-end.php < /dev/null');
$this->assertEquals('', $output);
}
public function testStubCanEndWithoutReadlineFunctions()
{
$output = $this->execExample('php -d disable_functions=readline_callback_handler_install,readline_callback_handler_remove ../tests/stub/04-end.php');
$this->assertEquals('', $output);
}
public function testPeriodicExampleViaInteractiveModeQuitsImmediately()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Skipped interactive mode on HHVM');
}
$output = $this->execExample('echo "require(\"01-periodic.php\");" | php -a');
// starts with either "Interactive mode enabled" or "Interactive shell"
$this->assertStringStartsWith('Interactive ', $output);
$this->assertNotContainsString('you just said:', $output);
}
private function execExample($command)
{
chdir(__DIR__ . '/../examples/');
return shell_exec($command);
}
}