diff --git a/composer.json b/composer.json index 435ac40..03f548f 100644 --- a/composer.json +++ b/composer.json @@ -36,5 +36,8 @@ }, "scripts":{ "phpunit": "phpunit -c phpunit.xml.dist" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index de5e1ce..1ef45c3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,32 +1,21 @@ - - - - tests/phpunit/Unit - - - tests/phpunit/Integration - - - - - src - - - - - - - + + + + + src + + + + + tests/phpunit/Unit + + + tests/phpunit/Integration + + + + + + + diff --git a/src/CurlRequest.php b/src/CurlRequest.php index afda0cd..ec811c5 100644 --- a/src/CurlRequest.php +++ b/src/CurlRequest.php @@ -29,7 +29,7 @@ class CurlRequest implements HttpRequest { */ public function __construct( $handle ) { - if ( get_resource_type( $handle ) !== 'curl' ) { + if ( ( is_resource( $handle ) && get_resource_type( $handle ) !== 'curl' ) || $handle instanceof CurlHandle ) { throw new InvalidArgumentException( "Expected a cURL resource type" ); } diff --git a/src/MultiCurlRequest.php b/src/MultiCurlRequest.php index 212d218..9e37383 100644 --- a/src/MultiCurlRequest.php +++ b/src/MultiCurlRequest.php @@ -40,7 +40,7 @@ class MultiCurlRequest implements HttpRequest { */ public function __construct( $handle ) { - if ( get_resource_type( $handle ) !== 'curl_multi' ) { + if ( ( is_resource( $handle ) && get_resource_type( $handle ) !== 'curl_multi' ) || $handle instanceof CurlMultiHandle ) { throw new InvalidArgumentException( "Expected a cURL multi resource type" ); } diff --git a/tests/phpunit/Integration/RequestToExternalUrlTest.php b/tests/phpunit/Integration/RequestToExternalUrlTest.php index 0e9ed8e..6a9b28e 100644 --- a/tests/phpunit/Integration/RequestToExternalUrlTest.php +++ b/tests/phpunit/Integration/RequestToExternalUrlTest.php @@ -14,7 +14,7 @@ * * @author mwjames */ -class RequestToExternalUrlTest extends \PHPUnit_Framework_TestCase { +class RequestToExternalUrlTest extends \PHPUnit\Framework\TestCase { public function testCachedRequestToExternalUrl() { @@ -35,8 +35,7 @@ public function testCachedRequestToExternalUrl() { $instance->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, 42 ); $instance->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX, 'foo' ); - $this->assertInternalType( - 'string', + $this->assertIsString( $instance->execute() ); diff --git a/tests/phpunit/Integration/RequestToPhpHttpdTest.php b/tests/phpunit/Integration/RequestToPhpHttpdTest.php index b9a96ec..f8cbb2f 100644 --- a/tests/phpunit/Integration/RequestToPhpHttpdTest.php +++ b/tests/phpunit/Integration/RequestToPhpHttpdTest.php @@ -14,7 +14,7 @@ * * @author mwjames */ -class RequestToPhpHttpdTest extends \PHPUnit_Framework_TestCase { +class RequestToPhpHttpdTest extends \PHPUnit\Framework\TestCase { private static $pid; @@ -25,7 +25,7 @@ class RequestToPhpHttpdTest extends \PHPUnit_Framework_TestCase { * Options defined in phpunit.xml.dist * @see https://github.com/vgno/tech.vg.no-1812/blob/master/features/bootstrap/FeatureContext.php */ - public static function setUpBeforeClass() { + public static function setUpBeforeClass(): void { $command = sprintf( 'php -S %s:%d -t %s >/dev/null 2>&1 & echo $!', WEB_SERVER_HOST, @@ -39,7 +39,7 @@ public static function setUpBeforeClass() { self::$pid = (int) $output[0]; } - public static function tearDownAfterClass() { + public static function tearDownAfterClass(): void { // exec( 'kill ' . (int) self::$pid ); } diff --git a/tests/phpunit/Unit/CachedCurlRequestTest.php b/tests/phpunit/Unit/CachedCurlRequestTest.php index d62a0b6..317b544 100644 --- a/tests/phpunit/Unit/CachedCurlRequestTest.php +++ b/tests/phpunit/Unit/CachedCurlRequestTest.php @@ -13,7 +13,7 @@ * * @author mwjames */ -class CachedCurlRequestTest extends \PHPUnit_Framework_TestCase { +class CachedCurlRequestTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { @@ -72,13 +72,12 @@ public function testDifferentOptionsToGenerateDifferentKeys() { ->setMethods( array( 'contains' ) ) ->getMockForAbstractClass(); - $cache->expects( $this->at( 0 ) ) + $cache->expects( $this->exactly( 2 ) ) ->method( 'contains' ) - ->with( $this->equalTo( 'onoi:http:7ccbcfd552a597d67077d6cc037580ac' ) ); - - $cache->expects( $this->at( 1 ) ) - ->method( 'contains' ) - ->with( $this->equalTo( 'onoi:http:e2015ad4244c4663f10f305e299d5c4f' ) ); + ->withConsecutive( + [$this->equalTo( 'onoi:http:7ccbcfd552a597d67077d6cc037580ac' )], + [$this->equalTo( 'onoi:http:e2015ad4244c4663f10f305e299d5c4f' )] + ); $instance = new CachedCurlRequest( curl_init(), $cache ); @@ -96,13 +95,12 @@ public function testToHaveTargetUrlAsPartOfTheCacheKey() { ->setMethods( array( 'contains', 'save' ) ) ->getMockForAbstractClass(); - $cache->expects( $this->at( 0 ) ) - ->method( 'contains' ) - ->with( $this->equalTo( 'onoi:http:236b194825be3d614ce5fc1b7763a278' ) ); - - $cache->expects( $this->at( 2 ) ) + $cache->expects( $this->exactly( 2 ) ) ->method( 'contains' ) - ->with( $this->equalTo( 'onoi:http:823a603f972819c10d13f32b14460573' ) ); + ->withConsecutive( + [$this->equalTo( 'onoi:http:236b194825be3d614ce5fc1b7763a278' )], + [$this->equalTo( 'onoi:http:823a603f972819c10d13f32b14460573' )] + ); $instance = new CachedCurlRequest( curl_init( 'http://example.org' ), $cache ); diff --git a/tests/phpunit/Unit/CurlRequestTest.php b/tests/phpunit/Unit/CurlRequestTest.php index 5af5a89..9fb7c6c 100644 --- a/tests/phpunit/Unit/CurlRequestTest.php +++ b/tests/phpunit/Unit/CurlRequestTest.php @@ -13,7 +13,7 @@ * * @author mwjames */ -class CurlRequestTest extends \PHPUnit_Framework_TestCase { +class CurlRequestTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { @@ -31,7 +31,7 @@ public function testCanConstruct() { } public function testWrongResourceTypeThrowsException() { - $this->setExpectedException( 'InvalidArgumentException' ); + $this->expectException( 'InvalidArgumentException' ); new CurlRequest( curl_multi_init() ); } @@ -45,8 +45,7 @@ public function testPing() { $instance->setOption( CURLOPT_URL, 'http://example.org' ); - $this->assertInternalType( - 'boolean', + $this->assertIsBool( $instance->ping() ); } @@ -55,8 +54,7 @@ public function testGetLastError() { $instance = new CurlRequest( curl_init() ); - $this->assertInternalType( - 'string', + $this->assertIsString( $instance->getLastError() ); } @@ -65,8 +63,7 @@ public function testGetLastErrorCode() { $instance = new CurlRequest( curl_init() ); - $this->assertInternalType( - 'integer', + $this->assertIsInt( $instance->getLastErrorCode() ); } diff --git a/tests/phpunit/Unit/Exception/BadHttpResponseExceptionTest.php b/tests/phpunit/Unit/Exception/BadHttpResponseExceptionTest.php index 5a6646f..114c219 100644 --- a/tests/phpunit/Unit/Exception/BadHttpResponseExceptionTest.php +++ b/tests/phpunit/Unit/Exception/BadHttpResponseExceptionTest.php @@ -14,11 +14,11 @@ * * @author mwjames */ -class BadHttpResponseExceptionTest extends \PHPUnit_Framework_TestCase { +class BadHttpResponseExceptionTest extends \PHPUnit\Framework\TestCase { private $httpRequest; - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' ) @@ -73,7 +73,7 @@ public function testForCurlRequest() { $e = new BadHttpResponseException( $curlRequest ); - $this->assertContains( + $this->assertStringContainsString( 'error 3', $e->getMessage() ); diff --git a/tests/phpunit/Unit/Exception/HttpConnectionExceptionTest.php b/tests/phpunit/Unit/Exception/HttpConnectionExceptionTest.php index 7da630f..9105a2b 100644 --- a/tests/phpunit/Unit/Exception/HttpConnectionExceptionTest.php +++ b/tests/phpunit/Unit/Exception/HttpConnectionExceptionTest.php @@ -14,7 +14,7 @@ * * @author mwjames */ -class HttpConnectionExceptionTest extends \PHPUnit_Framework_TestCase { +class HttpConnectionExceptionTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { @@ -28,7 +28,7 @@ public function testErrorMessage() { $e = new HttpConnectionException( 'foo', 42 ); - $this->assertContains( + $this->assertStringContainsString( 'foo', $e->getMessage() ); diff --git a/tests/phpunit/Unit/HttpRequestFactoryTest.php b/tests/phpunit/Unit/HttpRequestFactoryTest.php index 9fe4767..1b120a2 100644 --- a/tests/phpunit/Unit/HttpRequestFactoryTest.php +++ b/tests/phpunit/Unit/HttpRequestFactoryTest.php @@ -13,7 +13,7 @@ * * @author mwjames */ -class HttpRequestFactoryTest extends \PHPUnit_Framework_TestCase { +class HttpRequestFactoryTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { diff --git a/tests/phpunit/Unit/MockedHttpStreamSocketRequestTest.php b/tests/phpunit/Unit/MockedHttpStreamSocketRequestTest.php index 3174739..a70b5ea 100644 --- a/tests/phpunit/Unit/MockedHttpStreamSocketRequestTest.php +++ b/tests/phpunit/Unit/MockedHttpStreamSocketRequestTest.php @@ -13,9 +13,9 @@ * * @author mwjames */ -class MockedHttpStreamSocketRequestTest extends \PHPUnit_Framework_TestCase { +class MockedHttpStreamSocketRequestTest extends \PHPUnit\Framework\TestCase { - public function setUp() { + public function setUp(): void { parent::setUp(); stream_wrapper_unregister( 'http' ); @@ -44,7 +44,7 @@ public function getMockStream( $data, $code = 'HTTP/1.1 200 OK' ) { return fopen( 'http://example.com', 'r', false, $context ); } - public function tearDown() { + public function tearDown(): void { stream_wrapper_restore('http'); } diff --git a/tests/phpunit/Unit/MultiCurlRequestTest.php b/tests/phpunit/Unit/MultiCurlRequestTest.php index f85698b..998ba89 100644 --- a/tests/phpunit/Unit/MultiCurlRequestTest.php +++ b/tests/phpunit/Unit/MultiCurlRequestTest.php @@ -14,7 +14,7 @@ * * @author mwjames */ -class MultiCurlRequestTest extends \PHPUnit_Framework_TestCase { +class MultiCurlRequestTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { @@ -32,7 +32,7 @@ public function testCanConstruct() { } public function testWrongResourceTypeThrowsException() { - $this->setExpectedException( 'InvalidArgumentException' ); + $this->expectException( 'InvalidArgumentException' ); new MultiCurlRequest( curl_init() ); } @@ -98,13 +98,11 @@ public function testExecuteForResponse() { new CurlRequest( curl_init() ) ); - $this->assertInternalType( - 'array', + $this->assertIsArray( $instance->execute() ); - $this->assertInternalType( - 'string', + $this->assertIsString( $instance->getLastError() ); diff --git a/tests/phpunit/Unit/NullRequestTest.php b/tests/phpunit/Unit/NullRequestTest.php index 03c3065..d4f8729 100644 --- a/tests/phpunit/Unit/NullRequestTest.php +++ b/tests/phpunit/Unit/NullRequestTest.php @@ -13,7 +13,7 @@ * * @author mwjames */ -class NullRequestTest extends \PHPUnit_Framework_TestCase { +class NullRequestTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { @@ -34,38 +34,31 @@ public function testNull() { $instance = new NullRequest(); - $this->assertInternalType( - 'boolean', + $this->assertIsBool( $instance->ping() ); - $this->assertInternalType( - 'null', + $this->assertNull( $instance->setOption( 'foo', 42 ) ); - $this->assertInternalType( - 'null', + $this->assertNull( $instance->getOption( 'foo' ) ); - $this->assertInternalType( - 'null', + $this->assertNull( $instance->getLastTransferInfo() ); - $this->assertInternalType( - 'string', + $this->assertIsString( $instance->getLastError() ); - $this->assertInternalType( - 'integer', + $this->assertIsInt( $instance->getLastErrorCode() ); - $this->assertInternalType( - 'null', + $this->assertNull( $instance->execute() ); } diff --git a/tests/phpunit/Unit/RequestResponseTest.php b/tests/phpunit/Unit/RequestResponseTest.php index 99b616a..3a1b4e6 100644 --- a/tests/phpunit/Unit/RequestResponseTest.php +++ b/tests/phpunit/Unit/RequestResponseTest.php @@ -13,7 +13,7 @@ * * @author mwjames */ -class RequestResponseTest extends \PHPUnit_Framework_TestCase { +class RequestResponseTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { @@ -43,8 +43,7 @@ public function testSetGetValue() { $instance->getList() ); - $this->assertInternalType( - 'string', + $this->assertIsString( $instance->asJsonString() ); } @@ -53,7 +52,7 @@ public function testUnregisteredKeyThrowsException() { $instance = new RequestResponse(); - $this->setExpectedException( 'InvalidArgumentException' ); + $this->expectException( 'InvalidArgumentException' ); $instance->get( 'Foo' ); } diff --git a/tests/phpunit/Unit/SocketRequestTest.php b/tests/phpunit/Unit/SocketRequestTest.php index 1fe34a0..70b52b8 100644 --- a/tests/phpunit/Unit/SocketRequestTest.php +++ b/tests/phpunit/Unit/SocketRequestTest.php @@ -13,7 +13,7 @@ * * @author mwjames */ -class SocketRequestTest extends \PHPUnit_Framework_TestCase { +class SocketRequestTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { @@ -40,8 +40,7 @@ public function testPing() { $instance->setOption( ONOI_HTTP_REQUEST_URL, 'http://example.org' ); - $this->assertInternalType( - 'boolean', + $this->assertIsBool( $instance->ping() ); } @@ -52,8 +51,7 @@ public function testExecute() { $instance->setOption( ONOI_HTTP_REQUEST_CONNECTION_TIMEOUT, 1 ); $instance->setOption( ONOI_HTTP_REQUEST_URL, 'http://localhost:8888' ); - $this->assertInternalType( - 'boolean', + $this->assertIsBool( $instance->execute() ); } @@ -65,8 +63,7 @@ public function testGetLastError() { $instance->execute(); - $this->assertInternalType( - 'string', + $this->assertIsString( $instance->getLastError() ); } @@ -75,8 +72,7 @@ public function testGetLastErrorCode() { $instance = new SocketRequest(); - $this->assertInternalType( - 'integer', + $this->assertIsInt( $instance->getLastErrorCode() ); } @@ -85,8 +81,7 @@ public function testGetLastTransferInfo() { $instance = new SocketRequest(); - $this->assertInternalType( - 'string', + $this->assertIsString( $instance->getLastTransferInfo() ); }