diff --git a/.travis.yml b/.travis.yml index da1a4bc..47fe754 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: php php: - 7.2 - 7.3 + - 7.4 before_script: - composer install diff --git a/src/Server.php b/src/Server.php index 3b3b41c..47743d0 100644 --- a/src/Server.php +++ b/src/Server.php @@ -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; + } } diff --git a/tests/AppIntegrationTest.php b/tests/AppIntegrationTest.php index 53d2795..a63e6a4 100644 --- a/tests/AppIntegrationTest.php +++ b/tests/AppIntegrationTest.php @@ -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());