Skip to content
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