From 73d6ee82ed3a30092fd3558565cd42675feaf1e1 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Wed, 12 Aug 2020 17:05:15 +0200 Subject: [PATCH 01/17] Prepare changelog for release v3.1.3, #61 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4040519..8a116fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a CHANGELOG](http://keepachangelog.com). +## [3.1.3] - UNRELEASED + +### Fixed + +* Remove broken sockets from socket collection if writing the request to stream fails - [#61] + ## [3.1.2] - 2020-05-19 ### Added @@ -338,6 +344,7 @@ Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](http * Getters/Setters for connect timeout, read/write timeout, keep alive, socket persistence from `Client` (now part of the socket connection) * Method `Client->getValues()` +[3.1.3]: https://github.com/hollodotme/fast-cgi-client/compare/v3.1.2...v3.1.3 [3.1.2]: https://github.com/hollodotme/fast-cgi-client/compare/v3.1.1...v3.1.2 [3.1.1]: https://github.com/hollodotme/fast-cgi-client/compare/v3.1.0...v3.1.1 [3.1.0]: https://github.com/hollodotme/fast-cgi-client/compare/v3.0.1...v3.1.0 @@ -385,3 +392,4 @@ Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](http [#55]: https://github.com/hollodotme/fast-cgi-client/pull/55 [#56]: https://github.com/hollodotme/fast-cgi-client/issues/56 [#58]: https://github.com/hollodotme/fast-cgi-client/pull/58 +[#61]: https://github.com/hollodotme/fast-cgi-client/pull/61 From 57287c4e96128fc294b0d8fa9e81575f762e9d58 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Wed, 12 Aug 2020 17:48:54 +0200 Subject: [PATCH 02/17] Update Xdebug version to 2.9.6, #61 --- .docker/php/7.1/Dockerfile | 2 +- .docker/php/7.2/Dockerfile | 2 +- .docker/php/7.3/Dockerfile | 2 +- .docker/php/7.4/Dockerfile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.docker/php/7.1/Dockerfile b/.docker/php/7.1/Dockerfile index 70c368c..e68109b 100644 --- a/.docker/php/7.1/Dockerfile +++ b/.docker/php/7.1/Dockerfile @@ -1,5 +1,5 @@ FROM php:7.1-fpm-alpine -ENV XDEBUG_VERSION='2.9.5' +ENV XDEBUG_VERSION='2.9.6' ENV PHP_CONF_DIR=/usr/local/etc RUN apk update && apk upgrade && apk add --no-cache ${PHPIZE_DEPS} \ && pecl install xdebug-${XDEBUG_VERSION} \ diff --git a/.docker/php/7.2/Dockerfile b/.docker/php/7.2/Dockerfile index 243083a..1f8f04d 100644 --- a/.docker/php/7.2/Dockerfile +++ b/.docker/php/7.2/Dockerfile @@ -1,5 +1,5 @@ FROM php:7.2-fpm-alpine -ENV XDEBUG_VERSION='2.9.5' +ENV XDEBUG_VERSION='2.9.6' ENV PHP_CONF_DIR=/usr/local/etc RUN apk update && apk upgrade && apk add --no-cache ${PHPIZE_DEPS} \ && pecl install xdebug-${XDEBUG_VERSION} \ diff --git a/.docker/php/7.3/Dockerfile b/.docker/php/7.3/Dockerfile index f285b39..dc973a9 100644 --- a/.docker/php/7.3/Dockerfile +++ b/.docker/php/7.3/Dockerfile @@ -1,5 +1,5 @@ FROM php:7.3-fpm-alpine -ENV XDEBUG_VERSION='2.9.5' +ENV XDEBUG_VERSION='2.9.6' ENV PHP_CONF_DIR=/usr/local/etc RUN apk update && apk upgrade && apk add --no-cache ${PHPIZE_DEPS} \ && pecl install xdebug-${XDEBUG_VERSION} \ diff --git a/.docker/php/7.4/Dockerfile b/.docker/php/7.4/Dockerfile index 191daf7..d61115e 100644 --- a/.docker/php/7.4/Dockerfile +++ b/.docker/php/7.4/Dockerfile @@ -1,5 +1,5 @@ FROM php:7.4-fpm-alpine -ENV XDEBUG_VERSION='2.9.5' +ENV XDEBUG_VERSION='2.9.6' ENV PHP_CONF_DIR=/usr/local/etc RUN apk update && apk upgrade && apk add --no-cache ${PHPIZE_DEPS} \ && pecl install xdebug-${XDEBUG_VERSION} \ From 01f13637dbf1fe1bd6b6c925e171af25037b15c5 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Wed, 12 Aug 2020 18:20:40 +0200 Subject: [PATCH 03/17] Split phpunit configs by version, #61 --- .github/workflows/ci.yml | 8 +++---- build/{phpunit.xml => phpunit7.xml} | 0 build/phpunit8.xml | 31 ++++++++++++++++++++++++++ build/phpunit9.xml | 29 ++++++++++++++++++++++++ tests/runTestsOnAllLocalPhpVersions.sh | 8 +++---- 5 files changed, 68 insertions(+), 8 deletions(-) rename build/{phpunit.xml => phpunit7.xml} (100%) create mode 100644 build/phpunit8.xml create mode 100644 build/phpunit9.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbb7a69..bdc54e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: run: > docker-compose exec -T php71 php ${PHP_OPTIONS} /repo/vendor/bin/phpunit7.phar - -c /repo/build + -c /repo/build/phpunit7.xml --coverage-clover=/repo/coverage.xml env: COMPOSE_INTERACTIVE_NO_CLI: 1 @@ -71,7 +71,7 @@ jobs: run: > docker-compose exec -T php72 php ${PHP_OPTIONS} /repo/vendor/bin/phpunit8.phar - -c /repo/build + -c /repo/build/phpunit8.xml --coverage-clover=/repo/coverage.xml env: COMPOSE_INTERACTIVE_NO_CLI: 1 @@ -89,7 +89,7 @@ jobs: run: > docker-compose exec -T php73 php ${PHP_OPTIONS} /repo/vendor/bin/phpunit9.phar - -c /repo/build + -c /repo/build/phpunit9.xml --coverage-clover=/repo/coverage.xml env: COMPOSE_INTERACTIVE_NO_CLI: 1 @@ -107,7 +107,7 @@ jobs: run: > docker-compose exec -T php74 php ${PHP_OPTIONS} /repo/vendor/bin/phpunit9.phar - -c /repo/build + -c /repo/build/phpunit9.xml --coverage-clover=/repo/coverage.xml env: COMPOSE_INTERACTIVE_NO_CLI: 1 diff --git a/build/phpunit.xml b/build/phpunit7.xml similarity index 100% rename from build/phpunit.xml rename to build/phpunit7.xml diff --git a/build/phpunit8.xml b/build/phpunit8.xml new file mode 100644 index 0000000..4047d91 --- /dev/null +++ b/build/phpunit8.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + ../tests/Unit + + + ../tests/Integration + + + + + ../src + + + diff --git a/build/phpunit9.xml b/build/phpunit9.xml new file mode 100644 index 0000000..bdf00a8 --- /dev/null +++ b/build/phpunit9.xml @@ -0,0 +1,29 @@ + + + + + ../src + + + + + + + + + + + + + ../tests/Unit + + + ../tests/Integration + + + diff --git a/tests/runTestsOnAllLocalPhpVersions.sh b/tests/runTestsOnAllLocalPhpVersions.sh index 32f98c1..7f67c2b 100755 --- a/tests/runTestsOnAllLocalPhpVersions.sh +++ b/tests/runTestsOnAllLocalPhpVersions.sh @@ -12,19 +12,19 @@ echo -e "\n\033[43mRun PHPUnit\033[0m\n" echo -e "\n\033[33mOn PHP 7.1\033[0m\n" docker-compose down docker-compose up -d --force-recreate php71 -docker-compose exec php71 php ${PHP_OPTIONS} vendor/bin/phpunit7.phar -c build +docker-compose exec php71 php ${PHP_OPTIONS} vendor/bin/phpunit7.phar -c build/phpunit7.xml echo -e "\n\033[33mOn PHP 7.2\033[0m\n" docker-compose down docker-compose up -d --force-recreate php72 -docker-compose exec php72 php ${PHP_OPTIONS} vendor/bin/phpunit8.phar -c build +docker-compose exec php72 php ${PHP_OPTIONS} vendor/bin/phpunit8.phar -c build/phpunit8.xml echo -e "\n\033[33mOn PHP 7.3\033[0m\n" docker-compose down docker-compose up -d --force-recreate php73 -docker-compose exec php73 php ${PHP_OPTIONS} vendor/bin/phpunit9.phar -c build +docker-compose exec php73 php ${PHP_OPTIONS} vendor/bin/phpunit9.phar -c build/phpunit9.xml echo -e "\n\033[33mOn PHP 7.4\033[0m\n" docker-compose down docker-compose up -d --force-recreate php74 -docker-compose exec php74 php ${PHP_OPTIONS} vendor/bin/phpunit9.phar -c build +docker-compose exec php74 php ${PHP_OPTIONS} vendor/bin/phpunit9.phar -c build/phpunit9.xml echo -e "\n\033[43mRun phpstan\033[0m\n" docker-compose run --rm phpstan \ No newline at end of file From 5d13f9faf17f9909913f6d5329a4cae92a33585a Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Wed, 12 Aug 2020 18:41:59 +0200 Subject: [PATCH 04/17] Add test for removing broken socket from collection, #61 --- tests/Integration/SignaledWorkersTest.php | 42 +++++++++++++++++++++++ tests/Integration/Workers/pidWorker.php | 3 ++ 2 files changed, 45 insertions(+) create mode 100644 tests/Integration/Workers/pidWorker.php diff --git a/tests/Integration/SignaledWorkersTest.php b/tests/Integration/SignaledWorkersTest.php index f2ab9a4..a937fd7 100644 --- a/tests/Integration/SignaledWorkersTest.php +++ b/tests/Integration/SignaledWorkersTest.php @@ -311,4 +311,46 @@ static function ( Throwable $e ) use ( &$failures ) sleep( 1 ); } + + /** + * @throws ConnectException + * @throws ExpectationFailedException + * @throws InvalidArgumentException + * @throws Throwable + * @throws TimedoutException + * @throws WriteFailedException + */ + public function testBrokenSocketGetsRemovedIfWritingRequestFailed() : void + { + $client = new Client(); + $request = new PostRequest( __DIR__ . '/Workers/pidWorker.php', '' ); + $connection = $this->getUnixDomainSocketConnection(); + + $socketId1 = $client->sendAsyncRequest( $connection, $request ); + $pid1 = (int)$client->readResponse( $socketId1 )->getBody(); + + # This request should use the same socket and same PHP-FPM child process + $socketId2 = $client->sendAsyncRequest( $connection, $request ); + $pid2 = (int)$client->readResponse( $socketId2 )->getBody(); + + self::assertSame( $socketId1, $socketId2 ); + self::assertSame( $pid1, $pid2 ); + + $this->killPoolWorker( $pid2, 9 ); + + try + { + # This should fail because we killed the socket + $client->sendAsyncRequest( $connection, $request ); + } + catch ( WriteFailedException $e ) + { + # This request should use a new socket and a new PHP-FPM child process + $socketId3 = $client->sendAsyncRequest( $connection, $request ); + $pid3 = (int)$client->readResponse( $socketId3 )->getBody(); + + self::assertNotSame( $socketId2, $socketId3 ); + self::assertNotSame( $pid2, $pid3 ); + } + } } diff --git a/tests/Integration/Workers/pidWorker.php b/tests/Integration/Workers/pidWorker.php new file mode 100644 index 0000000..9f6b985 --- /dev/null +++ b/tests/Integration/Workers/pidWorker.php @@ -0,0 +1,3 @@ + Date: Wed, 12 Aug 2020 18:42:56 +0200 Subject: [PATCH 05/17] Remove broken socket if writing request to stream fails, #61 --- src/Client.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Client.php b/src/Client.php index 5efcb68..ddf160f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -91,24 +91,21 @@ public function sendRequest( */ public function sendAsyncRequest( ConfiguresSocketConnection $connection, ProvidesRequestData $request ) : int { - $socket = $this->sockets->getIdleSocket( $connection ); + $socket = $this->sockets->getIdleSocket( $connection ) + ?? $this->sockets->new( $connection, $this->packetEncoder, $this->nameValuePairEncoder ); - if ( null !== $socket ) + try { $socket->sendRequest( $request ); return $socket->getId(); } + catch ( TimedoutException | WriteFailedException $e ) + { + $this->sockets->remove( $socket->getId() ); - $socket = $this->sockets->new( - $connection, - $this->packetEncoder, - $this->nameValuePairEncoder - ); - - $socket->sendRequest( $request ); - - return $socket->getId(); + throw $e; + } } /** From b8bea22f7a7c5fde634ecf32afff6de47edd8080 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Wed, 12 Aug 2020 18:45:02 +0200 Subject: [PATCH 06/17] Silence writing to stream in order to throw right exception, #61 --- src/Sockets/Socket.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sockets/Socket.php b/src/Sockets/Socket.php index 128c4d6..e2cffba 100644 --- a/src/Sockets/Socket.php +++ b/src/Sockets/Socket.php @@ -397,8 +397,8 @@ private function write( string $data ) : void throw new WriteFailedException( 'Failed to write request to socket [broken pipe]' ); } - $writeResult = fwrite( $this->resource, $data ); - $flushResult = fflush( $this->resource ); + $writeResult = @fwrite( $this->resource, $data ); + $flushResult = @fflush( $this->resource ); if ( $writeResult === false || !$flushResult ) { From e882aa1667f31834fc9aa3bf635e8114119cb99c Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Wed, 12 Aug 2020 18:50:30 +0200 Subject: [PATCH 07/17] Fix circle CI config, #61 --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 980e96c..87d947e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,7 +122,7 @@ shared-unit-tests: &shared-unit-tests - run: name: Run unit tests - command: php -d error_reporting=-1 -d auto_prepend_file=build/xdebug-filter.php vendor/bin/phpunit$PHPUNIT_VERSION.phar -c build --testsuite Unit --log-junit build/logs/junit/junit.xml --coverage-html build/logs/coverage --coverage-clover=coverage.xml + command: php -d error_reporting=-1 -d auto_prepend_file=build/xdebug-filter.php vendor/bin/phpunit$PHPUNIT_VERSION.phar -c build/phpunit$PHPUNIT_VERSION.xml --testsuite Unit --log-junit build/logs/junit/junit.xml --coverage-html build/logs/coverage --coverage-clover=coverage.xml - run: name: Upload code coverage to codecov.io @@ -155,7 +155,7 @@ shared-integration-tests: &shared-integration-tests - run: name: Run integration tests - command: php -d error_reporting=-1 -d auto_prepend_file=build/xdebug-filter.php vendor/bin/phpunit$PHPUNIT_VERSION.phar -c build --testsuite Integration --log-junit build/logs/junit/junit.xml + command: php -d error_reporting=-1 -d auto_prepend_file=build/xdebug-filter.php vendor/bin/phpunit$PHPUNIT_VERSION.phar -c build/phpunit$PHPUNIT_VERSION.xml --testsuite Integration --log-junit build/logs/junit/junit.xml - store_test_results: path: build/logs/junit From daaaa8ae7492ff29ba70ae65de8c89a2cda0f569 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Thu, 13 Aug 2020 09:44:46 +0200 Subject: [PATCH 08/17] Fix assertion method calls --- tests/Integration/AsyncRequestsTest.php | 16 ++-- tests/Integration/FileUploadTest.php | 2 +- tests/Integration/NetworkSocketTest.php | 48 +++++------ tests/Integration/SignaledWorkersTest.php | 24 +++--- tests/Integration/UnixDomainSocketTest.php | 48 +++++------ tests/Unit/ClientTest.php | 2 +- .../Encoders/NameValuePairEncoderTest.php | 2 +- tests/Unit/Encoders/PacketEncoderTest.php | 4 +- tests/Unit/RequestContents/JsonDataTest.php | 6 +- .../RequestContents/MultipartFormDataTest.php | 6 +- .../UrlEncodedFormDataTest.php | 4 +- tests/Unit/Requests/AbstractRequestTest.php | 42 +++++----- tests/Unit/Requests/DeleteRequestTest.php | 6 +- tests/Unit/Requests/GetRequestTest.php | 6 +- tests/Unit/Requests/PatchRequestTest.php | 6 +- tests/Unit/Requests/PostRequestTest.php | 6 +- tests/Unit/Requests/PutRequestTest.php | 6 +- tests/Unit/Responses/ResponseTest.php | 48 +++++------ .../SocketConnections/NetworkSocketTest.php | 18 ++-- .../UnixDomainSocketTest.php | 18 ++-- tests/Unit/Sockets/SocketCollectionTest.php | 83 ++++++++++--------- tests/Unit/Sockets/SocketIdTest.php | 28 +++---- tests/Unit/Sockets/SocketTest.php | 30 +++---- 23 files changed, 230 insertions(+), 229 deletions(-) diff --git a/tests/Integration/AsyncRequestsTest.php b/tests/Integration/AsyncRequestsTest.php index 71aafbe..c5eb26c 100644 --- a/tests/Integration/AsyncRequestsTest.php +++ b/tests/Integration/AsyncRequestsTest.php @@ -40,7 +40,7 @@ public function testAsyncRequestsWillRespondToCallbackIfRequestsExceedPhpFpmMaxC $maxChildren = $this->getMaxChildrenSettingFromNetworkSocket(); $limit = $maxChildren + 5; - $this->assertTrue( $limit > 5 ); + self::assertTrue( $limit > 5 ); $client = new Client(); $results = []; @@ -65,7 +65,7 @@ static function ( ProvidesResponseData $response ) use ( &$results ) sort( $results ); - $this->assertSame( $expectedResults, $results ); + self::assertSame( $expectedResults, $results ); } private function getMaxChildrenSettingFromNetworkSocket() : int @@ -101,7 +101,7 @@ public function testAsyncRequestsWillRespondToCallbackIfRequestsExceedPhpFpmMaxC $maxChildren = $this->getMaxChildrenSettingFromUnixDomainSocket(); $limit = $maxChildren + 5; - $this->assertTrue( $limit > 5 ); + self::assertTrue( $limit > 5 ); $client = new Client(); $results = []; @@ -126,7 +126,7 @@ static function ( ProvidesResponseData $response ) use ( &$results ) sort( $results ); - $this->assertSame( $expectedResults, $results ); + self::assertSame( $expectedResults, $results ); } private function getMaxChildrenSettingFromUnixDomainSocket() : int @@ -157,7 +157,7 @@ public function testCanReadResponsesOfAsyncRequestsIfRequestsExceedPhpFpmMaxChil $maxChildren = $this->getMaxChildrenSettingFromNetworkSocket(); $limit = $maxChildren + 5; - $this->assertTrue( $limit > 5 ); + self::assertTrue( $limit > 5 ); $client = new Client(); $results = []; @@ -182,7 +182,7 @@ public function testCanReadResponsesOfAsyncRequestsIfRequestsExceedPhpFpmMaxChil sort( $results ); - $this->assertSame( $expectedResults, $results ); + self::assertSame( $expectedResults, $results ); } /** @@ -199,7 +199,7 @@ public function testCanReadResponsesOfAsyncRequestsIfRequestsExceedPhpFpmMaxChil $maxChildren = $this->getMaxChildrenSettingFromUnixDomainSocket(); $limit = $maxChildren + 5; - $this->assertTrue( $limit > 5 ); + self::assertTrue( $limit > 5 ); $client = new Client(); $results = []; @@ -230,6 +230,6 @@ static function ( ProvidesResponseData $response ) use ( &$results ) sort( $results ); - $this->assertSame( $expectedResults, $results ); + self::assertSame( $expectedResults, $results ); } } diff --git a/tests/Integration/FileUploadTest.php b/tests/Integration/FileUploadTest.php index 597e43f..350d923 100644 --- a/tests/Integration/FileUploadTest.php +++ b/tests/Integration/FileUploadTest.php @@ -80,6 +80,6 @@ public function testCanUploadFile() : void . "FILENAME: TestFile.txt\n" . "SIZE: 24\n\n"; - $this->assertSame( $expectedBody, $response->getBody() ); + self::assertSame( $expectedBody, $response->getBody() ); } } diff --git a/tests/Integration/NetworkSocketTest.php b/tests/Integration/NetworkSocketTest.php index 6534d09..7e275b6 100644 --- a/tests/Integration/NetworkSocketTest.php +++ b/tests/Integration/NetworkSocketTest.php @@ -81,8 +81,8 @@ public function testCanSendAsyncRequestAndReceiveSocketId() : void $socketId = $this->client->sendAsyncRequest( $this->connection, $request ); - $this->assertGreaterThanOrEqual( 1, $socketId ); - $this->assertLessThanOrEqual( 65535, $socketId ); + self::assertGreaterThanOrEqual( 1, $socketId ); + self::assertLessThanOrEqual( 65535, $socketId ); } /** @@ -102,9 +102,9 @@ public function testCanSendAsyncRequestAndReadResponse() : void $socketId = $this->client->sendAsyncRequest( $this->connection, $request ); $response = $this->client->readResponse( $socketId ); - $this->assertEquals( $expectedResponse, $response->getOutput() ); - $this->assertSame( 'unit', $response->getBody() ); - $this->assertGreaterThan( 0, $response->getDuration() ); + self::assertEquals( $expectedResponse, $response->getOutput() ); + self::assertSame( 'unit', $response->getBody() ); + self::assertGreaterThan( 0, $response->getDuration() ); } /** @@ -123,9 +123,9 @@ public function testCanSendSyncRequestAndReceiveResponse() : void $response = $this->client->sendRequest( $this->connection, $request ); - $this->assertEquals( $expectedResponse, $response->getOutput() ); - $this->assertSame( 'unit', $response->getBody() ); - $this->assertGreaterThan( 0, $response->getDuration() ); + self::assertEquals( $expectedResponse, $response->getOutput() ); + self::assertSame( 'unit', $response->getBody() ); + self::assertGreaterThan( 0, $response->getDuration() ); } /** @@ -205,8 +205,8 @@ public function testCanCheckForSocketIdsHavingResponses() : void usleep( 60000 ); - $this->assertTrue( $this->client->hasResponse( $socketId ) ); - $this->assertEquals( [$socketId], $this->client->getSocketIdsHavingResponse() ); + self::assertTrue( $this->client->hasResponse( $socketId ) ); + self::assertEquals( [$socketId], $this->client->getSocketIdsHavingResponse() ); } /** @@ -230,12 +230,12 @@ public function testCanReadResponses() : void $socketIds = [$socketIdOne, $socketIdTwo]; - $this->assertEquals( $socketIds, $this->client->getSocketIdsHavingResponse() ); + self::assertEquals( $socketIds, $this->client->getSocketIdsHavingResponse() ); $expectedBodies = ['unit' => 'unit', 'test' => 'test']; foreach ( $this->client->readResponses( null, ...$socketIds ) as $response ) { - $this->assertContains( $response->getBody(), $expectedBodies ); + self::assertContains( $response->getBody(), $expectedBodies ); unset( $expectedBodies[ $response->getBody() ] ); } @@ -261,7 +261,7 @@ public function testReadingSyncResponseCanTimeOut() : void $response = $this->client->sendRequest( $connection, $request ); - $this->assertSame( 'unit - 0', $response->getBody() ); + self::assertSame( 'unit - 0', $response->getBody() ); $content = http_build_query( ['sleep' => 1, 'test-key' => 'unit'] ); $request = new PostRequest( __DIR__ . '/Workers/sleepWorker.php', $content ); @@ -375,7 +375,7 @@ public function testReadResponsesSkipsUnknownSocketIds() : void echo $response->getBody(); } - $this->assertFalse( $this->client->hasUnhandledResponses() ); + self::assertFalse( $this->client->hasUnhandledResponses() ); $this->expectOutputString( 'unit' ); } @@ -439,7 +439,7 @@ public function testCanGetLengthOfSentContent( int $length ) : void $request->setContentType( '*/*' ); $result = $this->client->sendRequest( $this->connection, $request ); - $this->assertEquals( $length, $result->getBody() ); + self::assertEquals( $length, $result->getBody() ); } public function contentLengthProvider() : array @@ -497,8 +497,8 @@ public function testRequestingAnUnknownScriptPathThrowsException( string $script $response = $this->client->sendRequest( $this->connection, $request ); - $this->assertSame( '404 Not Found', $response->getHeaderLine( 'Status' ) ); - $this->assertSame( "File not found.\n", $response->getBody() ); + self::assertSame( '404 Not Found', $response->getHeaderLine( 'Status' ) ); + self::assertSame( "File not found.\n", $response->getBody() ); $this->assertMatchesRegExp( "#^Primary script unknown\n?$#", $response->getError() ); } @@ -542,12 +542,12 @@ public function testNotAllowedFileNameExtensionRespondsWithAccessDeniedHeader() $response = $this->client->sendRequest( $this->connection, $request ); - $this->assertSame( '403 Forbidden', $response->getHeaderLine( 'Status' ) ); + self::assertSame( '403 Forbidden', $response->getHeaderLine( 'Status' ) ); $this->assertMatchesRegExp( '#^Access to the script .+ has been denied \(see security\.limit_extensions\)$#', $response->getError() ); - $this->assertSame( "Access denied.\n", $response->getBody() ); + self::assertSame( "Access denied.\n", $response->getBody() ); } /** @@ -567,12 +567,12 @@ public function testUnaccessibleScriptRespondsWithAccessDeniedHeader() : void $request = new GetRequest( $scriptPath, '' ); $response = $this->client->sendRequest( $this->connection, $request ); - $this->assertSame( '403 Forbidden', $response->getHeaderLine( 'Status' ) ); + self::assertSame( '403 Forbidden', $response->getHeaderLine( 'Status' ) ); $this->assertMatchesRegExp( '#^Unable to open primary script\: .+ \(Permission denied\)$#', $response->getError() ); - $this->assertSame( "Access denied.\n", $response->getBody() ); + self::assertSame( "Access denied.\n", $response->getBody() ); $this->makeFileAccessible( $scriptPath ); } @@ -677,7 +677,7 @@ public function testSuccessiveRequestsShouldUseSameSocket() : void $sockets = (new ReflectionClass( $this->client ))->getProperty( 'sockets' ); $sockets->setAccessible( true ); - $this->assertCount( 0, $sockets->getValue( $this->client ) ); + self::assertCount( 0, $sockets->getValue( $this->client ) ); /** @noinspection UnusedFunctionResultInspection */ $this->client->sendRequest( $this->connection, $request ); @@ -694,7 +694,7 @@ public function testSuccessiveRequestsShouldUseSameSocket() : void $lastSocket = $socketCollection->getIdleSocket( $this->connection ); - $this->assertSame( $firstSocket, $lastSocket ); - $this->assertCount( 1, $sockets->getValue( $this->client ) ); + self::assertSame( $firstSocket, $lastSocket ); + self::assertCount( 1, $sockets->getValue( $this->client ) ); } } diff --git a/tests/Integration/SignaledWorkersTest.php b/tests/Integration/SignaledWorkersTest.php index a937fd7..6fa8f77 100644 --- a/tests/Integration/SignaledWorkersTest.php +++ b/tests/Integration/SignaledWorkersTest.php @@ -76,9 +76,9 @@ static function ( Throwable $e ) use ( &$failures ) $client->waitForResponses(); - $this->assertCount( 2, $success ); - $this->assertCount( 1, $failures ); - $this->assertContainsOnlyInstancesOf( ReadFailedException::class, $failures ); + self::assertCount( 2, $success ); + self::assertCount( 1, $failures ); + self::assertContainsOnlyInstancesOf( ReadFailedException::class, $failures ); sleep( 1 ); } @@ -184,9 +184,9 @@ static function ( Throwable $e ) use ( &$failures ) $client->waitForResponses(); - $this->assertCount( 2, $success ); - $this->assertCount( 1, $failures ); - $this->assertContainsOnlyInstancesOf( ReadFailedException::class, $failures ); + self::assertCount( 2, $success ); + self::assertCount( 1, $failures ); + self::assertContainsOnlyInstancesOf( ReadFailedException::class, $failures ); sleep( 1 ); } @@ -241,9 +241,9 @@ static function ( Throwable $e ) use ( &$failures ) $client->waitForResponses(); - $this->assertCount( 0, $success ); - $this->assertCount( 3, $failures ); - $this->assertContainsOnlyInstancesOf( ReadFailedException::class, $failures ); + self::assertCount( 0, $success ); + self::assertCount( 3, $failures ); + self::assertContainsOnlyInstancesOf( ReadFailedException::class, $failures ); sleep( 1 ); } @@ -305,9 +305,9 @@ static function ( Throwable $e ) use ( &$failures ) $client->waitForResponses(); - $this->assertCount( 0, $success ); - $this->assertCount( 3, $failures ); - $this->assertContainsOnlyInstancesOf( ReadFailedException::class, $failures ); + self::assertCount( 0, $success ); + self::assertCount( 3, $failures ); + self::assertContainsOnlyInstancesOf( ReadFailedException::class, $failures ); sleep( 1 ); } diff --git a/tests/Integration/UnixDomainSocketTest.php b/tests/Integration/UnixDomainSocketTest.php index b4d18d9..ac3662c 100644 --- a/tests/Integration/UnixDomainSocketTest.php +++ b/tests/Integration/UnixDomainSocketTest.php @@ -81,8 +81,8 @@ public function testCanSendAsyncRequestAndReceiveSocketId() : void $socketId = $this->client->sendAsyncRequest( $this->connection, $request ); - $this->assertGreaterThanOrEqual( 1, $socketId ); - $this->assertLessThanOrEqual( 65535, $socketId ); + self::assertGreaterThanOrEqual( 1, $socketId ); + self::assertLessThanOrEqual( 65535, $socketId ); } /** @@ -102,9 +102,9 @@ public function testCanSendAsyncRequestAndReadResponse() : void $socketId = $this->client->sendAsyncRequest( $this->connection, $request ); $response = $this->client->readResponse( $socketId ); - $this->assertEquals( $expectedResponse, $response->getOutput() ); - $this->assertSame( 'unit', $response->getBody() ); - $this->assertGreaterThan( 0, $response->getDuration() ); + self::assertEquals( $expectedResponse, $response->getOutput() ); + self::assertSame( 'unit', $response->getBody() ); + self::assertGreaterThan( 0, $response->getDuration() ); } /** @@ -123,9 +123,9 @@ public function testCanSendSyncRequestAndReceiveResponse() : void $response = $this->client->sendRequest( $this->connection, $request ); - $this->assertEquals( $expectedResponse, $response->getOutput() ); - $this->assertSame( 'unit', $response->getBody() ); - $this->assertGreaterThan( 0, $response->getDuration() ); + self::assertEquals( $expectedResponse, $response->getOutput() ); + self::assertSame( 'unit', $response->getBody() ); + self::assertGreaterThan( 0, $response->getDuration() ); } /** @@ -205,8 +205,8 @@ public function testCanCheckForSocketIdsHavingResponses() : void usleep( 60000 ); - $this->assertTrue( $this->client->hasResponse( $socketId ) ); - $this->assertEquals( [$socketId], $this->client->getSocketIdsHavingResponse() ); + self::assertTrue( $this->client->hasResponse( $socketId ) ); + self::assertEquals( [$socketId], $this->client->getSocketIdsHavingResponse() ); } /** @@ -230,12 +230,12 @@ public function testCanReadResponses() : void $socketIds = [$socketIdOne, $socketIdTwo]; - $this->assertEquals( $socketIds, $this->client->getSocketIdsHavingResponse() ); + self::assertEquals( $socketIds, $this->client->getSocketIdsHavingResponse() ); $expectedBodies = ['unit' => 'unit', 'test' => 'test']; foreach ( $this->client->readResponses( null, ...$socketIds ) as $response ) { - $this->assertContains( $response->getBody(), $expectedBodies ); + self::assertContains( $response->getBody(), $expectedBodies ); unset( $expectedBodies[ $response->getBody() ] ); } @@ -260,7 +260,7 @@ public function testReadingSyncResponseCanTimeOut() : void $response = $this->client->sendRequest( $connection, $request ); - $this->assertSame( 'unit - 0', $response->getBody() ); + self::assertSame( 'unit - 0', $response->getBody() ); $content = http_build_query( ['sleep' => 1, 'test-key' => 'unit'] ); $request = new PostRequest( __DIR__ . '/Workers/sleepWorker.php', $content ); @@ -374,7 +374,7 @@ public function testReadResponsesSkipsUnknownSocketIds() : void echo $response->getBody(); } - $this->assertFalse( $this->client->hasUnhandledResponses() ); + self::assertFalse( $this->client->hasUnhandledResponses() ); $this->expectOutputString( 'unit' ); } @@ -438,7 +438,7 @@ public function testCanGetLengthOfSentContent( int $length ) : void $response = $this->client->sendRequest( $this->connection, $request ); - $this->assertEquals( $length, $response->getBody() ); + self::assertEquals( $length, $response->getBody() ); } public function contentLengthProvider() : array @@ -493,8 +493,8 @@ public function testRequestingAnUnknownScriptPathThrowsException( string $script $response = $this->client->sendRequest( $this->connection, $request ); - $this->assertSame( '404 Not Found', $response->getHeaderLine( 'Status' ) ); - $this->assertSame( "File not found.\n", $response->getBody() ); + self::assertSame( '404 Not Found', $response->getHeaderLine( 'Status' ) ); + self::assertSame( "File not found.\n", $response->getBody() ); $this->assertMatchesRegExp( "#^Primary script unknown\n?$#", $response->getError() ); } @@ -525,12 +525,12 @@ public function testNotAllowedFileNameExtensionRespondsWithAccessDeniedHeader() $response = $this->client->sendRequest( $this->connection, $request ); - $this->assertSame( '403 Forbidden', $response->getHeaderLine( 'Status' ) ); + self::assertSame( '403 Forbidden', $response->getHeaderLine( 'Status' ) ); $this->assertMatchesRegExp( '#^Access to the script .+ has been denied \(see security\.limit_extensions\)$#', $response->getError() ); - $this->assertSame( "Access denied.\n", $response->getBody() ); + self::assertSame( "Access denied.\n", $response->getBody() ); } /** @@ -550,12 +550,12 @@ public function testUnaccessibleScriptRespondsWithAccessDeniedHeader() : void $request = new GetRequest( $scriptPath, '' ); $response = $this->client->sendRequest( $this->connection, $request ); - $this->assertSame( '403 Forbidden', $response->getHeaderLine( 'Status' ) ); + self::assertSame( '403 Forbidden', $response->getHeaderLine( 'Status' ) ); $this->assertMatchesRegExp( '#^Unable to open primary script\: .+ \(Permission denied\)$#', $response->getError() ); - $this->assertSame( "Access denied.\n", $response->getBody() ); + self::assertSame( "Access denied.\n", $response->getBody() ); $this->makeFileAccessible( $scriptPath ); } @@ -673,7 +673,7 @@ public function testSuccessiveRequestsShouldUseSameSocket() : void $sockets = (new ReflectionClass( $this->client ))->getProperty( 'sockets' ); $sockets->setAccessible( true ); - $this->assertCount( 0, $sockets->getValue( $this->client ) ); + self::assertCount( 0, $sockets->getValue( $this->client ) ); /** @noinspection UnusedFunctionResultInspection */ $this->client->sendRequest( $this->connection, $request ); @@ -690,7 +690,7 @@ public function testSuccessiveRequestsShouldUseSameSocket() : void $lastSocket = $socketCollection->getIdleSocket( $this->connection ); - $this->assertSame( $firstSocket, $lastSocket ); - $this->assertCount( 1, $sockets->getValue( $this->client ) ); + self::assertSame( $firstSocket, $lastSocket ); + self::assertCount( 1, $sockets->getValue( $this->client ) ); } } diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php index 15abf2c..cb9354d 100644 --- a/tests/Unit/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -164,7 +164,7 @@ public function testHandlingReadyResponsesJustReturnsIfClientGotNoRequests() : v { $client = new Client(); - $this->assertFalse( $client->hasUnhandledResponses() ); + self::assertFalse( $client->hasUnhandledResponses() ); $client->handleReadyResponses(); } diff --git a/tests/Unit/Encoders/NameValuePairEncoderTest.php b/tests/Unit/Encoders/NameValuePairEncoderTest.php index 279ff53..5346145 100644 --- a/tests/Unit/Encoders/NameValuePairEncoderTest.php +++ b/tests/Unit/Encoders/NameValuePairEncoderTest.php @@ -44,7 +44,7 @@ public function testCanEncodeAndDecodePairs( array $pairs ) : void $encoded = $nameValuePairEncoder->encodePairs( $pairs ); $decoded = $nameValuePairEncoder->decodePairs( $encoded ); - $this->assertEquals( $pairs, $decoded ); + self::assertEquals( $pairs, $decoded ); } public function pairProvider() : array diff --git a/tests/Unit/Encoders/PacketEncoderTest.php b/tests/Unit/Encoders/PacketEncoderTest.php index b7c09a3..8da9e13 100644 --- a/tests/Unit/Encoders/PacketEncoderTest.php +++ b/tests/Unit/Encoders/PacketEncoderTest.php @@ -49,8 +49,8 @@ public function testCanEncodeAndDecodePacket( int $type, string $content, int $r $header = $packetEncoder->decodeHeader( $packet ); - $this->assertEquals( $expectedHeader, $header ); - $this->assertEquals( substr( $packet, -1 * strlen( $content ) ), $content ); + self::assertEquals( $expectedHeader, $header ); + self::assertEquals( substr( $packet, -1 * strlen( $content ) ), $content ); } public function packetContentProvider() : array diff --git a/tests/Unit/RequestContents/JsonDataTest.php b/tests/Unit/RequestContents/JsonDataTest.php index a377860..b589216 100644 --- a/tests/Unit/RequestContents/JsonDataTest.php +++ b/tests/Unit/RequestContents/JsonDataTest.php @@ -16,7 +16,7 @@ final class JsonDataTest extends TestCase */ public function testGetContent() : void { - $this->assertSame( 'application/json', (new JsonData( '' ))->getContentType() ); + self::assertSame( 'application/json', (new JsonData( '' ))->getContentType() ); } /** @@ -31,7 +31,7 @@ public function testGetContent() : void */ public function testGetContentType( $data, string $expectedContent ) : void { - $this->assertSame( $expectedContent, (new JsonData( $data ))->getContent() ); + self::assertSame( $expectedContent, (new JsonData( $data ))->getContent() ); } public function jsonDataProvider() : array @@ -68,6 +68,6 @@ public function testGetContentThrowsExceptionIfDataCannotBeEncodedAsJson() : voi $data = ['unit' => ['test' => ['level' => ['three' => ['and' => ['more']]]]]]; - $this->assertSame( '', (new JsonData( $data, 0, 3 ))->getContent() ); + self::assertSame( '', (new JsonData( $data, 0, 3 ))->getContent() ); } } diff --git a/tests/Unit/RequestContents/MultipartFormDataTest.php b/tests/Unit/RequestContents/MultipartFormDataTest.php index 40f167c..3e7f957 100644 --- a/tests/Unit/RequestContents/MultipartFormDataTest.php +++ b/tests/Unit/RequestContents/MultipartFormDataTest.php @@ -31,7 +31,7 @@ public function testAddFile() : void . "VGhpcyBpcyBhIHRlc3RmaWxl\r\n" . "--__X_FASTCGI_CLIENT_BOUNDARY__--\r\n\r\n"; - $this->assertSame( $expectedContent, $multipartFormData->getContent() ); + self::assertSame( $expectedContent, $multipartFormData->getContent() ); } /** @@ -56,7 +56,7 @@ public function testGetContent() : void . "VGhpcyBpcyBhIHRlc3RmaWxl\r\n" . "--__X_FASTCGI_CLIENT_BOUNDARY__--\r\n\r\n"; - $this->assertSame( $expectedContent, $multipartFormData->getContent() ); + self::assertSame( $expectedContent, $multipartFormData->getContent() ); } public function testConstructorThrowsExceptionIfFileDoesNotExist() : void @@ -83,7 +83,7 @@ public function testAddFileThrowsExceptionIfFileDoesNotExist() : void */ public function testGetContentType() : void { - $this->assertSame( + self::assertSame( 'multipart/form-data; boundary=__X_FASTCGI_CLIENT_BOUNDARY__', (new MultipartFormData( [], [] ))->getContentType() ); diff --git a/tests/Unit/RequestContents/UrlEncodedFormDataTest.php b/tests/Unit/RequestContents/UrlEncodedFormDataTest.php index 2057fcf..453b231 100644 --- a/tests/Unit/RequestContents/UrlEncodedFormDataTest.php +++ b/tests/Unit/RequestContents/UrlEncodedFormDataTest.php @@ -15,7 +15,7 @@ final class UrlEncodedFormDataTest extends TestCase */ public function testGetContentType() : void { - $this->assertSame( 'application/x-www-form-urlencoded', (new UrlEncodedFormData( [] ))->getContentType() ); + self::assertSame( 'application/x-www-form-urlencoded', (new UrlEncodedFormData( [] ))->getContentType() ); } /** @@ -27,6 +27,6 @@ public function testGetContent() : void $formData = ['unit' => 'test', 'test' => 'unit']; $expectedContent = 'unit=test&test=unit'; - $this->assertSame( $expectedContent, (new UrlEncodedFormData( $formData ))->getContent() ); + self::assertSame( $expectedContent, (new UrlEncodedFormData( $formData ))->getContent() ); } } diff --git a/tests/Unit/Requests/AbstractRequestTest.php b/tests/Unit/Requests/AbstractRequestTest.php index d8fbd70..80f3d91 100644 --- a/tests/Unit/Requests/AbstractRequestTest.php +++ b/tests/Unit/Requests/AbstractRequestTest.php @@ -41,21 +41,21 @@ public function testCanGetDefaultValues( string $requestMethod ) : void { $request = $this->getRequest( $requestMethod, '/path/to/script.php', 'Unit-Test' ); - $this->assertSame( 'FastCGI/1.0', $request->getGatewayInterface() ); - $this->assertSame( '/path/to/script.php', $request->getScriptFilename() ); - $this->assertSame( 'Unit-Test', $request->getContent() ); - $this->assertSame( 9, $request->getContentLength() ); - $this->assertSame( '127.0.0.1', $request->getServerAddress() ); - $this->assertSame( 'localhost', $request->getServerName() ); - $this->assertSame( 'hollodotme/fast-cgi-client', $request->getServerSoftware() ); - $this->assertSame( 80, $request->getServerPort() ); - $this->assertSame( 'HTTP/1.1', $request->getServerProtocol() ); - $this->assertSame( '192.168.0.1', $request->getRemoteAddress() ); - $this->assertSame( 9985, $request->getRemotePort() ); - $this->assertSame( $requestMethod, $request->getRequestMethod() ); - $this->assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); - $this->assertSame( [], $request->getCustomVars() ); - $this->assertSame( '', $request->getRequestUri() ); + self::assertSame( 'FastCGI/1.0', $request->getGatewayInterface() ); + self::assertSame( '/path/to/script.php', $request->getScriptFilename() ); + self::assertSame( 'Unit-Test', $request->getContent() ); + self::assertSame( 9, $request->getContentLength() ); + self::assertSame( '127.0.0.1', $request->getServerAddress() ); + self::assertSame( 'localhost', $request->getServerName() ); + self::assertSame( 'hollodotme/fast-cgi-client', $request->getServerSoftware() ); + self::assertSame( 80, $request->getServerPort() ); + self::assertSame( 'HTTP/1.1', $request->getServerProtocol() ); + self::assertSame( '192.168.0.1', $request->getRemoteAddress() ); + self::assertSame( 9985, $request->getRemotePort() ); + self::assertSame( $requestMethod, $request->getRequestMethod() ); + self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); + self::assertSame( [], $request->getCustomVars() ); + self::assertSame( '', $request->getRequestUri() ); } /** @@ -125,7 +125,7 @@ public function testCanGetParametersArray( string $requestMethod ) : void 'CONTENT_LENGTH' => 9, ]; - $this->assertSame( $expectedParams, $request->getParams() ); + self::assertSame( $expectedParams, $request->getParams() ); } /** @@ -136,11 +136,11 @@ public function testContentLengthChangesWithContent() : void { $request = $this->getRequest( 'GET', '/path/to/script.php', 'Some content' ); - $this->assertSame( 12, $request->getContentLength() ); + self::assertSame( 12, $request->getContentLength() ); $request->setContent( 'Some new content' ); - $this->assertSame( 16, $request->getContentLength() ); + self::assertSame( 16, $request->getContentLength() ); } /** @@ -183,7 +183,7 @@ public function testCanOverwriteVars() : void 'CONTENT_LENGTH' => 9, ]; - $this->assertSame( $expectedParams, $request->getParams() ); + self::assertSame( $expectedParams, $request->getParams() ); } /** @@ -195,10 +195,10 @@ public function testCanResetCustomVars() : void $request = $this->getRequest( 'POST', '/path/to/script.php', 'Unit-Test' ); $request->setCustomVar( 'UNIT', 'Test' ); - $this->assertSame( ['UNIT' => 'Test'], $request->getCustomVars() ); + self::assertSame( ['UNIT' => 'Test'], $request->getCustomVars() ); $request->resetCustomVars(); - $this->assertSame( [], $request->getCustomVars() ); + self::assertSame( [], $request->getCustomVars() ); } } diff --git a/tests/Unit/Requests/DeleteRequestTest.php b/tests/Unit/Requests/DeleteRequestTest.php index aec0a1c..b527bd0 100644 --- a/tests/Unit/Requests/DeleteRequestTest.php +++ b/tests/Unit/Requests/DeleteRequestTest.php @@ -39,7 +39,7 @@ public function testRequestMethodIsGet() : void { $request = new DeleteRequest( '/path/to/script.php', 'Unit-Test' ); - $this->assertSame( 'DELETE', $request->getRequestMethod() ); + self::assertSame( 'DELETE', $request->getRequestMethod() ); } /** @@ -57,7 +57,7 @@ public function testCanCreateInstanceWithRequestContent() : void $request = DeleteRequest::newWithRequestContent( '/path/to/script.php', $urlEncodedContent ); - $this->assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); - $this->assertSame( 'unit=test&test=unit', $request->getContent() ); + self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); + self::assertSame( 'unit=test&test=unit', $request->getContent() ); } } diff --git a/tests/Unit/Requests/GetRequestTest.php b/tests/Unit/Requests/GetRequestTest.php index 1075000..5e765ec 100644 --- a/tests/Unit/Requests/GetRequestTest.php +++ b/tests/Unit/Requests/GetRequestTest.php @@ -39,7 +39,7 @@ public function testRequestMethodIsGet() : void { $request = new GetRequest( '/path/to/script.php', 'Unit-Test' ); - $this->assertSame( 'GET', $request->getRequestMethod() ); + self::assertSame( 'GET', $request->getRequestMethod() ); } /** @@ -57,7 +57,7 @@ public function testCanCreateInstanceWithRequestContent() : void $request = GetRequest::newWithRequestContent( '/path/to/script.php', $urlEncodedContent ); - $this->assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); - $this->assertSame( 'unit=test&test=unit', $request->getContent() ); + self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); + self::assertSame( 'unit=test&test=unit', $request->getContent() ); } } diff --git a/tests/Unit/Requests/PatchRequestTest.php b/tests/Unit/Requests/PatchRequestTest.php index 4040e6d..e1e3261 100644 --- a/tests/Unit/Requests/PatchRequestTest.php +++ b/tests/Unit/Requests/PatchRequestTest.php @@ -39,7 +39,7 @@ public function testRequestMethodIsGet() : void { $request = new PatchRequest( '/path/to/script.php', 'Unit-Test' ); - $this->assertSame( 'PATCH', $request->getRequestMethod() ); + self::assertSame( 'PATCH', $request->getRequestMethod() ); } /** @@ -57,7 +57,7 @@ public function testCanCreateInstanceWithRequestContent() : void $request = PatchRequest::newWithRequestContent( '/path/to/script.php', $urlEncodedContent ); - $this->assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); - $this->assertSame( 'unit=test&test=unit', $request->getContent() ); + self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); + self::assertSame( 'unit=test&test=unit', $request->getContent() ); } } diff --git a/tests/Unit/Requests/PostRequestTest.php b/tests/Unit/Requests/PostRequestTest.php index 5b22c75..98ed968 100644 --- a/tests/Unit/Requests/PostRequestTest.php +++ b/tests/Unit/Requests/PostRequestTest.php @@ -39,7 +39,7 @@ public function testRequestMethodIsPost() : void { $request = new PostRequest( '/path/to/script.php', 'Unit-Test' ); - $this->assertSame( 'POST', $request->getRequestMethod() ); + self::assertSame( 'POST', $request->getRequestMethod() ); } /** @@ -57,7 +57,7 @@ public function testCanCreateInstanceWithRequestContent() : void $request = PostRequest::newWithRequestContent( '/path/to/script.php', $urlEncodedContent ); - $this->assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); - $this->assertSame( 'unit=test&test=unit', $request->getContent() ); + self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); + self::assertSame( 'unit=test&test=unit', $request->getContent() ); } } diff --git a/tests/Unit/Requests/PutRequestTest.php b/tests/Unit/Requests/PutRequestTest.php index a8b38e1..6e66178 100644 --- a/tests/Unit/Requests/PutRequestTest.php +++ b/tests/Unit/Requests/PutRequestTest.php @@ -39,7 +39,7 @@ public function testRequestMethodIsPut() : void { $request = new PutRequest( '/path/to/script.php', 'Unit-Test' ); - $this->assertSame( 'PUT', $request->getRequestMethod() ); + self::assertSame( 'PUT', $request->getRequestMethod() ); } /** @@ -57,7 +57,7 @@ public function testCanCreateInstanceWithRequestContent() : void $request = PutRequest::newWithRequestContent( '/path/to/script.php', $urlEncodedContent ); - $this->assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); - $this->assertSame( 'unit=test&test=unit', $request->getContent() ); + self::assertSame( 'application/x-www-form-urlencoded', $request->getContentType() ); + self::assertSame( 'unit=test&test=unit', $request->getContent() ); } } diff --git a/tests/Unit/Responses/ResponseTest.php b/tests/Unit/Responses/ResponseTest.php index f8c556a..6a9d09b 100644 --- a/tests/Unit/Responses/ResponseTest.php +++ b/tests/Unit/Responses/ResponseTest.php @@ -69,43 +69,43 @@ public function testCanGetHeaders() : void ]; # All headers - $this->assertSame( $expectedHeaders, $response->getHeaders() ); + self::assertSame( $expectedHeaders, $response->getHeaders() ); # Header values by keys - $this->assertSame( ['PHP/7.3.0'], $response->getHeader( 'X-Powered-By' ) ); - $this->assertSame( ['Header'], $response->getHeader( 'X-Custom' ) ); - $this->assertSame( + self::assertSame( ['PHP/7.3.0'], $response->getHeader( 'X-Powered-By' ) ); + self::assertSame( ['Header'], $response->getHeader( 'X-Custom' ) ); + self::assertSame( ['yummy_cookie=choco', 'tasty_cookie=strawberry', 'delicious_cookie=cherry'], $response->getHeader( 'Set-Cookie' ) ); - $this->assertSame( ['text/html; charset=UTF-8'], $response->getHeader( 'Content-type' ) ); + self::assertSame( ['text/html; charset=UTF-8'], $response->getHeader( 'Content-type' ) ); # Header lines by keys - $this->assertSame( 'PHP/7.3.0', $response->getHeaderLine( 'X-Powered-By' ) ); - $this->assertSame( 'Header', $response->getHeaderLine( 'X-Custom' ) ); - $this->assertSame( + self::assertSame( 'PHP/7.3.0', $response->getHeaderLine( 'X-Powered-By' ) ); + self::assertSame( 'Header', $response->getHeaderLine( 'X-Custom' ) ); + self::assertSame( 'yummy_cookie=choco, tasty_cookie=strawberry, delicious_cookie=cherry', $response->getHeaderLine( 'Set-Cookie' ) ); - $this->assertSame( 'text/html; charset=UTF-8', $response->getHeaderLine( 'Content-type' ) ); + self::assertSame( 'text/html; charset=UTF-8', $response->getHeaderLine( 'Content-type' ) ); # Header values by case-insensitive keys - $this->assertSame( ['PHP/7.3.0'], $response->getHeader( 'x-powered-by' ) ); - $this->assertSame( ['Header'], $response->getHeader( 'X-CUSTOM' ) ); - $this->assertSame( + self::assertSame( ['PHP/7.3.0'], $response->getHeader( 'x-powered-by' ) ); + self::assertSame( ['Header'], $response->getHeader( 'X-CUSTOM' ) ); + self::assertSame( ['yummy_cookie=choco', 'tasty_cookie=strawberry', 'delicious_cookie=cherry'], $response->getHeader( 'Set-cookie' ) ); - $this->assertSame( ['text/html; charset=UTF-8'], $response->getHeader( 'Content-Type' ) ); + self::assertSame( ['text/html; charset=UTF-8'], $response->getHeader( 'Content-Type' ) ); # Header lines by case-insensitive keys - $this->assertSame( 'PHP/7.3.0', $response->getHeaderLine( 'x-powered-by' ) ); - $this->assertSame( 'Header', $response->getHeaderLine( 'X-CUSTOM' ) ); - $this->assertSame( + self::assertSame( 'PHP/7.3.0', $response->getHeaderLine( 'x-powered-by' ) ); + self::assertSame( 'Header', $response->getHeaderLine( 'X-CUSTOM' ) ); + self::assertSame( 'yummy_cookie=choco, tasty_cookie=strawberry, delicious_cookie=cherry', $response->getHeaderLine( 'Set-cookie' ) ); - $this->assertSame( 'text/html; charset=UTF-8', $response->getHeaderLine( 'Content-Type' ) ); + self::assertSame( 'text/html; charset=UTF-8', $response->getHeaderLine( 'Content-Type' ) ); } /** @@ -126,7 +126,7 @@ public function testCanGetBody() : void $expectedBody = "unit\r\ntest"; - $this->assertSame( $expectedBody, $response->getBody() ); + self::assertSame( $expectedBody, $response->getBody() ); } /** @@ -145,8 +145,8 @@ public function testCanGetOutput() : void $duration = 0.54321; $response = new Response( $output, $error, $duration ); - $this->assertSame( $output, $response->getOutput() ); - $this->assertSame( $duration, $response->getDuration() ); + self::assertSame( $output, $response->getOutput() ); + self::assertSame( $duration, $response->getDuration() ); } /** @@ -165,9 +165,9 @@ public function testCanGetError() : void $duration = 0.54321; $response = new Response( $output, $error, $duration ); - $this->assertSame( $output, $response->getOutput() ); - $this->assertSame( 'File not found.', $response->getBody() ); - $this->assertSame( $error, $response->getError() ); - $this->assertSame( $duration, $response->getDuration() ); + self::assertSame( $output, $response->getOutput() ); + self::assertSame( 'File not found.', $response->getBody() ); + self::assertSame( $error, $response->getError() ); + self::assertSame( $duration, $response->getDuration() ); } } diff --git a/tests/Unit/SocketConnections/NetworkSocketTest.php b/tests/Unit/SocketConnections/NetworkSocketTest.php index 4f8e50e..23c71ed 100644 --- a/tests/Unit/SocketConnections/NetworkSocketTest.php +++ b/tests/Unit/SocketConnections/NetworkSocketTest.php @@ -47,7 +47,7 @@ public function testImplementsConnectionInterface() : void { $connection = new NetworkSocket( 'localhost', 9000 ); - $this->assertInstanceOf( ConfiguresSocketConnection::class, $connection ); + self::assertInstanceOf( ConfiguresSocketConnection::class, $connection ); } /** @@ -60,9 +60,9 @@ public function testCanGetDefaultValues() : void $expectedSocketAddress = sprintf( 'tcp://%s:%d', $this->getNetworkSocketHost(), $this->getNetworkSocketPort() ); - $this->assertSame( $expectedSocketAddress, $connection->getSocketAddress() ); - $this->assertSame( Defaults::CONNECT_TIMEOUT, $connection->getConnectTimeout() ); - $this->assertSame( Defaults::READ_WRITE_TIMEOUT, $connection->getReadWriteTimeout() ); + self::assertSame( $expectedSocketAddress, $connection->getSocketAddress() ); + self::assertSame( Defaults::CONNECT_TIMEOUT, $connection->getConnectTimeout() ); + self::assertSame( Defaults::READ_WRITE_TIMEOUT, $connection->getReadWriteTimeout() ); } /** @@ -75,9 +75,9 @@ public function testCanGetSetValues() : void $expectedSocketAddress = sprintf( 'tcp://%s:%d', $this->getNetworkSocketHost(), $this->getNetworkSocketPort() ); - $this->assertSame( $expectedSocketAddress, $connection->getSocketAddress() ); - $this->assertSame( 2000, $connection->getConnectTimeout() ); - $this->assertSame( 3000, $connection->getReadWriteTimeout() ); + self::assertSame( $expectedSocketAddress, $connection->getSocketAddress() ); + self::assertSame( 2000, $connection->getConnectTimeout() ); + self::assertSame( 3000, $connection->getReadWriteTimeout() ); } /** @@ -92,8 +92,8 @@ public function testCanCheckForEquality( ConfiguresSocketConnection $connection, { $networkConnection = new NetworkSocket( $this->getNetworkSocketHost(), $this->getNetworkSocketPort() ); - $this->assertSame( $expectedEqual, $networkConnection->equals( $connection ) ); - $this->assertSame( $expectedEqual, $connection->equals( $networkConnection ) ); + self::assertSame( $expectedEqual, $networkConnection->equals( $connection ) ); + self::assertSame( $expectedEqual, $connection->equals( $networkConnection ) ); } public function connectionProvider() : array diff --git a/tests/Unit/SocketConnections/UnixDomainSocketTest.php b/tests/Unit/SocketConnections/UnixDomainSocketTest.php index 49bf3d4..0fb85d9 100644 --- a/tests/Unit/SocketConnections/UnixDomainSocketTest.php +++ b/tests/Unit/SocketConnections/UnixDomainSocketTest.php @@ -47,7 +47,7 @@ public function testImplementsConnectionInterface() : void { $connection = new UnixDomainSocket( $this->getUnixDomainSocket() ); - $this->assertInstanceOf( ConfiguresSocketConnection::class, $connection ); + self::assertInstanceOf( ConfiguresSocketConnection::class, $connection ); } /** @@ -60,9 +60,9 @@ public function testCanGetDefaultValues() : void $expectedSocketAddress = sprintf( 'unix://%s', $this->getUnixDomainSocket() ); - $this->assertSame( $expectedSocketAddress, $connection->getSocketAddress() ); - $this->assertSame( Defaults::CONNECT_TIMEOUT, $connection->getConnectTimeout() ); - $this->assertSame( Defaults::READ_WRITE_TIMEOUT, $connection->getReadWriteTimeout() ); + self::assertSame( $expectedSocketAddress, $connection->getSocketAddress() ); + self::assertSame( Defaults::CONNECT_TIMEOUT, $connection->getConnectTimeout() ); + self::assertSame( Defaults::READ_WRITE_TIMEOUT, $connection->getReadWriteTimeout() ); } /** @@ -75,9 +75,9 @@ public function testCanGetSetValues() : void $expectedSocketAddress = sprintf( 'unix://%s', $this->getUnixDomainSocket() ); - $this->assertSame( $expectedSocketAddress, $connection->getSocketAddress() ); - $this->assertSame( 2000, $connection->getConnectTimeout() ); - $this->assertSame( 3000, $connection->getReadWriteTimeout() ); + self::assertSame( $expectedSocketAddress, $connection->getSocketAddress() ); + self::assertSame( 2000, $connection->getConnectTimeout() ); + self::assertSame( 3000, $connection->getReadWriteTimeout() ); } /** @@ -92,8 +92,8 @@ public function testCanCheckForEquality( ConfiguresSocketConnection $connection, { $unixDomainConnection = new UnixDomainSocket( $this->getUnixDomainSocket() ); - $this->assertSame( $expectedEqual, $unixDomainConnection->equals( $connection ) ); - $this->assertSame( $expectedEqual, $connection->equals( $unixDomainConnection ) ); + self::assertSame( $expectedEqual, $unixDomainConnection->equals( $connection ) ); + self::assertSame( $expectedEqual, $connection->equals( $unixDomainConnection ) ); } public function connectionProvider() : array diff --git a/tests/Unit/Sockets/SocketCollectionTest.php b/tests/Unit/Sockets/SocketCollectionTest.php index f49d902..08ec270 100644 --- a/tests/Unit/Sockets/SocketCollectionTest.php +++ b/tests/Unit/Sockets/SocketCollectionTest.php @@ -91,7 +91,7 @@ public function testCollectResources() : void $socketOne->collectResource( $resources ); $socketTwo->collectResource( $resources ); - $this->assertSame( $resources, $this->collection->collectResources() ); + self::assertSame( $resources, $this->collection->collectResources() ); } /** @@ -124,7 +124,7 @@ public function testGetByResource() : void $checkSocket = $this->collection->getByResource( reset( $resources ) ); - $this->assertSame( $checkSocket, $socket ); + self::assertSame( $checkSocket, $socket ); } /** @@ -139,7 +139,7 @@ public function testThrowsExceptionIfSocketCannotBeFoundByResource() : void /** @noinspection UnusedFunctionResultInspection */ $this->collection->getByResource( STDIN ); - $this->fail( 'Expected a ReadFailedException for not found socket by resource.' ); + self::fail( 'Expected a ReadFailedException for not found socket by resource.' ); } /** @@ -182,7 +182,7 @@ public function testGetSocketIdsByResources() : void $expectedSocketIds = [$socketOne->getId(), $socketTwo->getId()]; - $this->assertSame( $expectedSocketIds, $this->collection->getSocketIdsByResources( $resources ) ); + self::assertSame( $expectedSocketIds, $this->collection->getSocketIdsByResources( $resources ) ); } /** @@ -194,7 +194,7 @@ public function testEmptyCollectionHasNoIdleSocket() : void { $connection = $this->getSocketConnection(); - $this->assertNull( $this->collection->getIdleSocket( $connection ) ); + self::assertNull( $this->collection->getIdleSocket( $connection ) ); } /** @@ -210,7 +210,7 @@ public function testNewlyAddedSocketIsIdle() : void $packetEncoder = new PacketEncoder(); $nameValuePairEncoder = new NameValuePairEncoder(); - $this->assertCount( 0, $this->collection ); + self::assertCount( 0, $this->collection ); $socket = $this->collection->new( $connection, @@ -218,7 +218,7 @@ public function testNewlyAddedSocketIsIdle() : void $nameValuePairEncoder ); - $this->assertSame( $socket, $this->collection->getIdleSocket( $connection ) ); + self::assertSame( $socket, $this->collection->getIdleSocket( $connection ) ); } /** @@ -237,7 +237,7 @@ public function testSocketWithResponseIsIdle() : void $packetEncoder = new PacketEncoder(); $nameValuePairEncoder = new NameValuePairEncoder(); - $this->assertCount( 0, $this->collection ); + self::assertCount( 0, $this->collection ); $socket = $this->collection->new( $connection, @@ -254,7 +254,7 @@ public function testSocketWithResponseIsIdle() : void /** @noinspection UnusedFunctionResultInspection */ $socket->fetchResponse( 2000 ); - $this->assertSame( $socket, $this->collection->getIdleSocket( $connection ) ); + self::assertSame( $socket, $this->collection->getIdleSocket( $connection ) ); } /** @@ -272,7 +272,7 @@ public function testBusySocketIsNotIdle() : void $packetEncoder = new PacketEncoder(); $nameValuePairEncoder = new NameValuePairEncoder(); - $this->assertCount( 0, $this->collection ); + self::assertCount( 0, $this->collection ); $socket = $this->collection->new( $connection, @@ -284,7 +284,7 @@ public function testBusySocketIsNotIdle() : void new PostRequest( '/some/script.php', '' ) ); - $this->assertNull( $this->collection->getIdleSocket( $connection ) ); + self::assertNull( $this->collection->getIdleSocket( $connection ) ); } /** @@ -301,7 +301,7 @@ public function testNotUsableSocketIsNotIdle() : void $packetEncoder = new PacketEncoder(); $nameValuePairEncoder = new NameValuePairEncoder(); - $this->assertCount( 0, $this->collection ); + self::assertCount( 0, $this->collection ); $socket = $this->collection->new( $connection, @@ -322,10 +322,10 @@ public function testNotUsableSocketIsNotIdle() : void } } - $this->assertNull( $this->collection->getIdleSocket( $connection ) ); + self::assertNull( $this->collection->getIdleSocket( $connection ) ); # Socket should also be removed from collection - $this->assertCount( 0, $this->collection ); + self::assertCount( 0, $this->collection ); } /** @@ -342,7 +342,7 @@ public function testClosedSocketIsNotIdle() : void $packetEncoder = new PacketEncoder(); $nameValuePairEncoder = new NameValuePairEncoder(); - $this->assertCount( 0, $this->collection ); + self::assertCount( 0, $this->collection ); $socket = $this->collection->new( $connection, @@ -359,10 +359,10 @@ public function testClosedSocketIsNotIdle() : void fclose( $resource ); } - $this->assertNull( $this->collection->getIdleSocket( $connection ) ); + self::assertNull( $this->collection->getIdleSocket( $connection ) ); # Socket should also be removed from collection - $this->assertCount( 0, $this->collection ); + self::assertCount( 0, $this->collection ); } /** @@ -387,7 +387,7 @@ public function testGetById() : void $checkSocket = $this->collection->getById( $socket->getId() ); - $this->assertSame( $checkSocket, $socket ); + self::assertSame( $checkSocket, $socket ); } /** @@ -402,7 +402,7 @@ public function testThrowsExceptionIfSocketCannotByFoundById() : void /** @noinspection UnusedFunctionResultInspection */ $this->collection->getById( 123 ); - $this->fail( 'Expected a ReadFailedException to be thrown.' ); + self::fail( 'Expected a ReadFailedException to be thrown.' ); } /** @@ -424,9 +424,9 @@ public function testNew() : void $nameValuePairEncoder ); - $this->assertGreaterThan( 0, $socketOne->getId() ); - $this->assertCount( 1, $this->collection ); - $this->assertSame( 1, $this->collection->count() ); + self::assertGreaterThan( 0, $socketOne->getId() ); + self::assertCount( 1, $this->collection ); + self::assertSame( 1, $this->collection->count() ); $socketTwo = $this->collection->new( $connection, @@ -434,10 +434,10 @@ public function testNew() : void $nameValuePairEncoder ); - $this->assertGreaterThan( 0, $socketTwo->getId() ); - $this->assertNotSame( $socketOne->getId(), $socketTwo->getId() ); - $this->assertCount( 2, $this->collection ); - $this->assertSame( 2, $this->collection->count() ); + self::assertGreaterThan( 0, $socketTwo->getId() ); + self::assertNotSame( $socketOne->getId(), $socketTwo->getId() ); + self::assertCount( 2, $this->collection ); + self::assertSame( 2, $this->collection->count() ); } /** @@ -459,7 +459,7 @@ public function testThrowsExceptionIfNoNewSocketCanBeCreated() : void $this->collection->new( $connection, $packetEncoder, $nameValuePairEncoder ); } - $this->fail( 'Expected WriteFailedException to be thrown.' ); + self::fail( 'Expected WriteFailedException to be thrown.' ); } /** @@ -477,8 +477,8 @@ public function testHasBusySockets() : void $packetEncoder = new PacketEncoder(); $nameValuePairEncoder = new NameValuePairEncoder(); - $this->assertCount( 0, $this->collection ); - $this->assertFalse( $this->collection->hasBusySockets() ); + self::assertCount( 0, $this->collection ); + self::assertFalse( $this->collection->hasBusySockets() ); $socket = $this->collection->new( $connection, @@ -490,7 +490,7 @@ public function testHasBusySockets() : void new PostRequest( '/some/sctipt.php', '' ) ); - $this->assertTrue( $this->collection->hasBusySockets() ); + self::assertTrue( $this->collection->hasBusySockets() ); } /** @@ -506,7 +506,7 @@ public function testRemove() : void $packetEncoder = new PacketEncoder(); $nameValuePairEncoder = new NameValuePairEncoder(); - $this->assertCount( 0, $this->collection ); + self::assertCount( 0, $this->collection ); $socket = $this->collection->new( $connection, @@ -514,11 +514,11 @@ public function testRemove() : void $nameValuePairEncoder ); - $this->assertCount( 1, $this->collection ); + self::assertCount( 1, $this->collection ); $this->collection->remove( $socket->getId() ); - $this->assertCount( 0, $this->collection ); + self::assertCount( 0, $this->collection ); } /** @@ -528,8 +528,8 @@ public function testRemove() : void */ public function testCount() : void { - $this->assertSame( 0, $this->collection->count() ); - $this->assertCount( 0, $this->collection ); + self::assertSame( 0, $this->collection->count() ); + self::assertCount( 0, $this->collection ); } /** @@ -538,10 +538,11 @@ public function testCount() : void */ public function testIsEmpty() : void { - $this->assertTrue( $this->collection->isEmpty() ); + self::assertTrue( $this->collection->isEmpty() ); } /** + * @throws Exception * @throws ExpectationFailedException * @throws InvalidArgumentException * @throws WriteFailedException @@ -566,12 +567,12 @@ public function testIdleSocketsAreIdentifiedByConnection() : void $nameValuePairEncoder ); - $this->assertCount( 2, $this->collection ); + self::assertCount( 2, $this->collection ); - $this->assertSame( $unixDomainSocket, $this->collection->getIdleSocket( $unixDomainConnection ) ); - $this->assertNotSame( $unixDomainSocket, $this->collection->getIdleSocket( $networkConnection ) ); + self::assertSame( $unixDomainSocket, $this->collection->getIdleSocket( $unixDomainConnection ) ); + self::assertNotSame( $unixDomainSocket, $this->collection->getIdleSocket( $networkConnection ) ); - $this->assertSame( $networkSocket, $this->collection->getIdleSocket( $networkConnection ) ); - $this->assertNotSame( $networkSocket, $this->collection->getIdleSocket( $unixDomainConnection ) ); + self::assertSame( $networkSocket, $this->collection->getIdleSocket( $networkConnection ) ); + self::assertNotSame( $networkSocket, $this->collection->getIdleSocket( $unixDomainConnection ) ); } } diff --git a/tests/Unit/Sockets/SocketIdTest.php b/tests/Unit/Sockets/SocketIdTest.php index 0ab804c..44cb1fd 100644 --- a/tests/Unit/Sockets/SocketIdTest.php +++ b/tests/Unit/Sockets/SocketIdTest.php @@ -20,8 +20,8 @@ public function testCanGetNewInstance() : void { $socketId = SocketId::new(); - $this->assertGreaterThanOrEqual( 1, $socketId->getValue() ); - $this->assertLessThanOrEqual( (1 << 16) - 1, $socketId->getValue() ); + self::assertGreaterThanOrEqual( 1, $socketId->getValue() ); + self::assertLessThanOrEqual( (1 << 16) - 1, $socketId->getValue() ); } } @@ -34,8 +34,8 @@ public function testGetValue() : void { $socketId = SocketId::new(); - $this->assertGreaterThanOrEqual( 1, $socketId->getValue() ); - $this->assertLessThanOrEqual( (1 << 16) - 1, $socketId->getValue() ); + self::assertGreaterThanOrEqual( 1, $socketId->getValue() ); + self::assertLessThanOrEqual( (1 << 16) - 1, $socketId->getValue() ); } /** @@ -49,7 +49,7 @@ public function testCanGetNewInstanceFromInt() : void { $socketId = SocketId::fromInt( $i ); - $this->assertSame( $i, $socketId->getValue() ); + self::assertSame( $i, $socketId->getValue() ); } } @@ -90,17 +90,17 @@ public function testEquals() : void $otherEquals = SocketId::fromInt( 123 ); $otherEqualsNot = SocketId::fromInt( 321 ); - $this->assertNotSame( $socketId, $otherEquals ); - $this->assertNotSame( $socketId, $otherEqualsNot ); - $this->assertNotSame( $otherEquals, $otherEqualsNot ); + self::assertNotSame( $socketId, $otherEquals ); + self::assertNotSame( $socketId, $otherEqualsNot ); + self::assertNotSame( $otherEquals, $otherEqualsNot ); - $this->assertTrue( $socketId->equals( $otherEquals ) ); - $this->assertTrue( $otherEquals->equals( $socketId ) ); + self::assertTrue( $socketId->equals( $otherEquals ) ); + self::assertTrue( $otherEquals->equals( $socketId ) ); - $this->assertFalse( $socketId->equals( $otherEqualsNot ) ); - $this->assertFalse( $otherEqualsNot->equals( $socketId ) ); + self::assertFalse( $socketId->equals( $otherEqualsNot ) ); + self::assertFalse( $otherEqualsNot->equals( $socketId ) ); - $this->assertFalse( $otherEquals->equals( $otherEqualsNot ) ); - $this->assertFalse( $otherEqualsNot->equals( $otherEquals ) ); + self::assertFalse( $otherEquals->equals( $otherEqualsNot ) ); + self::assertFalse( $otherEqualsNot->equals( $otherEquals ) ); } } diff --git a/tests/Unit/Sockets/SocketTest.php b/tests/Unit/Sockets/SocketTest.php index d99b919..c499b93 100644 --- a/tests/Unit/Sockets/SocketTest.php +++ b/tests/Unit/Sockets/SocketTest.php @@ -60,8 +60,8 @@ public function testCanGetIdAfterConstruction() : void { $socket = $this->getSocket(); - $this->assertGreaterThanOrEqual( 1, $socket->getId() ); - $this->assertLessThanOrEqual( (1 << 16) - 1, $socket->getId() ); + self::assertGreaterThanOrEqual( 1, $socket->getId() ); + self::assertLessThanOrEqual( (1 << 16) - 1, $socket->getId() ); } /** @@ -107,11 +107,11 @@ public function testCanSendRequestAndFetchResponse() : void $response = $socket->fetchResponse(); - $this->assertSame( 'unit', $response->getBody() ); + self::assertSame( 'unit', $response->getBody() ); $response2 = $socket->fetchResponse(); - $this->assertSame( $response, $response2 ); + self::assertSame( $response, $response2 ); } /** @@ -134,13 +134,13 @@ public function testCanCollectResource() : void $socket->collectResource( $resources ); - $this->assertEmpty( $resources ); + self::assertEmpty( $resources ); $socket->sendRequest( $request ); $socket->collectResource( $resources ); - $this->assertIsResource( $resources[ $socket->getId() ] ); + self::assertIsResource( $resources[ $socket->getId() ] ); } /** @@ -219,7 +219,7 @@ public function testThrowsExceptionIfRequestIsSentToSocketThatIsNotIdle() : void $socket->sendRequest( $request ); - $this->fail( 'Expected ConnectException to be thrown.' ); + self::fail( 'Expected ConnectException to be thrown.' ); } /** @@ -249,7 +249,7 @@ public function testRequestCompletedGuard( $guardMethod->invoke( $socket, $flag ); - $this->fail( 'Expected an Exception to be thrown.' ); + self::fail( 'Expected an Exception to be thrown.' ); } public function responseFlagProvider() : array @@ -287,7 +287,7 @@ public function testIsUsableWhenInInitialState() : void { $socket = $this->getSocket(); - $this->assertTrue( $socket->isUsable() ); + self::assertTrue( $socket->isUsable() ); } /** @@ -315,7 +315,7 @@ public function testIsNotUsableWhenTimedOut() : void { } - $this->assertFalse( $socket->isUsable() ); + self::assertFalse( $socket->isUsable() ); } /** @@ -336,7 +336,7 @@ public function testIsNotUsableWhenSocketWasClosed() : void $disconnectMethod->setAccessible( true ); $disconnectMethod->invoke( $socket ); - $this->assertFalse( $socket->isUsable() ); + self::assertFalse( $socket->isUsable() ); } /** @@ -366,10 +366,10 @@ public function testCanCheckIfSocketUsesConnection() : void $nameValuePairEncoder ); - $this->assertTrue( $unixDomainSocket->usesConnection( $unixDomainConnection ) ); - $this->assertFalse( $unixDomainSocket->usesConnection( $networkConnection ) ); + self::assertTrue( $unixDomainSocket->usesConnection( $unixDomainConnection ) ); + self::assertFalse( $unixDomainSocket->usesConnection( $networkConnection ) ); - $this->assertTrue( $networkSocket->usesConnection( $networkConnection ) ); - $this->assertFalse( $networkSocket->usesConnection( $unixDomainConnection ) ); + self::assertTrue( $networkSocket->usesConnection( $networkConnection ) ); + self::assertFalse( $networkSocket->usesConnection( $unixDomainConnection ) ); } } From 5410512e44f138a1f6968c40eaebb318b584eec6 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Thu, 13 Aug 2020 10:04:15 +0200 Subject: [PATCH 09/17] Kill pool worker one by one instead of all at once, #61 --- tests/Integration/SignaledWorkersTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/Integration/SignaledWorkersTest.php b/tests/Integration/SignaledWorkersTest.php index 6fa8f77..aa0a196 100644 --- a/tests/Integration/SignaledWorkersTest.php +++ b/tests/Integration/SignaledWorkersTest.php @@ -19,7 +19,6 @@ use function escapeshellarg; use function exec; use function http_build_query; -use function implode; use function preg_match; use function shell_exec; use function sleep; @@ -256,8 +255,10 @@ private function killPhpFpmChildProcesses( string $poolName, int $signal ) : voi private function killPoolWorkers( array $PIDs, int $signal ) : void { - $command = sprintf( 'kill -%d %s', $signal, implode( ' ', $PIDs ) ); - exec( $command ); + foreach ( $PIDs as $PID ) + { + $this->killPoolWorker( $PID, $signal ); + } } /** From 442cba9e477eddf916d75752438f439be175ac91 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Thu, 13 Aug 2020 10:23:19 +0200 Subject: [PATCH 10/17] Add phpstan config file, add tests to analyzer scope --- docker-compose.yml | 2 +- phpstan.neon | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon diff --git a/docker-compose.yml b/docker-compose.yml index 7fd60f2..af687f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -61,7 +61,7 @@ services: container_name: fcc_phpstan working_dir: /repo restart: "no" - command: "analyze --level max src/" + command: "analyze" networks: - fcc_network volumes: diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b86fe7b --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + paths: + - src + - tests + level: max + bootstrapFiles: + - ./vendor/bin/phpunit7.phar \ No newline at end of file From a38f822fb82984baff0fcc236c3416521be5dd1b Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Thu, 13 Aug 2020 10:24:06 +0200 Subject: [PATCH 11/17] Do not export phpstan and docker-compose config in composer archives --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitattributes b/.gitattributes index 5399cbd..41884e8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,3 +6,5 @@ bin/ export-ignore build/ export-ignore tests/ export-ignore CHANGELOG.md export-ignore +docker-compose.yml export-ignore +phpstan.neon export-ignore From b57ea931fbadae64f4b5b3150342095f84560b67 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Thu, 13 Aug 2020 10:42:12 +0200 Subject: [PATCH 12/17] Allow passing options to phpunit when calling the script --- tests/runTestsOnAllLocalPhpVersions.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/runTestsOnAllLocalPhpVersions.sh b/tests/runTestsOnAllLocalPhpVersions.sh index 7f67c2b..6aa48fd 100755 --- a/tests/runTestsOnAllLocalPhpVersions.sh +++ b/tests/runTestsOnAllLocalPhpVersions.sh @@ -5,6 +5,7 @@ cd "$(dirname "${DIR}" )" >/dev/null 2>&1 PHP_OPTIONS="-d error_reporting=-1 -d auto_prepend_file=build/xdebug-filter.php" +PHPUNIT_OPTIONS="$@" echo -e "\nPHP interpreter options:\n" ${PHP_OPTIONS} "\n" @@ -12,19 +13,19 @@ echo -e "\n\033[43mRun PHPUnit\033[0m\n" echo -e "\n\033[33mOn PHP 7.1\033[0m\n" docker-compose down docker-compose up -d --force-recreate php71 -docker-compose exec php71 php ${PHP_OPTIONS} vendor/bin/phpunit7.phar -c build/phpunit7.xml +docker-compose exec php71 php ${PHP_OPTIONS} vendor/bin/phpunit7.phar -c build/phpunit7.xml ${PHPUNIT_OPTIONS} echo -e "\n\033[33mOn PHP 7.2\033[0m\n" docker-compose down docker-compose up -d --force-recreate php72 -docker-compose exec php72 php ${PHP_OPTIONS} vendor/bin/phpunit8.phar -c build/phpunit8.xml +docker-compose exec php72 php ${PHP_OPTIONS} vendor/bin/phpunit8.phar -c build/phpunit8.xml ${PHPUNIT_OPTIONS} echo -e "\n\033[33mOn PHP 7.3\033[0m\n" docker-compose down docker-compose up -d --force-recreate php73 -docker-compose exec php73 php ${PHP_OPTIONS} vendor/bin/phpunit9.phar -c build/phpunit9.xml +docker-compose exec php73 php ${PHP_OPTIONS} vendor/bin/phpunit9.phar -c build/phpunit9.xml ${PHPUNIT_OPTIONS} echo -e "\n\033[33mOn PHP 7.4\033[0m\n" docker-compose down docker-compose up -d --force-recreate php74 -docker-compose exec php74 php ${PHP_OPTIONS} vendor/bin/phpunit9.phar -c build/phpunit9.xml +docker-compose exec php74 php ${PHP_OPTIONS} vendor/bin/phpunit9.phar -c build/phpunit9.xml ${PHPUNIT_OPTIONS} echo -e "\n\033[43mRun phpstan\033[0m\n" docker-compose run --rm phpstan \ No newline at end of file From 132edd8423da92a39386b4d03896036296102eca Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Thu, 13 Aug 2020 10:43:39 +0200 Subject: [PATCH 13/17] Use phpstan config for analysis --- .circleci/config.yml | 2 +- .github/workflows/ci.yml | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 87d947e..10b85b5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -174,7 +174,7 @@ shared-phpstan: &shared-phpstan - run: name: Run PHPStan - command: phpstan analyze --level max src/ + command: phpstan analyze # Define the actual jobs from the templates above jobs: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bdc54e5..fe39b5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: run: docker run --rm -v $(pwd):/app composer update -o -v --ignore-platform-reqs - name: Run PHPStan - run: docker run --rm -v $(pwd):/app phpstan/phpstan analyze --level=max /app/src + run: docker run --rm -v $(pwd):/app phpstan/phpstan analyze unit-tests: runs-on: ubuntu-latest @@ -55,6 +55,7 @@ jobs: /repo/vendor/bin/phpunit7.phar -c /repo/build/phpunit7.xml --coverage-clover=/repo/coverage.xml + --testdox env: COMPOSE_INTERACTIVE_NO_CLI: 1 PHP_OPTIONS: "-d error_reporting=-1 -d auto_prepend_file=/repo/build/xdebug-filter.php" @@ -73,6 +74,7 @@ jobs: /repo/vendor/bin/phpunit8.phar -c /repo/build/phpunit8.xml --coverage-clover=/repo/coverage.xml + --testdox env: COMPOSE_INTERACTIVE_NO_CLI: 1 PHP_OPTIONS: "-d error_reporting=-1 -d auto_prepend_file=/repo/build/xdebug-filter.php" @@ -91,6 +93,7 @@ jobs: /repo/vendor/bin/phpunit9.phar -c /repo/build/phpunit9.xml --coverage-clover=/repo/coverage.xml + --testdox env: COMPOSE_INTERACTIVE_NO_CLI: 1 PHP_OPTIONS: "-d error_reporting=-1 -d auto_prepend_file=/repo/build/xdebug-filter.php" @@ -109,6 +112,7 @@ jobs: /repo/vendor/bin/phpunit9.phar -c /repo/build/phpunit9.xml --coverage-clover=/repo/coverage.xml + --testdox env: COMPOSE_INTERACTIVE_NO_CLI: 1 PHP_OPTIONS: "-d error_reporting=-1 -d auto_prepend_file=/repo/build/xdebug-filter.php" From 1944e67d5c8de72fdc7da93798f5ced21255071c Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Thu, 13 Aug 2020 10:44:53 +0200 Subject: [PATCH 14/17] Fix inspection issues in tests found by phpstan --- tests/Integration/AsyncRequestsTest.php | 8 ++--- tests/Integration/FileUploadTest.php | 4 +-- tests/Integration/NetworkSocketTest.php | 10 ++++-- tests/Integration/SignaledWorkersTest.php | 14 +++++++- tests/Integration/UnixDomainSocketTest.php | 10 ++++-- tests/Integration/Workers/lengthWorker.php | 2 +- .../Encoders/NameValuePairEncoderTest.php | 13 +++++--- tests/Unit/Encoders/PacketEncoderTest.php | 32 +++++++++++++------ tests/Unit/RequestContents/JsonDataTest.php | 3 ++ tests/Unit/Requests/AbstractRequestTest.php | 23 ++++++++++--- .../SocketConnections/NetworkSocketTest.php | 3 ++ .../UnixDomainSocketTest.php | 3 ++ tests/Unit/Sockets/SocketCollectionTest.php | 2 +- tests/Unit/Sockets/SocketIdTest.php | 3 ++ tests/Unit/Sockets/SocketTest.php | 3 ++ 15 files changed, 99 insertions(+), 34 deletions(-) diff --git a/tests/Integration/AsyncRequestsTest.php b/tests/Integration/AsyncRequestsTest.php index c5eb26c..fe4e541 100644 --- a/tests/Integration/AsyncRequestsTest.php +++ b/tests/Integration/AsyncRequestsTest.php @@ -27,7 +27,6 @@ final class AsyncRequestsTest extends TestCase /** * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws Throwable * @throws ConnectException * @throws ReadFailedException @@ -70,7 +69,7 @@ static function ( ProvidesResponseData $response ) use ( &$results ) private function getMaxChildrenSettingFromNetworkSocket() : int { - $iniSettings = parse_ini_file( + $iniSettings = (array)parse_ini_file( __DIR__ . '/../../.docker/php/network-socket.pool.conf', true ); @@ -89,7 +88,6 @@ private function getNetworkSocketConnection() : NetworkSocket /** * @throws ConnectException * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws ReadFailedException * @throws Throwable * @throws TimedoutException @@ -131,7 +129,7 @@ static function ( ProvidesResponseData $response ) use ( &$results ) private function getMaxChildrenSettingFromUnixDomainSocket() : int { - $iniSettings = parse_ini_file( + $iniSettings = (array)parse_ini_file( __DIR__ . '/../../.docker/php/unix-domain-socket.pool.conf', true ); @@ -147,10 +145,10 @@ private function getUnixDomainSocketConnection() : UnixDomainSocket /** * @throws ConnectException * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws ReadFailedException * @throws TimedoutException * @throws WriteFailedException + * @throws InvalidArgumentException */ public function testCanReadResponsesOfAsyncRequestsIfRequestsExceedPhpFpmMaxChildrenSettingOnNetworkSocket() : void { diff --git a/tests/Integration/FileUploadTest.php b/tests/Integration/FileUploadTest.php index 350d923..73d2bba 100644 --- a/tests/Integration/FileUploadTest.php +++ b/tests/Integration/FileUploadTest.php @@ -33,8 +33,8 @@ protected function setUp() : void protected function tearDown() : void { - $this->connection = null; - $this->client = null; + $this->connection = new NetworkSocket( $this->getNetworkSocketHost(), $this->getNetworkSocketPort() ); + $this->client = new Client(); } /** diff --git a/tests/Integration/NetworkSocketTest.php b/tests/Integration/NetworkSocketTest.php index 7e275b6..1747af3 100644 --- a/tests/Integration/NetworkSocketTest.php +++ b/tests/Integration/NetworkSocketTest.php @@ -64,8 +64,8 @@ protected function setUp() : void protected function tearDown() : void { - $this->connection = null; - $this->client = null; + $this->connection = new NetworkSocket( $this->getNetworkSocketHost(), $this->getNetworkSocketPort() ); + $this->client = new Client(); } /** @@ -442,6 +442,9 @@ public function testCanGetLengthOfSentContent( int $length ) : void self::assertEquals( $length, $result->getBody() ); } + /** + * @return array> + */ public function contentLengthProvider() : array { return [ @@ -515,6 +518,9 @@ private function assertMatchesRegExp( string $pattern, string $string, string $m static::assertThat( $string, new RegularExpression( $pattern ), $message ); } + /** + * @return array> + */ public function invalidScriptFileNamesProvider() : array { return [ diff --git a/tests/Integration/SignaledWorkersTest.php b/tests/Integration/SignaledWorkersTest.php index aa0a196..9937b50 100644 --- a/tests/Integration/SignaledWorkersTest.php +++ b/tests/Integration/SignaledWorkersTest.php @@ -82,6 +82,9 @@ static function ( Throwable $e ) use ( &$failures ) sleep( 1 ); } + /** + * @return array> + */ public function signalProvider() : array { return [ @@ -112,13 +115,18 @@ private function getNetworkSocketConnection() : NetworkSocket ); } + /** + * @param string $poolName + * + * @return array + */ private function getPoolWorkerPIDs( string $poolName ) : array { $command = sprintf( 'ps -o pid,args | grep %s | grep -v "grep"', escapeshellarg( $poolName ) ); - $list = shell_exec( $command ); + $list = (string)shell_exec( $command ); return array_map( static function ( string $item ) @@ -253,6 +261,10 @@ private function killPhpFpmChildProcesses( string $poolName, int $signal ) : voi $this->killPoolWorkers( $PIDs, $signal ); } + /** + * @param array $PIDs + * @param int $signal + */ private function killPoolWorkers( array $PIDs, int $signal ) : void { foreach ( $PIDs as $PID ) diff --git a/tests/Integration/UnixDomainSocketTest.php b/tests/Integration/UnixDomainSocketTest.php index ac3662c..918d322 100644 --- a/tests/Integration/UnixDomainSocketTest.php +++ b/tests/Integration/UnixDomainSocketTest.php @@ -64,8 +64,8 @@ protected function setUp() : void protected function tearDown() : void { - $this->connection = null; - $this->client = null; + $this->connection = new UnixDomainSocket( $this->getUnixDomainSocket() ); + $this->client = new Client(); } /** @@ -441,6 +441,9 @@ public function testCanGetLengthOfSentContent( int $length ) : void self::assertEquals( $length, $response->getBody() ); } + /** + * @return array> + */ public function contentLengthProvider() : array { return [ @@ -498,6 +501,9 @@ public function testRequestingAnUnknownScriptPathThrowsException( string $script $this->assertMatchesRegExp( "#^Primary script unknown\n?$#", $response->getError() ); } + /** + * @return array> + */ public function invalidScriptFileNamesProvider() : array { return [ diff --git a/tests/Integration/Workers/lengthWorker.php b/tests/Integration/Workers/lengthWorker.php index 7313944..6089c61 100644 --- a/tests/Integration/Workers/lengthWorker.php +++ b/tests/Integration/Workers/lengthWorker.php @@ -21,4 +21,4 @@ * SOFTWARE. */ -echo strlen( file_get_contents( 'php://input' ) ); +echo strlen( (string)file_get_contents( 'php://input' ) ); diff --git a/tests/Unit/Encoders/NameValuePairEncoderTest.php b/tests/Unit/Encoders/NameValuePairEncoderTest.php index 5346145..020a74f 100644 --- a/tests/Unit/Encoders/NameValuePairEncoderTest.php +++ b/tests/Unit/Encoders/NameValuePairEncoderTest.php @@ -31,7 +31,7 @@ final class NameValuePairEncoderTest extends TestCase { /** - * @param array $pairs + * @param array $pairs * * @throws ExpectationFailedException * @throws InvalidArgumentException @@ -47,23 +47,26 @@ public function testCanEncodeAndDecodePairs( array $pairs ) : void self::assertEquals( $pairs, $decoded ); } + /** + * @return array>> + */ public function pairProvider() : array { return [ [ - ['unit' => 'test'], + 'pairs' => ['unit' => 'test'], ], # no strings [ - [10 => 12.3, 'null' => null], + 'pairs' => [10 => 12.3, 'null' => null], ], # name longer than 128 chars [ - [str_repeat( 'a', 129 ) => 'unit'], + 'pairs' => [str_repeat( 'a', 129 ) => 'unit'], ], # value longer than 128 chars [ - ['unit' => str_repeat( 'b', 129 )], + 'pairs' => ['unit' => str_repeat( 'b', 129 )], ], ]; } diff --git a/tests/Unit/Encoders/PacketEncoderTest.php b/tests/Unit/Encoders/PacketEncoderTest.php index 8da9e13..d8f4929 100644 --- a/tests/Unit/Encoders/PacketEncoderTest.php +++ b/tests/Unit/Encoders/PacketEncoderTest.php @@ -1,4 +1,4 @@ - $expectedHeader * * @throws ExpectationFailedException * @throws InvalidArgumentException * @dataProvider packetContentProvider */ - public function testCanEncodeAndDecodePacket( int $type, string $content, int $requestId, array $expectedHeader ) : void + public function testCanEncodeAndDecodePacket( + int $type, + string $content, + int $requestId, + array $expectedHeader + ) : void { $packetEncoder = new PacketEncoder(); @@ -53,12 +58,17 @@ public function testCanEncodeAndDecodePacket( int $type, string $content, int $r self::assertEquals( substr( $packet, -1 * strlen( $content ) ), $content ); } + /** + * @return array>> + */ public function packetContentProvider() : array { return [ [ - 4, 'test', 1, - [ + 'type' => 4, + 'content' => 'test', + 'requestId' => 1, + 'expectedHeader' => [ 'version' => 1, 'type' => 4, 'requestId' => 1, @@ -68,8 +78,10 @@ public function packetContentProvider() : array ], ], [ - 5, 'çélinö~ß', 12, - [ + 'type' => 5, + 'content' => 'çélinö~ß', + 'requestId' => 12, + 'expectedHeader' => [ 'version' => 1, 'type' => 5, 'requestId' => 12, diff --git a/tests/Unit/RequestContents/JsonDataTest.php b/tests/Unit/RequestContents/JsonDataTest.php index b589216..e9c0451 100644 --- a/tests/Unit/RequestContents/JsonDataTest.php +++ b/tests/Unit/RequestContents/JsonDataTest.php @@ -34,6 +34,9 @@ public function testGetContentType( $data, string $expectedContent ) : void self::assertSame( $expectedContent, (new JsonData( $data ))->getContent() ); } + /** + * @return array> + */ public function jsonDataProvider() : array { return [ diff --git a/tests/Unit/Requests/AbstractRequestTest.php b/tests/Unit/Requests/AbstractRequestTest.php index 80f3d91..00f02f6 100644 --- a/tests/Unit/Requests/AbstractRequestTest.php +++ b/tests/Unit/Requests/AbstractRequestTest.php @@ -84,14 +84,27 @@ public function getRequestMethod() : string }; } + /** + * @return array> + */ public function requestMethodProvider() : array { return [ - ['GET'], - ['POST'], - ['PUT'], - ['PATCH'], - ['DELETE'], + [ + 'requestMethod' => 'GET', + ], + [ + 'requestMethod' => 'POST', + ], + [ + 'requestMethod' => 'PUT', + ], + [ + 'requestMethod' => 'PATCH', + ], + [ + 'requestMethod' => 'DELETE', + ], ]; } diff --git a/tests/Unit/SocketConnections/NetworkSocketTest.php b/tests/Unit/SocketConnections/NetworkSocketTest.php index 23c71ed..bd0b412 100644 --- a/tests/Unit/SocketConnections/NetworkSocketTest.php +++ b/tests/Unit/SocketConnections/NetworkSocketTest.php @@ -96,6 +96,9 @@ public function testCanCheckForEquality( ConfiguresSocketConnection $connection, self::assertSame( $expectedEqual, $connection->equals( $networkConnection ) ); } + /** + * @return array> + */ public function connectionProvider() : array { return [ diff --git a/tests/Unit/SocketConnections/UnixDomainSocketTest.php b/tests/Unit/SocketConnections/UnixDomainSocketTest.php index 0fb85d9..13757e6 100644 --- a/tests/Unit/SocketConnections/UnixDomainSocketTest.php +++ b/tests/Unit/SocketConnections/UnixDomainSocketTest.php @@ -96,6 +96,9 @@ public function testCanCheckForEquality( ConfiguresSocketConnection $connection, self::assertSame( $expectedEqual, $connection->equals( $unixDomainConnection ) ); } + /** + * @return array> + */ public function connectionProvider() : array { return [ diff --git a/tests/Unit/Sockets/SocketCollectionTest.php b/tests/Unit/Sockets/SocketCollectionTest.php index 08ec270..9529586 100644 --- a/tests/Unit/Sockets/SocketCollectionTest.php +++ b/tests/Unit/Sockets/SocketCollectionTest.php @@ -42,7 +42,7 @@ protected function setUp() : void protected function tearDown() : void { - $this->collection = null; + $this->collection = new SocketCollection(); } /** diff --git a/tests/Unit/Sockets/SocketIdTest.php b/tests/Unit/Sockets/SocketIdTest.php index 44cb1fd..e51731b 100644 --- a/tests/Unit/Sockets/SocketIdTest.php +++ b/tests/Unit/Sockets/SocketIdTest.php @@ -67,6 +67,9 @@ public function testThrowsExceptionIfSocketIdValueIsOutOfRange( int $socketIdVal SocketId::fromInt( $socketIdValue ); } + /** + * @return array> + */ public function outOfRangeSocketIdValueProvider() : array { return [ diff --git a/tests/Unit/Sockets/SocketTest.php b/tests/Unit/Sockets/SocketTest.php index c499b93..39c781a 100644 --- a/tests/Unit/Sockets/SocketTest.php +++ b/tests/Unit/Sockets/SocketTest.php @@ -252,6 +252,9 @@ public function testRequestCompletedGuard( self::fail( 'Expected an Exception to be thrown.' ); } + /** + * @return array> + */ public function responseFlagProvider() : array { return [ From d651d9508939be6a88c5aff28287215cf63fcfba Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Thu, 13 Aug 2020 10:51:06 +0200 Subject: [PATCH 15/17] Repeat killing pool processes, #61 --- tests/Integration/SignaledWorkersTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Integration/SignaledWorkersTest.php b/tests/Integration/SignaledWorkersTest.php index 9937b50..4b96d93 100644 --- a/tests/Integration/SignaledWorkersTest.php +++ b/tests/Integration/SignaledWorkersTest.php @@ -23,6 +23,7 @@ use function shell_exec; use function sleep; use function sprintf; +use function usleep; final class SignaledWorkersTest extends TestCase { @@ -257,6 +258,13 @@ static function ( Throwable $e ) use ( &$failures ) private function killPhpFpmChildProcesses( string $poolName, int $signal ) : void { + usleep( 100000 ); + + $PIDs = $this->getPoolWorkerPIDs( $poolName ); + $this->killPoolWorkers( $PIDs, $signal ); + + usleep( 100000 ); + $PIDs = $this->getPoolWorkerPIDs( $poolName ); $this->killPoolWorkers( $PIDs, $signal ); } From 6fac951bf62514d731744f127c144de5ab964f1c Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Thu, 13 Aug 2020 11:01:21 +0200 Subject: [PATCH 16/17] Update changelog, bump v3.1.3, #61 --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a116fa..fb1f6c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a CHANGELOG](http://keepachangelog.com). -## [3.1.3] - UNRELEASED +## [3.1.3] - 2020-08-13 ### Fixed * Remove broken sockets from socket collection if writing the request to stream fails - [#61] +* Do not export `docker-compose.yml` with composer archives via `.gitattributes` +* Stabilize unreliable tests with signaled pool processes ## [3.1.2] - 2020-05-19 From 8cb8a3b658df2fe9e93100eb15570b5081802c87 Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Thu, 13 Aug 2020 11:01:49 +0200 Subject: [PATCH 17/17] Update changelog, bump v3.1.3, #61 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb1f6c1..1aad48f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -394,4 +394,4 @@ Based on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](http [#55]: https://github.com/hollodotme/fast-cgi-client/pull/55 [#56]: https://github.com/hollodotme/fast-cgi-client/issues/56 [#58]: https://github.com/hollodotme/fast-cgi-client/pull/58 -[#61]: https://github.com/hollodotme/fast-cgi-client/pull/61 +[#61]: https://github.com/hollodotme/fast-cgi-client/issues/61