Skip to content

Commit b2b4f27

Browse files
authored
Fix: PHP 7.4 cli logs in stderr (#55)
* tests: simulating the situation of PHP 7.4 stderr output * fix: patch to clean stderr output based on the keywords * chore: adding PHP 7.4 to travis * fix: forgot to wipe the error output after the test
1 parent 30c26d3 commit b2b4f27

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ php:
44
- 7.1
55
- 7.2
66
- 7.3
7+
- 7.4
78

89
before_script:
910
- composer install

src/Server.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,46 @@ private function pollWait()
119119
}
120120
}
121121
}
122+
123+
public function getIncrementalErrorOutput()
124+
{
125+
return self::cleanErrorOutput(parent::getIncrementalErrorOutput());
126+
}
127+
128+
public function getErrorOutput()
129+
{
130+
return self::cleanErrorOutput(parent::getErrorOutput());
131+
}
132+
133+
private static function cleanErrorOutput($output)
134+
{
135+
if (!trim($output)) {
136+
return '';
137+
}
138+
139+
$errorLines = [];
140+
141+
foreach (explode(PHP_EOL, $output) as $line) {
142+
if (!$line) {
143+
continue;
144+
}
145+
146+
if (!self::stringEndsWithAny($line, ['Accepted', 'Closing', ' started'])) {
147+
$errorLines[] = $line;
148+
}
149+
}
150+
151+
return $errorLines ? implode(PHP_EOL, $errorLines) : '';
152+
}
153+
154+
private static function stringEndsWithAny($haystack, array $needles)
155+
{
156+
foreach ($needles as $needle) {
157+
if (substr($haystack, (-1 * strlen($needle))) === $needle) {
158+
return true;
159+
}
160+
}
161+
162+
return false;
163+
}
122164
}

tests/AppIntegrationTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,24 @@ static function ($request) {
207207
$this->assertSame('second', $this->client->get('/')->send()->getBody(true));
208208
}
209209

210+
public function testServerLogsAreNotInErrorOutput()
211+
{
212+
$this->client->delete('/_all');
213+
214+
$expectedServerErrorOutput = '[404]: (null) / - No such file or directory';
215+
216+
self::$server1->addErrorOutput('PHP 7.4.2 Development Server (http://localhost:8086) started' . PHP_EOL);
217+
self::$server1->addErrorOutput('Accepted' . PHP_EOL);
218+
self::$server1->addErrorOutput($expectedServerErrorOutput . PHP_EOL);
219+
self::$server1->addErrorOutput('Closing' . PHP_EOL);
220+
221+
$actualServerErrorOutput = self::$server1->getErrorOutput();
222+
223+
$this->assertEquals($expectedServerErrorOutput, $actualServerErrorOutput);
224+
225+
self::$server1->clearErrorOutput();
226+
}
227+
210228
private function parseRequestFromResponse(GuzzleResponse $response)
211229
{
212230
$body = unserialize($response->getBody());

0 commit comments

Comments
 (0)