Skip to content

Commit 6b5d87e

Browse files
committed
Improve test suite to skip flaky closed stream tests
1 parent b940022 commit 6b5d87e

1 file changed

Lines changed: 29 additions & 26 deletions

File tree

tests/FunctionalExampleTest.php

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,51 @@ public function testPeriodicExampleWithSleepNoInputQuitsOnEnd()
3232
$this->assertNotContainsString('you just said:', $output);
3333
}
3434

35-
public function testPeriodicExampleWithClosedInputQuitsImmediately()
35+
public function testStubReportsStdinIsReadableByDefault()
3636
{
37-
if (getenv('CI') === 'true' && (defined('HHVM_VERSION') || PHP_VERSION_ID >= 70000)) {
38-
$this->markTestSkipped('Test fails for Github CI with PHP >= 7.0 and HHVM');
39-
}
37+
$output = $this->execExample('php ../tests/stub/01-check-stdin.php');
38+
39+
$this->assertContainsString('YES', $output);
40+
}
4041

42+
public function testStubReportsStdinIsNotReadableWithoutDescriptor()
43+
{
4144
if (PHP_VERSION_ID === 80108 || PHP_VERSION_ID === 80107 || PHP_VERSION_ID === 80020) {
4245
$this->markTestSkipped('Skip bugged PHP version: https://github.com/php/php-src/issues/8827');
4346
}
4447

45-
$output = $this->execExample('php 01-periodic.php <&-');
48+
$output = $this->execExample('php ../tests/stub/01-check-stdin.php <&-');
4649

47-
if (strpos($output, 'said') !== false) {
48-
$this->markTestIncomplete('Your platform exhibits a closed STDIN bug, this may need some further debugging');
50+
// Closing STDIN frees file descriptor 0, which may then be reused by an
51+
// internal stream descriptor so STDIN no longer refers to the console and
52+
// is wrongly reported as readable. This is platform- and PHP-version
53+
// dependent (see https://github.com/php/php-src/issues/8827). Skip here
54+
// (and the dependent tests via @depends) when this platform does not
55+
// report the closed STDIN as unreadable.
56+
if (strpos($output, 'NO') === false) {
57+
$this->markTestSkipped('Closed STDIN is not reliably detectable on this platform (file descriptor 0 reused)');
4958
}
5059

51-
$this->assertNotContainsString('you just said:', $output);
60+
$this->assertContainsString('NO', $output);
5261
}
5362

54-
public function testPeriodicExampleWithClosedInputAndOutputQuitsImmediatelyWithoutOutput()
63+
/**
64+
* @depends testStubReportsStdinIsNotReadableWithoutDescriptor
65+
*/
66+
public function testPeriodicExampleWithClosedInputQuitsImmediately()
5567
{
56-
if (getenv('CI') === 'true' && (defined('HHVM_VERSION') || PHP_VERSION_ID >= 70000)) {
57-
$this->markTestSkipped('Test fails for Github CI with PHP >= 7.0 and HHVM');
58-
}
68+
$output = $this->execExample('php 01-periodic.php <&-');
5969

60-
if (PHP_VERSION_ID === 80108 || PHP_VERSION_ID === 80107 || PHP_VERSION_ID === 80020) {
61-
$this->markTestSkipped('Skip bugged PHP version: https://github.com/php/php-src/issues/8827');
62-
}
70+
$this->assertNotContainsString('you just said:', $output);
71+
}
6372

73+
/**
74+
* @depends testPeriodicExampleWithClosedInputQuitsImmediately
75+
*/
76+
public function testPeriodicExampleWithClosedInputAndOutputQuitsImmediatelyWithoutOutput()
77+
{
6478
$output = $this->execExample('php 01-periodic.php <&- >&- 2>&-');
6579

66-
if (strpos($output, 'said') !== false) {
67-
$this->markTestIncomplete('Your platform exhibits a closed STDIN bug, this may need some further debugging');
68-
}
69-
7080
$this->assertEquals('', $output);
7181
}
7282

@@ -84,13 +94,6 @@ public function testBindingsExampleWithPipedInputEndsWithSpecialBindingsReplaced
8494
$this->assertContainsString('you just said: hellö (6)' . PHP_EOL, $output);
8595
}
8696

87-
public function testStubShowStdinIsReadableByDefault()
88-
{
89-
$output = $this->execExample('php ../tests/stub/01-check-stdin.php');
90-
91-
$this->assertContainsString('YES', $output);
92-
}
93-
9497
public function testStubCanCloseStdinAndIsNotReadable()
9598
{
9699
$output = $this->execExample('php ../tests/stub/02-close-stdin.php');

0 commit comments

Comments
 (0)