diff --git a/.circleci/config.yml b/.circleci/config.yml
index 980e96c..10b85b5 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
@@ -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/.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} \
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
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index cbb7a69..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
@@ -53,8 +53,9 @@ 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
+ --testdox
env:
COMPOSE_INTERACTIVE_NO_CLI: 1
PHP_OPTIONS: "-d error_reporting=-1 -d auto_prepend_file=/repo/build/xdebug-filter.php"
@@ -71,8 +72,9 @@ 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
+ --testdox
env:
COMPOSE_INTERACTIVE_NO_CLI: 1
PHP_OPTIONS: "-d error_reporting=-1 -d auto_prepend_file=/repo/build/xdebug-filter.php"
@@ -89,8 +91,9 @@ 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
+ --testdox
env:
COMPOSE_INTERACTIVE_NO_CLI: 1
PHP_OPTIONS: "-d error_reporting=-1 -d auto_prepend_file=/repo/build/xdebug-filter.php"
@@ -107,8 +110,9 @@ 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
+ --testdox
env:
COMPOSE_INTERACTIVE_NO_CLI: 1
PHP_OPTIONS: "-d error_reporting=-1 -d auto_prepend_file=/repo/build/xdebug-filter.php"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4040519..1aad48f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,14 @@
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] - 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
### Added
@@ -338,6 +346,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 +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/issues/61
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/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
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;
+ }
}
/**
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 )
{
diff --git a/tests/Integration/AsyncRequestsTest.php b/tests/Integration/AsyncRequestsTest.php
index 71aafbe..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
@@ -40,7 +39,7 @@ public function testAsyncRequestsWillRespondToCallbackIfRequestsExceedPhpFpmMaxC
$maxChildren = $this->getMaxChildrenSettingFromNetworkSocket();
$limit = $maxChildren + 5;
- $this->assertTrue( $limit > 5 );
+ self::assertTrue( $limit > 5 );
$client = new Client();
$results = [];
@@ -65,12 +64,12 @@ static function ( ProvidesResponseData $response ) use ( &$results )
sort( $results );
- $this->assertSame( $expectedResults, $results );
+ self::assertSame( $expectedResults, $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
@@ -101,7 +99,7 @@ public function testAsyncRequestsWillRespondToCallbackIfRequestsExceedPhpFpmMaxC
$maxChildren = $this->getMaxChildrenSettingFromUnixDomainSocket();
$limit = $maxChildren + 5;
- $this->assertTrue( $limit > 5 );
+ self::assertTrue( $limit > 5 );
$client = new Client();
$results = [];
@@ -126,12 +124,12 @@ static function ( ProvidesResponseData $response ) use ( &$results )
sort( $results );
- $this->assertSame( $expectedResults, $results );
+ self::assertSame( $expectedResults, $results );
}
private function getMaxChildrenSettingFromUnixDomainSocket() : int
{
- $iniSettings = parse_ini_file(
+ $iniSettings = (array)parse_ini_file(
__DIR__ . '/../../.docker/php/unix-domain-socket.pool.conf',
true
);
@@ -147,17 +145,17 @@ private function getUnixDomainSocketConnection() : UnixDomainSocket
/**
* @throws ConnectException
* @throws ExpectationFailedException
- * @throws InvalidArgumentException
* @throws ReadFailedException
* @throws TimedoutException
* @throws WriteFailedException
+ * @throws InvalidArgumentException
*/
public function testCanReadResponsesOfAsyncRequestsIfRequestsExceedPhpFpmMaxChildrenSettingOnNetworkSocket() : void
{
$maxChildren = $this->getMaxChildrenSettingFromNetworkSocket();
$limit = $maxChildren + 5;
- $this->assertTrue( $limit > 5 );
+ self::assertTrue( $limit > 5 );
$client = new Client();
$results = [];
@@ -182,7 +180,7 @@ public function testCanReadResponsesOfAsyncRequestsIfRequestsExceedPhpFpmMaxChil
sort( $results );
- $this->assertSame( $expectedResults, $results );
+ self::assertSame( $expectedResults, $results );
}
/**
@@ -199,7 +197,7 @@ public function testCanReadResponsesOfAsyncRequestsIfRequestsExceedPhpFpmMaxChil
$maxChildren = $this->getMaxChildrenSettingFromUnixDomainSocket();
$limit = $maxChildren + 5;
- $this->assertTrue( $limit > 5 );
+ self::assertTrue( $limit > 5 );
$client = new Client();
$results = [];
@@ -230,6 +228,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..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();
}
/**
@@ -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..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();
}
/**
@@ -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,9 +439,12 @@ 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() );
}
+ /**
+ * @return array>
+ */
public function contentLengthProvider() : array
{
return [
@@ -497,8 +500,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() );
}
@@ -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 [
@@ -542,12 +548,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 +573,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 +683,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 +700,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 f2ab9a4..4b96d93 100644
--- a/tests/Integration/SignaledWorkersTest.php
+++ b/tests/Integration/SignaledWorkersTest.php
@@ -19,11 +19,11 @@
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;
use function sprintf;
+use function usleep;
final class SignaledWorkersTest extends TestCase
{
@@ -76,13 +76,16 @@ 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 );
}
+ /**
+ * @return array>
+ */
public function signalProvider() : array
{
return [
@@ -113,13 +116,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 )
@@ -184,9 +192,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,23 +249,36 @@ 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 );
}
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 );
}
+ /**
+ * @param array $PIDs
+ * @param int $signal
+ */
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 );
+ }
}
/**
@@ -305,10 +326,52 @@ 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 );
}
+
+ /**
+ * @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/UnixDomainSocketTest.php b/tests/Integration/UnixDomainSocketTest.php
index b4d18d9..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();
}
/**
@@ -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,9 +438,12 @@ public function testCanGetLengthOfSentContent( int $length ) : void
$response = $this->client->sendRequest( $this->connection, $request );
- $this->assertEquals( $length, $response->getBody() );
+ self::assertEquals( $length, $response->getBody() );
}
+ /**
+ * @return array>
+ */
public function contentLengthProvider() : array
{
return [
@@ -493,11 +496,14 @@ 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() );
}
+ /**
+ * @return array>
+ */
public function invalidScriptFileNamesProvider() : array
{
return [
@@ -525,12 +531,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 +556,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 +679,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 +696,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/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/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 @@
+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..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
@@ -44,26 +44,29 @@ public function testCanEncodeAndDecodePairs( array $pairs ) : void
$encoded = $nameValuePairEncoder->encodePairs( $pairs );
$decoded = $nameValuePairEncoder->decodePairs( $encoded );
- $this->assertEquals( $pairs, $decoded );
+ 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 b7c09a3..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();
@@ -49,16 +54,21 @@ 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 );
}
+ /**
+ * @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 a377860..e9c0451 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,9 +31,12 @@ 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() );
}
+ /**
+ * @return array>
+ */
public function jsonDataProvider() : array
{
return [
@@ -68,6 +71,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..00f02f6 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() );
}
/**
@@ -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',
+ ],
];
}
@@ -125,7 +138,7 @@ public function testCanGetParametersArray( string $requestMethod ) : void
'CONTENT_LENGTH' => 9,
];
- $this->assertSame( $expectedParams, $request->getParams() );
+ self::assertSame( $expectedParams, $request->getParams() );
}
/**
@@ -136,11 +149,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 +196,7 @@ public function testCanOverwriteVars() : void
'CONTENT_LENGTH' => 9,
];
- $this->assertSame( $expectedParams, $request->getParams() );
+ self::assertSame( $expectedParams, $request->getParams() );
}
/**
@@ -195,10 +208,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..bd0b412 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,10 +92,13 @@ 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 ) );
}
+ /**
+ * @return array>
+ */
public function connectionProvider() : array
{
return [
diff --git a/tests/Unit/SocketConnections/UnixDomainSocketTest.php b/tests/Unit/SocketConnections/UnixDomainSocketTest.php
index 49bf3d4..13757e6 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,10 +92,13 @@ 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 ) );
}
+ /**
+ * @return array>
+ */
public function connectionProvider() : array
{
return [
diff --git a/tests/Unit/Sockets/SocketCollectionTest.php b/tests/Unit/Sockets/SocketCollectionTest.php
index f49d902..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();
}
/**
@@ -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..e51731b 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() );
}
}
@@ -67,6 +67,9 @@ public function testThrowsExceptionIfSocketIdValueIsOutOfRange( int $socketIdVal
SocketId::fromInt( $socketIdValue );
}
+ /**
+ * @return array>
+ */
public function outOfRangeSocketIdValueProvider() : array
{
return [
@@ -90,17 +93,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..39c781a 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,9 +249,12 @@ public function testRequestCompletedGuard(
$guardMethod->invoke( $socket, $flag );
- $this->fail( 'Expected an Exception to be thrown.' );
+ self::fail( 'Expected an Exception to be thrown.' );
}
+ /**
+ * @return array>
+ */
public function responseFlagProvider() : array
{
return [
@@ -287,7 +290,7 @@ public function testIsUsableWhenInInitialState() : void
{
$socket = $this->getSocket();
- $this->assertTrue( $socket->isUsable() );
+ self::assertTrue( $socket->isUsable() );
}
/**
@@ -315,7 +318,7 @@ public function testIsNotUsableWhenTimedOut() : void
{
}
- $this->assertFalse( $socket->isUsable() );
+ self::assertFalse( $socket->isUsable() );
}
/**
@@ -336,7 +339,7 @@ public function testIsNotUsableWhenSocketWasClosed() : void
$disconnectMethod->setAccessible( true );
$disconnectMethod->invoke( $socket );
- $this->assertFalse( $socket->isUsable() );
+ self::assertFalse( $socket->isUsable() );
}
/**
@@ -366,10 +369,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 ) );
}
}
diff --git a/tests/runTestsOnAllLocalPhpVersions.sh b/tests/runTestsOnAllLocalPhpVersions.sh
index 32f98c1..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
+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
+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
+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
+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