Skip to content

Commit ed93802

Browse files
authored
Merge pull request #10 from gabfr/fix/php-74-cli-logs
Fix: PHP 7.4 cli logs in stderr output
2 parents 8e15651 + 435f11a commit ed93802

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ language: php
33
php:
44
- 7.2
55
- 7.3
6+
- 7.4
67

78
before_script:
89
- composer install

src/Server.php

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

tests/AppIntegrationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ static function ($request) {
235235
$this->assertSame('second', $this->client->get('/')->getBody()->getContents());
236236
}
237237

238+
public function testServerLogsAreNotInErrorOutput()
239+
{
240+
$this->client->delete('/_all');
241+
242+
$expectedServerErrorOutput = '[404]: (null) / - No such file or directory';
243+
244+
self::$server1->addErrorOutput('PHP 7.4.2 Development Server (http://localhost:8086) started' . PHP_EOL);
245+
self::$server1->addErrorOutput('Accepted' . PHP_EOL);
246+
self::$server1->addErrorOutput($expectedServerErrorOutput . PHP_EOL);
247+
self::$server1->addErrorOutput('Closing' . PHP_EOL);
248+
249+
$actualServerErrorOutput = self::$server1->getErrorOutput();
250+
251+
$this->assertEquals($expectedServerErrorOutput, $actualServerErrorOutput);
252+
}
253+
238254
private function parseRequestFromResponse(ResponseInterface $response)
239255
{
240256
$body = unserialize($response->getBody());

0 commit comments

Comments
 (0)