Skip to content

Fix: PHP 7.4 cli logs in stderr output #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: php
php:
- 7.2
- 7.3
- 7.4

before_script:
- composer install
Expand Down
42 changes: 42 additions & 0 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,46 @@ private function pollWait()
}
}
}

public function getIncrementalErrorOutput()
{
return self::cleanErrorOutput(parent::getIncrementalErrorOutput());
}

public function getErrorOutput()
{
return self::cleanErrorOutput(parent::getErrorOutput());
}

private static function cleanErrorOutput($output)
{
if (!trim($output)) {
return '';
}

$errorLines = [];

foreach (explode(PHP_EOL, $output) as $line) {
if (!$line) {
continue;
}

if (!self::stringEndsWithAny($line, ['Accepted', 'Closing', ' started'])) {
$errorLines[] = $line;
}
}

return $errorLines ? implode(PHP_EOL, $errorLines) : '';
}

private static function stringEndsWithAny($haystack, array $needles)
{
foreach ($needles as $needle) {
if (substr($haystack, (-1 * strlen($needle))) === $needle) {
return true;
}
}

return false;
}
}
16 changes: 16 additions & 0 deletions tests/AppIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ static function ($request) {
$this->assertSame('second', $this->client->get('/')->getBody()->getContents());
}

public function testServerLogsAreNotInErrorOutput()
{
$this->client->delete('/_all');

$expectedServerErrorOutput = '[404]: (null) / - No such file or directory';

self::$server1->addErrorOutput('PHP 7.4.2 Development Server (http://localhost:8086) started' . PHP_EOL);
self::$server1->addErrorOutput('Accepted' . PHP_EOL);
self::$server1->addErrorOutput($expectedServerErrorOutput . PHP_EOL);
self::$server1->addErrorOutput('Closing' . PHP_EOL);

$actualServerErrorOutput = self::$server1->getErrorOutput();

$this->assertEquals($expectedServerErrorOutput, $actualServerErrorOutput);
}

private function parseRequestFromResponse(ResponseInterface $response)
{
$body = unserialize($response->getBody());
Expand Down