From e8bbb27042a2ecce35944d5a460607e9e901deb1 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 24 Feb 2020 20:14:26 -0300 Subject: [PATCH 1/5] tests: simulating the situation of PHP 7.4 stderr output --- tests/AppIntegrationTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/AppIntegrationTest.php b/tests/AppIntegrationTest.php index 53d2795..c47d93d 100644 --- a/tests/AppIntegrationTest.php +++ b/tests/AppIntegrationTest.php @@ -235,6 +235,19 @@ static function ($request) { $this->assertSame('second', $this->client->get('/')->getBody()->getContents()); } + public function testServerLogsAreNotInErrorOutput() + { + $expectedErrorOutput = '[Sun Feb 23 10:18:43 2020] [::1]:55146 [404]: (null) / - No such file or directory'; + $serverLogsExample = '[Sun Feb 23 10:18:31 2020] PHP 7.4.2 Development Server (http://localhost:8086) started' . PHP_EOL . + '[Sun Feb 23 10:18:43 2020] [::1]:55146 Accepted' . PHP_EOL . + $expectedErrorOutput . PHP_EOL . + '[Sun Feb 23 10:18:43 2020] [::1]:55146 Closing' . PHP_EOL; + + $cleanedServerLogs = Server::cleanErrorOutput($serverLogsExample); + + $this->assertEquals($expectedErrorOutput, $cleanedServerLogs); + } + private function parseRequestFromResponse(ResponseInterface $response) { $body = unserialize($response->getBody()); From 8400ebc7b5feaaa093dd8b622884ff7e158be0d3 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 24 Feb 2020 20:24:09 -0300 Subject: [PATCH 2/5] fix: patch to clean stderr output based on the keywords --- src/Server.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/Server.php b/src/Server.php index 3b3b41c..b323e37 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()); + } + + public 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; + } } From 3fc719055fc42324e11d2f6bdff871cb2f67ea14 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 24 Feb 2020 20:30:00 -0300 Subject: [PATCH 3/5] chore: removing PHP 7.2 from travis and adding 7.4 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index da1a4bc..6bdcc29 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: php php: - - 7.2 - 7.3 + - 7.4 before_script: - composer install From 3b717ac48609e71a94e3b6f508fc8342ce6ce239 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 25 Feb 2020 12:34:58 -0300 Subject: [PATCH 4/5] refactor: making the cleanErrorOutput private For that, I had to rewrite the test too --- src/Server.php | 2 +- tests/AppIntegrationTest.php | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Server.php b/src/Server.php index b323e37..47743d0 100644 --- a/src/Server.php +++ b/src/Server.php @@ -125,7 +125,7 @@ public function getErrorOutput() return self::cleanErrorOutput(parent::getErrorOutput()); } - public static function cleanErrorOutput($output) + private static function cleanErrorOutput($output) { if (!trim($output)) { return ''; diff --git a/tests/AppIntegrationTest.php b/tests/AppIntegrationTest.php index c47d93d..a63e6a4 100644 --- a/tests/AppIntegrationTest.php +++ b/tests/AppIntegrationTest.php @@ -237,15 +237,18 @@ static function ($request) { public function testServerLogsAreNotInErrorOutput() { - $expectedErrorOutput = '[Sun Feb 23 10:18:43 2020] [::1]:55146 [404]: (null) / - No such file or directory'; - $serverLogsExample = '[Sun Feb 23 10:18:31 2020] PHP 7.4.2 Development Server (http://localhost:8086) started' . PHP_EOL . - '[Sun Feb 23 10:18:43 2020] [::1]:55146 Accepted' . PHP_EOL . - $expectedErrorOutput . PHP_EOL . - '[Sun Feb 23 10:18:43 2020] [::1]:55146 Closing' . PHP_EOL; + $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); - $cleanedServerLogs = Server::cleanErrorOutput($serverLogsExample); + $actualServerErrorOutput = self::$server1->getErrorOutput(); - $this->assertEquals($expectedErrorOutput, $cleanedServerLogs); + $this->assertEquals($expectedServerErrorOutput, $actualServerErrorOutput); } private function parseRequestFromResponse(ResponseInterface $response) From 435f11afca6c2681409ae040e4c6ec2b4fae4ec3 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 25 Feb 2020 15:18:42 -0300 Subject: [PATCH 5/5] chore: maintaining PHP 7.2 to support some legacy we still have --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6bdcc29..47fe754 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: php php: + - 7.2 - 7.3 - 7.4