diff --git a/composer.json b/composer.json index 33919186..2fe67da0 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "clue/http-proxy-react": "^1.8", "clue/reactphp-ssh-proxy": "^1.4", "clue/socks-react": "^1.4", - "phpunit/phpunit": "^9.6 || ^5.7", + "phpunit/phpunit": "^9.6 || ^7.5", "react/async": "^4 || ^3", "react/promise-stream": "^1.4", "react/promise-timer": "^1.9" diff --git a/phpunit.xml.legacy b/phpunit.xml.legacy index a018d7ab..00868603 100644 --- a/phpunit.xml.legacy +++ b/phpunit.xml.legacy @@ -2,7 +2,7 @@ diff --git a/tests/BrowserTest.php b/tests/BrowserTest.php index a7188b2c..8f3e10bd 100644 --- a/tests/BrowserTest.php +++ b/tests/BrowserTest.php @@ -3,8 +3,11 @@ namespace React\Tests\Http; use Psr\Http\Message\RequestInterface; +use React\EventLoop\LoopInterface; +use React\Http\Io\Transaction; use React\Http\Browser; use React\Promise\Promise; +use React\Socket\ConnectorInterface; class BrowserTest extends TestCase { @@ -17,8 +20,8 @@ class BrowserTest extends TestCase */ public function setUpBrowser() { - $this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); - $this->sender = $this->getMockBuilder('React\Http\Io\Transaction')->disableOriginalConstructor()->getMock(); + $this->loop = $this->createMock(LoopInterface::class); + $this->sender = $this->createMock(Transaction::class); $this->browser = new Browser(null, $this->loop); $ref = new \ReflectionProperty($this->browser, 'transaction'); @@ -38,12 +41,12 @@ public function testConstructWithoutLoopAssignsLoopAutomatically() $ref->setAccessible(true); $loop = $ref->getValue($transaction); - $this->assertInstanceOf('React\EventLoop\LoopInterface', $loop); + $this->assertInstanceOf(LoopInterface::class, $loop); } public function testConstructWithConnectorAssignsGivenConnector() { - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $browser = new Browser($connector); @@ -250,108 +253,106 @@ public function testWithBase() { $browser = $this->browser->withBase('http://example.com/root'); - $this->assertInstanceOf('React\Http\Browser', $browser); + $this->assertInstanceOf(Browser::class, $browser); $this->assertNotSame($this->browser, $browser); } - public function provideOtherUris() - { - return [ - 'empty returns base' => [ - 'http://example.com/base', - '', - 'http://example.com/base', - ], - 'absolute same as base returns base' => [ - 'http://example.com/base', - 'http://example.com/base', - 'http://example.com/base', - ], - 'absolute below base returns absolute' => [ - 'http://example.com/base', - 'http://example.com/base/another', - 'http://example.com/base/another', - ], - 'slash returns base without path' => [ - 'http://example.com/base', - '/', - 'http://example.com/', - ], - 'relative is added behind base' => [ - 'http://example.com/base/', - 'test', - 'http://example.com/base/test', - ], - 'relative is added behind base without path' => [ - 'http://example.com/base', - 'test', - 'http://example.com/test', - ], - 'relative level up is added behind parent path' => [ - 'http://example.com/base/foo/', - '../bar', - 'http://example.com/base/bar', - ], - 'absolute with slash is added behind base without path' => [ - 'http://example.com/base', - '/test', - 'http://example.com/test', - ], - 'query string is added behind base' => [ - 'http://example.com/base', - '?key=value', - 'http://example.com/base?key=value', - ], - 'query string is added behind base with slash' => [ - 'http://example.com/base/', - '?key=value', - 'http://example.com/base/?key=value', - ], - 'query string with slash is added behind base without path' => [ - 'http://example.com/base', - '/?key=value', - 'http://example.com/?key=value', - ], - 'absolute with query string below base is returned as-is' => [ - 'http://example.com/base', - 'http://example.com/base?test', - 'http://example.com/base?test', - ], - 'urlencoded special chars will stay as-is' => [ - 'http://example.com/%7Bversion%7D/', - '', - 'http://example.com/%7Bversion%7D/' - ], - 'special chars will be urlencoded' => [ - 'http://example.com/{version}/', - '', - 'http://example.com/%7Bversion%7D/' - ], - 'other domain' => [ - 'http://example.com/base/', - 'http://example.org/base/', - 'http://example.org/base/' - ], - 'other scheme' => [ - 'http://example.com/base/', - 'https://example.com/base/', - 'https://example.com/base/' - ], - 'other port' => [ - 'http://example.com/base/', - 'http://example.com:81/base/', - 'http://example.com:81/base/' - ], - 'other path' => [ - 'http://example.com/base/', - 'http://example.com/other/', - 'http://example.com/other/' - ], - 'other path due to missing slash' => [ - 'http://example.com/base/', - 'http://example.com/other', - 'http://example.com/other' - ], + public static function provideOtherUris() + { + yield 'empty returns base' => [ + 'http://example.com/base', + '', + 'http://example.com/base', + ]; + yield 'absolute same as base returns base' => [ + 'http://example.com/base', + 'http://example.com/base', + 'http://example.com/base', + ]; + yield 'absolute below base returns absolute' => [ + 'http://example.com/base', + 'http://example.com/base/another', + 'http://example.com/base/another', + ]; + yield 'slash returns base without path' => [ + 'http://example.com/base', + '/', + 'http://example.com/', + ]; + yield 'relative is added behind base' => [ + 'http://example.com/base/', + 'test', + 'http://example.com/base/test', + ]; + yield 'relative is added behind base without path' => [ + 'http://example.com/base', + 'test', + 'http://example.com/test', + ]; + yield 'relative level up is added behind parent path' => [ + 'http://example.com/base/foo/', + '../bar', + 'http://example.com/base/bar', + ]; + yield 'absolute with slash is added behind base without path' => [ + 'http://example.com/base', + '/test', + 'http://example.com/test', + ]; + yield 'query string is added behind base' => [ + 'http://example.com/base', + '?key=value', + 'http://example.com/base?key=value', + ]; + yield 'query string is added behind base with slash' => [ + 'http://example.com/base/', + '?key=value', + 'http://example.com/base/?key=value', + ]; + yield 'query string with slash is added behind base without path' => [ + 'http://example.com/base', + '/?key=value', + 'http://example.com/?key=value', + ]; + yield 'absolute with query string below base is returned as-is' => [ + 'http://example.com/base', + 'http://example.com/base?test', + 'http://example.com/base?test', + ]; + yield 'urlencoded special chars will stay as-is' => [ + 'http://example.com/%7Bversion%7D/', + '', + 'http://example.com/%7Bversion%7D/' + ]; + yield 'special chars will be urlencoded' => [ + 'http://example.com/{version}/', + '', + 'http://example.com/%7Bversion%7D/' + ]; + yield 'other domain' => [ + 'http://example.com/base/', + 'http://example.org/base/', + 'http://example.org/base/' + ]; + yield 'other scheme' => [ + 'http://example.com/base/', + 'https://example.com/base/', + 'https://example.com/base/' + ]; + yield 'other port' => [ + 'http://example.com/base/', + 'http://example.com:81/base/', + 'http://example.com:81/base/' + ]; + yield 'other path' => [ + 'http://example.com/base/', + 'http://example.com/other/', + 'http://example.com/other/' + ]; + yield 'other path due to missing slash' => [ + 'http://example.com/base/', + 'http://example.com/other', + 'http://example.com/other' ]; } @@ -374,13 +375,13 @@ public function testResolveUriWithBaseEndsWithoutSlash($base, $uri, $expectedAbs public function testWithBaseUrlNotAbsoluteFails() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->browser->withBase('hello'); } public function testWithBaseUrlInvalidSchemeFails() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->browser->withBase('ftp://example.com'); } @@ -410,7 +411,7 @@ public function testWithProtocolVersionFollowedByGetRequestSendsRequestWithProto public function testWithProtocolVersionInvalidThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->browser->withProtocolVersion('1.2'); } @@ -418,7 +419,7 @@ public function testCancelGetRequestShouldCancelUnderlyingSocketConnection() { $pending = new Promise(function () { }, $this->expectCallableOnce()); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->with('example.com:80')->willReturn($pending); $this->browser = new Browser($connector, $this->loop); diff --git a/tests/FunctionalBrowserTest.php b/tests/FunctionalBrowserTest.php index 92c873d1..d89d92e9 100644 --- a/tests/FunctionalBrowserTest.php +++ b/tests/FunctionalBrowserTest.php @@ -176,7 +176,8 @@ public function testGetRequestWithRelativeAddressRejects() { $promise = $this->browser->get('delay'); - $this->setExpectedException('InvalidArgumentException', 'Invalid request URL given'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid request URL given'); await($promise); } @@ -201,7 +202,7 @@ public function testCancelGetRequestWillRejectRequest() $promise = $this->browser->get($this->base . 'get'); $promise->cancel(); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); await($promise); } @@ -212,13 +213,13 @@ public function testCancelRequestWithPromiseFollowerWillRejectRequest() }); $promise->cancel(); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); await($promise); } public function testRequestWithoutAuthenticationFails() { - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); await($this->browser->get($this->base . 'basic-auth/user/pass')); } @@ -269,7 +270,8 @@ public function testCancelRedirectedRequestShouldReject() $promise->cancel(); }); - $this->setExpectedException('RuntimeException', 'Request cancelled'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Request cancelled'); await($promise); } @@ -277,7 +279,8 @@ public function testTimeoutDelayedResponseShouldReject() { $promise = $this->browser->withTimeout(0.1)->get($this->base . 'delay/10'); - $this->setExpectedException('RuntimeException', 'Request timed out after 0.1 seconds'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Request timed out after 0.1 seconds'); await($promise); } @@ -287,7 +290,8 @@ public function testTimeoutDelayedResponseAfterStreamingRequestShouldReject() $promise = $this->browser->withTimeout(0.1)->post($this->base . 'delay/10', [], $stream); $stream->end(); - $this->setExpectedException('RuntimeException', 'Request timed out after 0.1 seconds'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Request timed out after 0.1 seconds'); await($promise); } @@ -329,7 +333,7 @@ public function testFollowRedirectsZeroRejectsOnRedirect() { $browser = $this->browser->withFollowRedirects(0); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); await($browser->get($this->base . 'redirect-to?url=get')); } @@ -367,11 +371,9 @@ public function testGetRequestWithResponseBufferExceededRejects() { $promise = $this->browser->withResponseBuffer(4)->get($this->base . 'get'); - $this->setExpectedException( - 'OverflowException', - 'Response body size of 5 bytes exceeds maximum of 4 bytes', - defined('SOCKET_EMSGSIZE') ? SOCKET_EMSGSIZE : 0 - ); + $this->expectException(\OverflowException::class); + $this->expectExceptionMessage('Response body size of 5 bytes exceeds maximum of 4 bytes'); + $this->expectExceptionCode(defined('SOCKET_EMSGSIZE') ? SOCKET_EMSGSIZE : 0); await($promise); } @@ -379,11 +381,9 @@ public function testGetRequestWithResponseBufferExceededDuringStreamingRejects() { $promise = $this->browser->withResponseBuffer(4)->get($this->base . 'stream/1'); - $this->setExpectedException( - 'OverflowException', - 'Response body size exceeds maximum of 4 bytes', - defined('SOCKET_EMSGSIZE') ? SOCKET_EMSGSIZE : 0 - ); + $this->expectException(\OverflowException::class); + $this->expectExceptionMessage('Response body size exceeds maximum of 4 bytes'); + $this->expectExceptionCode(defined('SOCKET_EMSGSIZE') ? SOCKET_EMSGSIZE : 0); await($promise); } @@ -409,7 +409,7 @@ public function testVerifyPeerEnabledForBadSslRejects() $browser = new Browser($connector); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); await($browser->get('https://self-signed.badssl.com/')); } @@ -435,7 +435,7 @@ public function testVerifyPeerDisabledForBadSslResolves() */ public function testInvalidPort() { - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); await($this->browser->get('http://www.google.com:443/')); } @@ -447,7 +447,7 @@ public function testErrorStatusCodeRejectsWithResponseException() } catch (ResponseException $e) { $this->assertEquals(404, $e->getCode()); - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $e->getResponse()); + $this->assertInstanceOf(ResponseInterface::class, $e->getResponse()); $this->assertEquals(404, $e->getResponse()->getStatusCode()); } } @@ -762,7 +762,7 @@ public function testRequestStreamingGetReceivesResponseWithStreamingBodyAndKnown $body = $response->getBody(); $this->assertEquals(5, $body->getSize()); $this->assertEquals('', (string) $body); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); } public function testRequestStreamingGetReceivesResponseWithStreamingBodyAndUnknownSizeFromStreamingEndpoint() @@ -773,7 +773,7 @@ public function testRequestStreamingGetReceivesResponseWithStreamingBodyAndUnkno $body = $response->getBody(); $this->assertNull($body->getSize()); $this->assertEquals('', (string) $body); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); } public function testRequestStreamingGetReceivesStreamingResponseBody() diff --git a/tests/FunctionalHttpServerTest.php b/tests/FunctionalHttpServerTest.php index c0fcfe83..dc0bd276 100644 --- a/tests/FunctionalHttpServerTest.php +++ b/tests/FunctionalHttpServerTest.php @@ -43,8 +43,8 @@ public function testPlainHttpOnRandomPort() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('http://' . noScheme($socket->getAddress()) . '/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('http://' . noScheme($socket->getAddress()) . '/', $response); $socket->close(); } @@ -70,7 +70,7 @@ function () { $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 404 Not Found", $response); + $this->assertStringContainsString("HTTP/1.0 404 Not Found", $response); $socket->close(); } @@ -94,8 +94,8 @@ public function testPlainHttpOnRandomPortWithoutHostHeaderUsesSocketUri() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('http://' . noScheme($socket->getAddress()) . '/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('http://' . noScheme($socket->getAddress()) . '/', $response); $socket->close(); } @@ -119,8 +119,8 @@ public function testPlainHttpOnRandomPortWithOtherHostHeaderTakesPrecedence() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('http://localhost:1000/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('http://localhost:1000/', $response); $socket->close(); } @@ -150,8 +150,8 @@ public function testSecureHttpsOnRandomPort() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('https://' . noScheme($socket->getAddress()) . '/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('https://' . noScheme($socket->getAddress()) . '/', $response); $socket->close(); } @@ -181,8 +181,8 @@ public function testSecureHttpsReturnsData() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString("\r\nContent-Length: 33000\r\n", $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString("\r\nContent-Length: 33000\r\n", $response); $this->assertStringEndsWith("\r\n". str_repeat('.', 33000), $response); $socket->close(); @@ -211,8 +211,8 @@ public function testSecureHttpsOnRandomPortWithoutHostHeaderUsesSocketUri() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('https://' . noScheme($socket->getAddress()) . '/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('https://' . noScheme($socket->getAddress()) . '/', $response); $socket->close(); } @@ -240,8 +240,8 @@ public function testPlainHttpOnStandardPortReturnsUriWithNoPort() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('http://127.0.0.1/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('http://127.0.0.1/', $response); $socket->close(); } @@ -269,8 +269,8 @@ public function testPlainHttpOnStandardPortWithoutHostHeaderReturnsUriWithNoPort $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('http://127.0.0.1/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('http://127.0.0.1/', $response); $socket->close(); } @@ -303,8 +303,8 @@ public function testSecureHttpsOnStandardPortReturnsUriWithNoPort() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('https://127.0.0.1/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('https://127.0.0.1/', $response); $socket->close(); } @@ -337,8 +337,8 @@ public function testSecureHttpsOnStandardPortWithoutHostHeaderUsesSocketUri() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('https://127.0.0.1/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('https://127.0.0.1/', $response); $socket->close(); } @@ -366,8 +366,8 @@ public function testPlainHttpOnHttpsStandardPortReturnsUriWithPort() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('http://127.0.0.1:443/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('http://127.0.0.1:443/', $response); $socket->close(); } @@ -400,8 +400,8 @@ public function testSecureHttpsOnHttpStandardPortReturnsUriWithPort() $response = await(timeout($result, 1.0)); - $this->assertContainsString("HTTP/1.0 200 OK", $response); - $this->assertContainsString('https://127.0.0.1:80/', $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response); + $this->assertStringContainsString('https://127.0.0.1:80/', $response); $socket->close(); } @@ -743,7 +743,7 @@ function (ServerRequestInterface $request) { $responses = await(timeout(all($result), 1.0)); foreach ($responses as $response) { - $this->assertContainsString("HTTP/1.0 200 OK", $response, $response); + $this->assertStringContainsString("HTTP/1.0 200 OK", $response, $response); $this->assertTrue(substr($response, -4) == 1024, $response); } diff --git a/tests/HttpServerTest.php b/tests/HttpServerTest.php index fc977d9b..a62e5fbd 100644 --- a/tests/HttpServerTest.php +++ b/tests/HttpServerTest.php @@ -4,10 +4,14 @@ use Psr\Http\Message\ServerRequestInterface; use React\EventLoop\Loop; +use React\EventLoop\LoopInterface; use React\Http\HttpServer; use React\Http\Io\IniUtil; +use React\Http\Middleware\LimitConcurrentRequestsMiddleware; +use React\Http\Middleware\RequestBodyBufferMiddleware; use React\Http\Middleware\StreamingRequestMiddleware; use React\Promise\Deferred; +use React\Socket\Connection; use React\Stream\ReadableStreamInterface; use function React\Async\await; use function React\Promise\reject; @@ -25,7 +29,7 @@ final class HttpServerTest extends TestCase */ public function setUpConnectionMockAndSocket() { - $this->connection = $this->getMockBuilder('React\Socket\Connection') + $this->connection = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->setMethods( [ @@ -65,12 +69,12 @@ public function testConstructWithoutLoopAssignsLoopAutomatically() $ref->setAccessible(true); $loop = $ref->getValue($clock); - $this->assertInstanceOf('React\EventLoop\LoopInterface', $loop); + $this->assertInstanceOf(LoopInterface::class, $loop); } public function testInvalidCallbackFunctionLeadsToException() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new HttpServer('invalid'); } @@ -271,8 +275,8 @@ public function testForwardErrors() $data = $this->createPostFileUploadRequest(); $this->connection->emit('data', [implode('', $data)]); - $this->assertInstanceOf('RuntimeException', $capturedException); - $this->assertInstanceOf('Exception', $capturedException->getPrevious()); + $this->assertInstanceOf(\RuntimeException::class, $capturedException); + $this->assertInstanceOf(\Exception::class, $capturedException->getPrevious()); $this->assertSame($exception, $capturedException->getPrevious()); } @@ -297,24 +301,22 @@ private function createPostFileUploadRequest() return $data; } - public function provideIniSettingsForConcurrency() + public static function provideIniSettingsForConcurrency() { - return [ - 'default settings' => [ - '128M', - '64K', // 8M capped at maximum - 1024 - ], - 'unlimited memory_limit has no concurrency limit' => [ - '-1', - '8M', - null - ], - 'small post_max_size results in high concurrency' => [ - '128M', - '1k', - 65536 - ] + yield 'default settings' => [ + '128M', + '64K', // 8M capped at maximum + 1024 + ]; + yield 'unlimited memory_limit has no concurrency limit' => [ + '-1', + '8M', + null + ]; + yield 'small post_max_size results in high concurrency' => [ + '128M', + '1k', + 65536 ]; } @@ -401,7 +403,7 @@ public function testConstructServerWithUnlimitedMemoryLimitDoesNotLimitConcurren $middleware = $ref->getValue($middlewareRunner); $this->assertTrue(is_array($middleware)); - $this->assertInstanceOf('React\Http\Middleware\RequestBodyBufferMiddleware', $middleware[0]); + $this->assertInstanceOf(RequestBodyBufferMiddleware::class, $middleware[0]); } public function testConstructServerWithMemoryLimitDoesLimitConcurrency() @@ -431,7 +433,7 @@ public function testConstructServerWithMemoryLimitDoesLimitConcurrency() $middleware = $ref->getValue($middlewareRunner); $this->assertTrue(is_array($middleware)); - $this->assertInstanceOf('React\Http\Middleware\LimitConcurrentRequestsMiddleware', $middleware[0]); + $this->assertInstanceOf(LimitConcurrentRequestsMiddleware::class, $middleware[0]); } public function testConstructFiltersOutConfigurationMiddlewareBefore() diff --git a/tests/Io/AbstractMessageTest.php b/tests/Io/AbstractMessageTest.php index 59c170ec..5451281a 100644 --- a/tests/Io/AbstractMessageTest.php +++ b/tests/Io/AbstractMessageTest.php @@ -26,7 +26,7 @@ public function testWithProtocolVersionReturnsNewInstanceWhenProtocolVersionIsCh $message = new MessageMock( '1.1', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock() + $this->createMock(StreamInterface::class) ); $new = $message->withProtocolVersion('1.0'); @@ -40,7 +40,7 @@ public function testWithProtocolVersionReturnsSameInstanceWhenProtocolVersionIsU $message = new MessageMock( '1.1', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock() + $this->createMock(StreamInterface::class) ); $new = $message->withProtocolVersion('1.1'); @@ -55,7 +55,7 @@ public function testHeaderWithStringValue() [ 'Content-Type' => 'text/plain' ], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock() + $this->createMock(StreamInterface::class) ); $this->assertEquals(['Content-Type' => ['text/plain']], $message->getHeaders()); @@ -109,7 +109,7 @@ public function testHeaderWithMultipleValues() 'b=2' ] ], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock() + $this->createMock(StreamInterface::class) ); $this->assertEquals(['Set-Cookie' => ['a=1', 'b=2']], $message->getHeaders()); @@ -152,7 +152,7 @@ public function testHeaderWithEmptyValue() [ 'Content-Type' => [] ], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock() + $this->createMock(StreamInterface::class) ); $this->assertEquals([], $message->getHeaders()); @@ -183,7 +183,7 @@ public function testHeaderWithMultipleValuesAcrossMixedCaseNamesInConstructorMer 'set-cookie' => ['b=2'], 'set-COOKIE' => [] ], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock() + $this->createMock(StreamInterface::class) ); $this->assertEquals(['set-cookie' => ['a=1', 'b=2']], $message->getHeaders()); @@ -192,14 +192,14 @@ public function testHeaderWithMultipleValuesAcrossMixedCaseNamesInConstructorMer public function testWithBodyReturnsNewInstanceWhenBodyIsChanged() { - $body = $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(); + $body = $this->createMock(StreamInterface::class); $message = new MessageMock( '1.1', [], $body ); - $body2 = $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(); + $body2 = $this->createMock(StreamInterface::class); $new = $message->withBody($body2); $this->assertNotSame($message, $new); $this->assertSame($body2, $new->getBody()); @@ -208,7 +208,7 @@ public function testWithBodyReturnsNewInstanceWhenBodyIsChanged() public function testWithBodyReturnsSameInstanceWhenBodyIsUnchanged() { - $body = $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(); + $body = $this->createMock(StreamInterface::class); $message = new MessageMock( '1.1', [], diff --git a/tests/Io/AbstractRequestTest.php b/tests/Io/AbstractRequestTest.php index 24990622..5d41369b 100644 --- a/tests/Io/AbstractRequestTest.php +++ b/tests/Io/AbstractRequestTest.php @@ -32,12 +32,12 @@ class AbstractRequestTest extends TestCase { public function testCtorWithInvalidUriThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new RequestMock( 'GET', null, [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); } @@ -48,7 +48,7 @@ public function testGetHeadersReturnsHostHeaderFromUri() 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -61,7 +61,7 @@ public function testGetHeadersReturnsHostHeaderFromUriWithCustomHttpPort() 'GET', 'http://example.com:8080/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -74,7 +74,7 @@ public function testGetHeadersReturnsHostHeaderFromUriWithCustomPortHttpOnHttpsP 'GET', 'http://example.com:443/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -87,7 +87,7 @@ public function testGetHeadersReturnsHostHeaderFromUriWithCustomPortHttpsOnHttpP 'GET', 'https://example.com:80/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -100,7 +100,7 @@ public function testGetHeadersReturnsHostHeaderFromUriWithoutDefaultHttpPort() 'GET', 'http://example.com:80/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -113,7 +113,7 @@ public function testGetHeadersReturnsHostHeaderFromUriWithoutDefaultHttpsPort() 'GET', 'https://example.com:443/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -128,7 +128,7 @@ public function testGetHeadersReturnsHostHeaderFromUriBeforeOtherHeadersExplicit [ 'User-Agent' => 'demo' ], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -143,7 +143,7 @@ public function testGetHeadersReturnsHostHeaderFromHeadersExplicitlyGiven() [ 'Host' => 'example.com:8080' ], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -158,7 +158,7 @@ public function testGetHeadersReturnsHostHeaderFromUriWhenHeadersExplicitlyGiven [ 'Host' => [] ], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -171,7 +171,7 @@ public function testGetRequestTargetReturnsPathAndQueryFromUri() 'GET', 'http://example.com/demo?name=Alice', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -184,7 +184,7 @@ public function testGetRequestTargetReturnsSlashOnlyIfUriHasNoPathOrQuery() 'GET', 'http://example.com', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -197,7 +197,7 @@ public function testGetRequestTargetReturnsRequestTargetInAbsoluteFormIfGivenExp 'GET', 'http://example.com/demo?name=Alice', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); $request = $request->withRequestTarget('http://example.com/demo?name=Alice'); @@ -211,7 +211,7 @@ public function testWithRequestTargetReturnsNewInstanceWhenRequestTargetIsChange 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -227,7 +227,7 @@ public function testWithRequestTargetReturnsSameInstanceWhenRequestTargetIsUncha 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); $request = $request->withRequestTarget('/'); @@ -243,7 +243,7 @@ public function testWithMethodReturnsNewInstanceWhenMethodIsChanged() 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -259,7 +259,7 @@ public function testWithMethodReturnsSameInstanceWhenMethodIsUnchanged() 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -270,13 +270,13 @@ public function testWithMethodReturnsSameInstanceWhenMethodIsUnchanged() public function testGetUriReturnsUriInstanceGivenToCtor() { - $uri = $this->getMockBuilder('Psr\Http\Message\UriInterface')->getMock(); + $uri = $this->createMock(UriInterface::class); $request = new RequestMock( 'GET', $uri, [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -289,12 +289,12 @@ public function testGetUriReturnsUriInstanceForUriStringGivenToCtor() 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); $uri = $request->getUri(); - $this->assertInstanceOf('Psr\Http\Message\UriInterface', $uri); + $this->assertInstanceOf(UriInterface::class, $uri); $this->assertEquals('http://example.com/', (string) $uri); } @@ -304,11 +304,11 @@ public function testWithUriReturnsNewInstanceWhenUriIsChanged() 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); - $uri = $this->getMockBuilder('Psr\Http\Message\UriInterface')->getMock(); + $uri = $this->createMock(UriInterface::class); $new = $request->withUri($uri); $this->assertNotSame($request, $new); @@ -318,13 +318,13 @@ public function testWithUriReturnsNewInstanceWhenUriIsChanged() public function testWithUriReturnsSameInstanceWhenUriIsUnchanged() { - $uri = $this->getMockBuilder('Psr\Http\Message\UriInterface')->getMock(); + $uri = $this->createMock(UriInterface::class); $request = new RequestMock( 'GET', $uri, [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -339,7 +339,7 @@ public function testWithUriReturnsNewInstanceWithHostHeaderChangedIfUriContainsH 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -357,7 +357,7 @@ public function testWithUriReturnsNewInstanceWithHostHeaderChangedIfUriContainsH 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -377,7 +377,7 @@ public function testWithUriReturnsNewInstanceWithHostHeaderAddedAsFirstHeaderBef [ 'User-Agent' => 'test' ], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); $request = $request->withoutHeader('Host'); @@ -396,7 +396,7 @@ public function testWithUriReturnsNewInstanceWithHostHeaderUnchangedIfUriContain 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -414,7 +414,7 @@ public function testWithUriReturnsNewInstanceWithHostHeaderUnchangedIfPreserveHo 'GET', 'http://example.com/', [], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); @@ -434,7 +434,7 @@ public function testWithUriReturnsNewInstanceWithHostHeaderAddedAsFirstHeaderNoM [ 'User-Agent' => 'test' ], - $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(), + $this->createMock(StreamInterface::class), '1.1' ); $request = $request->withoutHeader('Host'); diff --git a/tests/Io/BufferedBodyTest.php b/tests/Io/BufferedBodyTest.php index 4f5d042a..c8534d50 100644 --- a/tests/Io/BufferedBodyTest.php +++ b/tests/Io/BufferedBodyTest.php @@ -91,7 +91,7 @@ public function testSeekBeforeStartThrows() } catch (\RuntimeException $e) { $this->assertSame(0, $stream->tell()); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); throw $e; } } @@ -100,7 +100,7 @@ public function testSeekWithInvalidModeThrows() { $stream = new BufferedBody('hello'); - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $stream->seek(1, 12345); } @@ -109,7 +109,7 @@ public function testSeekAfterCloseThrows() $stream = new BufferedBody('hello'); $stream->close(); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); $stream->seek(0); } @@ -118,7 +118,7 @@ public function testTellAfterCloseThrows() $stream = new BufferedBody('hello'); $stream->close(); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); $stream->tell(); } @@ -136,7 +136,7 @@ public function testRewindAfterCloseThrows() $stream = new BufferedBody('hello'); $stream->close(); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); $stream->rewind(); } @@ -180,7 +180,7 @@ public function testReadZeroThrows() { $stream = new BufferedBody('hello'); - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $stream->read(0); } @@ -189,7 +189,7 @@ public function testReadAfterCloseThrows() $stream = new BufferedBody('hello'); $stream->close(); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); $stream->read(10); } @@ -218,7 +218,7 @@ public function testGetContentsAfterCloseThrows() $stream = new BufferedBody('hello'); $stream->close(); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); $stream->getContents(); } @@ -280,7 +280,7 @@ public function testWriteAfterCloseThrows() $stream = new BufferedBody('hello'); $stream->close(); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); $stream->write('foo'); } diff --git a/tests/Io/ChunkedDecoderTest.php b/tests/Io/ChunkedDecoderTest.php index 5168f2d0..3ae8c742 100644 --- a/tests/Io/ChunkedDecoderTest.php +++ b/tests/Io/ChunkedDecoderTest.php @@ -3,7 +3,9 @@ namespace React\Tests\Http\Io; use React\Http\Io\ChunkedDecoder; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; +use React\Stream\WritableStreamInterface; use React\Tests\Http\TestCase; class ChunkedDecoderTest extends TestCase @@ -394,7 +396,7 @@ public function testHandleError() public function testPauseStream() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('pause'); $parser = new ChunkedDecoder($input); @@ -403,7 +405,7 @@ public function testPauseStream() public function testResumeStream() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('pause'); $parser = new ChunkedDecoder($input); @@ -413,7 +415,7 @@ public function testResumeStream() public function testPipeStream() { - $dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); + $dest = $this->createMock(WritableStreamInterface::class); $ret = $this->parser->pipe($dest); diff --git a/tests/Io/ChunkedEncoderTest.php b/tests/Io/ChunkedEncoderTest.php index 96b97848..cbb3e7ad 100644 --- a/tests/Io/ChunkedEncoderTest.php +++ b/tests/Io/ChunkedEncoderTest.php @@ -3,7 +3,9 @@ namespace React\Tests\Http\Io; use React\Http\Io\ChunkedEncoder; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; +use React\Stream\WritableStreamInterface; use React\Tests\Http\TestCase; class ChunkedEncoderTest extends TestCase @@ -59,7 +61,7 @@ public function testHandleError() public function testPauseStream() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('pause'); $parser = new ChunkedEncoder($input); @@ -68,7 +70,7 @@ public function testPauseStream() public function testResumeStream() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('pause'); $parser = new ChunkedEncoder($input); @@ -78,7 +80,7 @@ public function testResumeStream() public function testPipeStream() { - $dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); + $dest = $this->createMock(WritableStreamInterface::class); $ret = $this->chunkedStream->pipe($dest); diff --git a/tests/Io/ClientConnectionManagerTest.php b/tests/Io/ClientConnectionManagerTest.php index 88c5ff4f..c4b3a07e 100644 --- a/tests/Io/ClientConnectionManagerTest.php +++ b/tests/Io/ClientConnectionManagerTest.php @@ -2,10 +2,14 @@ namespace React\Tests\Http\Io; +use React\EventLoop\LoopInterface; +use React\EventLoop\TimerInterface; use React\Http\Io\ClientConnectionManager; use React\Http\Message\Uri; use React\Promise\Promise; use React\Promise\PromiseInterface; +use React\Socket\ConnectionInterface; +use React\Socket\ConnectorInterface; use React\Tests\Http\TestCase; use function React\Promise\resolve; @@ -14,10 +18,10 @@ class ClientConnectionManagerTest extends TestCase public function testConnectWithHttpsUriShouldConnectToTlsWithDefaultPort() { $promise = new Promise(function () { }); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->with('tls://reactphp.org:443')->willReturn($promise); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $connectionManager = new ClientConnectionManager($connector, $loop); @@ -30,10 +34,10 @@ public function testConnectWithHttpsUriShouldConnectToTlsWithDefaultPort() public function testConnectWithHttpUriShouldConnectToTcpWithDefaultPort() { $promise = new Promise(function () { }); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->with('reactphp.org:80')->willReturn($promise); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $connectionManager = new ClientConnectionManager($connector, $loop); @@ -44,10 +48,10 @@ public function testConnectWithHttpUriShouldConnectToTcpWithDefaultPort() public function testConnectWithExplicitPortShouldConnectWithGivenPort() { $promise = new Promise(function () { }); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->with('reactphp.org:8080')->willReturn($promise); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $connectionManager = new ClientConnectionManager($connector, $loop); @@ -57,10 +61,10 @@ public function testConnectWithExplicitPortShouldConnectWithGivenPort() public function testConnectWithInvalidSchemeShouldRejectWithException() { - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->never())->method('connect'); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $connectionManager = new ClientConnectionManager($connector, $loop); @@ -71,16 +75,16 @@ public function testConnectWithInvalidSchemeShouldRejectWithException() $exception = $reason; }); - $this->assertInstanceOf('InvalidArgumentException', $exception); + $this->assertInstanceOf(\InvalidArgumentException::class, $exception); $this->assertEquals('Invalid request URL given', $exception->getMessage()); } public function testConnectWithoutSchemeShouldRejectWithException() { - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->never())->method('connect'); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $connectionManager = new ClientConnectionManager($connector, $loop); @@ -91,13 +95,13 @@ public function testConnectWithoutSchemeShouldRejectWithException() $exception = $reason; }); - $this->assertInstanceOf('InvalidArgumentException', $exception); + $this->assertInstanceOf(\InvalidArgumentException::class, $exception); $this->assertEquals('Invalid request URL given', $exception->getMessage()); } public function testConnectReusesIdleConnectionFromPreviousKeepAliveCallWithoutUsingConnectorAndWillAddAndRemoveStreamEventsAndAddAndCancelIdleTimer() { - $connectionToReuse = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connectionToReuse = $this->createMock(ConnectionInterface::class); $streamHandler = null; $connectionToReuse->expects($this->exactly(3))->method('on')->withConsecutive( @@ -148,11 +152,11 @@ public function testConnectReusesIdleConnectionFromPreviousKeepAliveCallWithoutU ] ); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->never())->method('connect'); - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->willReturn($timer); $loop->expects($this->once())->method('cancelTimer')->with($timer); @@ -173,13 +177,13 @@ public function testConnectReusesIdleConnectionFromPreviousKeepAliveCallWithoutU public function testConnectReusesIdleConnectionFromPreviousKeepAliveCallWithoutUsingConnectorAlsoWhenUriPathAndQueryAndFragmentIsDifferent() { - $connectionToReuse = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connectionToReuse = $this->createMock(ConnectionInterface::class); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->never())->method('connect'); - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->willReturn($timer); $loop->expects($this->once())->method('cancelTimer')->with($timer); @@ -200,13 +204,13 @@ public function testConnectReusesIdleConnectionFromPreviousKeepAliveCallWithoutU public function testConnectUsesConnectorWithSameUriAndReturnsPromiseForNewConnectionFromConnectorWhenPreviousKeepAliveCallUsedDifferentUri() { - $connectionToReuse = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connectionToReuse = $this->createMock(ConnectionInterface::class); $promise = new Promise(function () { }); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->with('tls://reactphp.org:443')->willReturn($promise); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $connectionManager = new ClientConnectionManager($connector, $loop); @@ -220,14 +224,14 @@ public function testConnectUsesConnectorWithSameUriAndReturnsPromiseForNewConnec public function testConnectUsesConnectorForNewConnectionWhenPreviousConnectReusedIdleConnectionFromPreviousKeepAliveCall() { - $firstConnection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); - $secondConnection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $firstConnection = $this->createMock(ConnectionInterface::class); + $secondConnection = $this->createMock(ConnectionInterface::class); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->with('tls://reactphp.org:443')->willReturn(resolve($secondConnection)); - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->willReturn($timer); $loop->expects($this->once())->method('cancelTimer')->with($timer); @@ -251,12 +255,12 @@ public function testConnectUsesConnectorForNewConnectionWhenPreviousConnectReuse public function testKeepAliveAddsTimerAndDoesNotCloseConnectionImmediately() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->never())->method('close'); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->with(0.001, $this->anything()); $connectionManager = new ClientConnectionManager($connector, $loop); @@ -266,14 +270,14 @@ public function testKeepAliveAddsTimerAndDoesNotCloseConnectionImmediately() public function testKeepAliveClosesConnectionAfterIdleTimeout() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('close'); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $timerCallback = null; - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->with($this->anything(), $this->callback(function ($cb) use (&$timerCallback) { $timerCallback = $cb; return true; @@ -291,18 +295,18 @@ public function testKeepAliveClosesConnectionAfterIdleTimeout() public function testConnectUsesConnectorForNewConnectionWhenIdleConnectionFromPreviousKeepAliveCallHasAlreadyTimedOut() { - $firstConnection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $firstConnection = $this->createMock(ConnectionInterface::class); $firstConnection->expects($this->once())->method('close'); - $secondConnection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $secondConnection = $this->createMock(ConnectionInterface::class); $secondConnection->expects($this->never())->method('close'); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->with('tls://reactphp.org:443')->willReturn(resolve($secondConnection)); $timerCallback = null; - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->with($this->anything(), $this->callback(function ($cb) use (&$timerCallback) { $timerCallback = $cb; return true; @@ -330,7 +334,7 @@ public function testConnectUsesConnectorForNewConnectionWhenIdleConnectionFromPr public function testConnectUsesConnectorForNewConnectionWhenIdleConnectionFromPreviousKeepAliveCallHasAlreadyFiredUnexpectedStreamEventBeforeIdleTimeoutThatClosesConnection() { - $firstConnection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $firstConnection = $this->createMock(ConnectionInterface::class); $firstConnection->expects($this->once())->method('close'); $streamHandler = null; @@ -358,14 +362,14 @@ public function testConnectUsesConnectorForNewConnectionWhenIdleConnectionFromPr ] ); - $secondConnection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $secondConnection = $this->createMock(ConnectionInterface::class); $secondConnection->expects($this->never())->method('close'); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->with('tls://reactphp.org:443')->willReturn(resolve($secondConnection)); - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->willReturn($timer); $loop->expects($this->once())->method('cancelTimer')->with($timer); diff --git a/tests/Io/ClientRequestStreamTest.php b/tests/Io/ClientRequestStreamTest.php index 0df92961..a20cda61 100644 --- a/tests/Io/ClientRequestStreamTest.php +++ b/tests/Io/ClientRequestStreamTest.php @@ -4,11 +4,15 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use React\EventLoop\LoopInterface; +use React\Http\Io\ClientConnectionManager; use React\Http\Io\ClientRequestStream; use React\Http\Message\Request; use React\Http\Message\Uri; use React\Promise\Deferred; use React\Promise\Promise; +use React\Socket\Connection; +use React\Socket\ConnectionInterface; use React\Stream\DuplexResourceStream; use React\Stream\ReadableStreamInterface; use React\Tests\Http\TestCase; @@ -20,10 +24,10 @@ class ClientRequestStreamTest extends TestCase /** @test */ public function testRequestShouldUseConnectionManagerWithUriFromRequestAndBindToStreamEvents() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $uri = new Uri('http://www.example.com'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->with($uri)->willReturn(resolve($connection)); $requestData = new Request('GET', $uri); @@ -55,13 +59,13 @@ public function testRequestShouldUseConnectionManagerWithUriFromRequestAndBindTo /** @test */ public function requestShouldEmitErrorIfConnectionFails() { - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(reject(new \RuntimeException())); $requestData = new Request('GET', 'http://www.example.com'); $request = new ClientRequestStream($connectionManager, $requestData); - $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException'))); + $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf(\RuntimeException::class))); $request->on('close', $this->expectCallableOnce()); $request->end(); @@ -70,15 +74,15 @@ public function requestShouldEmitErrorIfConnectionFails() /** @test */ public function requestShouldEmitErrorIfConnectionClosesBeforeResponseIsParsed() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com'); $request = new ClientRequestStream($connectionManager, $requestData); - $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException'))); + $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf(\RuntimeException::class))); $request->on('close', $this->expectCallableOnce()); $request->end(); @@ -88,15 +92,15 @@ public function requestShouldEmitErrorIfConnectionClosesBeforeResponseIsParsed() /** @test */ public function requestShouldEmitErrorIfConnectionEmitsError() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com'); $request = new ClientRequestStream($connectionManager, $requestData); - $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('Exception'))); + $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf(\Exception::class))); $request->on('close', $this->expectCallableOnce()); $request->end(); @@ -107,43 +111,41 @@ public static function provideInvalidRequest() { $request = new Request('GET' , "http://localhost/"); - return [ - [ - $request->withMethod("INVA\r\nLID", '') - ], - [ - $request->withRequestTarget('/inva lid') - ], - [ - $request->withHeader('Invalid', "Yes\r\n") - ], - [ - $request->withHeader('Invalid', "Yes\n") - ], - [ - $request->withHeader('Invalid', "Yes\r") - ], - [ - $request->withHeader("Inva\r\nlid", 'Yes') - ], - [ - $request->withHeader("Inva\nlid", 'Yes') - ], - [ - $request->withHeader("Inva\rlid", 'Yes') - ], - [ - $request->withHeader('Inva Lid', 'Yes') - ], - [ - $request->withHeader('Inva:Lid', 'Yes') - ], - [ - $request->withHeader('Invalid', "Val\0ue") - ], - [ - $request->withHeader("Inva\0lid", 'Yes') - ] + yield [ + $request->withMethod("INVA\r\nLID", '') + ]; + yield [ + $request->withRequestTarget('/inva lid') + ]; + yield [ + $request->withHeader('Invalid', "Yes\r\n") + ]; + yield [ + $request->withHeader('Invalid', "Yes\n") + ]; + yield [ + $request->withHeader('Invalid', "Yes\r") + ]; + yield [ + $request->withHeader("Inva\r\nlid", 'Yes') + ]; + yield [ + $request->withHeader("Inva\nlid", 'Yes') + ]; + yield [ + $request->withHeader("Inva\rlid", 'Yes') + ]; + yield [ + $request->withHeader('Inva Lid', 'Yes') + ]; + yield [ + $request->withHeader('Inva:Lid', 'Yes') + ]; + yield [ + $request->withHeader('Invalid', "Val\0ue") + ]; + yield [ + $request->withHeader("Inva\0lid", 'Yes') ]; } @@ -153,12 +155,12 @@ public static function provideInvalidRequest() */ public function testStreamShouldEmitErrorBeforeCreatingConnectionWhenRequestIsInvalid(RequestInterface $request) { - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->never())->method('connect'); $stream = new ClientRequestStream($connectionManager, $request); - $stream->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException'))); + $stream->on('error', $this->expectCallableOnceWith($this->isInstanceOf(\InvalidArgumentException::class))); $stream->on('close', $this->expectCallableOnce()); $stream->end(); @@ -167,15 +169,15 @@ public function testStreamShouldEmitErrorBeforeCreatingConnectionWhenRequestIsIn /** @test */ public function requestShouldEmitErrorIfRequestParserThrowsException() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com'); $request = new ClientRequestStream($connectionManager, $requestData); - $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException'))); + $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf(\InvalidArgumentException::class))); $request->on('close', $this->expectCallableOnce()); $request->end(); @@ -185,10 +187,10 @@ public function requestShouldEmitErrorIfRequestParserThrowsException() /** @test */ public function getRequestShouldSendAGetRequest() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n"); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', [], '', '1.0'); @@ -200,10 +202,10 @@ public function getRequestShouldSendAGetRequest() /** @test */ public function getHttp11RequestShouldSendAGetRequestWithGivenConnectionCloseHeader() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -215,10 +217,10 @@ public function getHttp11RequestShouldSendAGetRequestWithGivenConnectionCloseHea /** @test */ public function getOptionsAsteriskShouldSendAOptionsRequestAsteriskRequestTarget() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("OPTIONS * HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('OPTIONS', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -230,11 +232,11 @@ public function getOptionsAsteriskShouldSendAOptionsRequestAsteriskRequestTarget public function testStreamShouldEmitResponseWithEmptyBodyWhenResponseContainsContentLengthZero() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->once())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -254,11 +256,11 @@ public function testStreamShouldEmitResponseWithEmptyBodyWhenResponseContainsCon public function testStreamShouldEmitResponseWithEmptyBodyWhenResponseContainsStatusNoContent() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->once())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -278,11 +280,11 @@ public function testStreamShouldEmitResponseWithEmptyBodyWhenResponseContainsSta public function testStreamShouldEmitResponseWithEmptyBodyWhenResponseContainsStatusNotModifiedWithContentLengthGiven() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->once())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -302,11 +304,11 @@ public function testStreamShouldEmitResponseWithEmptyBodyWhenResponseContainsSta public function testStreamShouldEmitResponseWithEmptyBodyWhenRequestMethodIsHead() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("HEAD / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->once())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('HEAD', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -326,11 +328,11 @@ public function testStreamShouldEmitResponseWithEmptyBodyWhenRequestMethodIsHead public function testStreamShouldEmitResponseWithStreamingBodyUntilEndWhenResponseContainsContentLengthAndResponseBody() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->once())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -350,11 +352,11 @@ public function testStreamShouldEmitResponseWithStreamingBodyUntilEndWhenRespons public function testStreamShouldEmitResponseWithStreamingBodyWithoutDataWhenResponseContainsContentLengthWithoutResponseBody() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->never())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -374,11 +376,11 @@ public function testStreamShouldEmitResponseWithStreamingBodyWithoutDataWhenResp public function testStreamShouldEmitResponseWithStreamingBodyWithDataWithoutEndWhenResponseContainsContentLengthWithIncompleteResponseBody() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->never())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -398,11 +400,11 @@ public function testStreamShouldEmitResponseWithStreamingBodyWithDataWithoutEndW public function testStreamShouldEmitResponseWithStreamingBodyUntilEndWhenResponseContainsTransferEncodingChunkedAndResponseBody() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->once())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -422,11 +424,11 @@ public function testStreamShouldEmitResponseWithStreamingBodyUntilEndWhenRespons public function testStreamShouldEmitResponseWithStreamingBodyWithoutDataWhenResponseContainsTransferEncodingChunkedWithoutResponseBody() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->never())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -446,11 +448,11 @@ public function testStreamShouldEmitResponseWithStreamingBodyWithoutDataWhenResp public function testStreamShouldEmitResponseWithStreamingBodyWithDataWithoutEndWhenResponseContainsTransferEncodingChunkedWithIncompleteResponseBody() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->never())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -470,11 +472,11 @@ public function testStreamShouldEmitResponseWithStreamingBodyWithDataWithoutEndW public function testStreamShouldEmitResponseWithStreamingBodyWithDataWithoutEndWhenResponseContainsNoContentLengthAndIncompleteResponseBody() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->never())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -494,7 +496,7 @@ public function testStreamShouldEmitResponseWithStreamingBodyWithDataWithoutEndW public function testStreamShouldEmitResponseWithStreamingBodyUntilEndWhenResponseContainsNoContentLengthAndResponseBodyTerminatedByConnectionEndEvent() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"); $connection->expects($this->once())->method('close'); @@ -510,7 +512,7 @@ public function testStreamShouldEmitResponseWithStreamingBodyUntilEndWhenRespons return true; })); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'close'], '', '1.1'); @@ -533,12 +535,12 @@ public function testStreamShouldEmitResponseWithStreamingBodyUntilEndWhenRespons public function testStreamShouldReuseConnectionForHttp11ByDefault() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"); $connection->expects($this->once())->method('isReadable')->willReturn(true); $connection->expects($this->never())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $connectionManager->expects($this->once())->method('keepAlive')->with(new Uri('http://www.example.com'), $connection); @@ -554,12 +556,12 @@ public function testStreamShouldReuseConnectionForHttp11ByDefault() public function testStreamShouldNotReuseConnectionWhenResponseContainsConnectionClose() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"); $connection->expects($this->once())->method('isReadable')->willReturn(true); $connection->expects($this->once())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', [], '', '1.1'); @@ -574,12 +576,12 @@ public function testStreamShouldNotReuseConnectionWhenResponseContainsConnection public function testStreamShouldNotReuseConnectionWhenRequestContainsConnectionCloseWithAdditionalOptions() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: FOO, CLOSE, BAR\r\n\r\n"); $connection->expects($this->once())->method('isReadable')->willReturn(true); $connection->expects($this->once())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', ['Connection' => 'FOO, CLOSE, BAR'], '', '1.1'); @@ -594,12 +596,12 @@ public function testStreamShouldNotReuseConnectionWhenRequestContainsConnectionC public function testStreamShouldNotReuseConnectionForHttp10ByDefault() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n"); $connection->expects($this->once())->method('isReadable')->willReturn(true); $connection->expects($this->once())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', [], '', '1.0'); @@ -614,12 +616,12 @@ public function testStreamShouldNotReuseConnectionForHttp10ByDefault() public function testStreamShouldReuseConnectionForHttp10WhenBothRequestAndResponseContainConnectionKeepAlive() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: keep-alive\r\n\r\n"); $connection->expects($this->once())->method('isReadable')->willReturn(true); $connection->expects($this->never())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $connectionManager->expects($this->once())->method('keepAlive')->with(new Uri('http://www.example.com'), $connection); @@ -635,12 +637,12 @@ public function testStreamShouldReuseConnectionForHttp10WhenBothRequestAndRespon public function testStreamShouldReuseConnectionForHttp10WhenBothRequestAndResponseContainConnectionKeepAliveWithAdditionalOptions() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: FOO, KEEP-ALIVE, BAR\r\n\r\n"); $connection->expects($this->once())->method('isReadable')->willReturn(true); $connection->expects($this->never())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $connectionManager->expects($this->once())->method('keepAlive')->with(new Uri('http://www.example.com'), $connection); @@ -656,7 +658,7 @@ public function testStreamShouldReuseConnectionForHttp10WhenBothRequestAndRespon public function testStreamShouldNotReuseConnectionWhenResponseContainsNoContentLengthAndResponseBodyTerminatedByConnectionEndEvent() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"); $connection->expects($this->once())->method('isReadable')->willReturn(false); $connection->expects($this->once())->method('close'); @@ -673,7 +675,7 @@ public function testStreamShouldNotReuseConnectionWhenResponseContainsNoContentL return true; })); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', [], '', '1.1'); @@ -691,7 +693,7 @@ public function testStreamShouldNotReuseConnectionWhenResponseContainsNoContentL public function testStreamShouldNotReuseConnectionWhenResponseContainsContentLengthButIsTerminatedByUnexpectedCloseEvent() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"); $connection->expects($this->atMost(1))->method('isReadable')->willReturn(false); $connection->expects($this->once())->method('close'); @@ -708,7 +710,7 @@ public function testStreamShouldNotReuseConnectionWhenResponseContainsContentLen return true; })); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', [], '', '1.1'); @@ -726,12 +728,12 @@ public function testStreamShouldNotReuseConnectionWhenResponseContainsContentLen public function testStreamShouldReuseConnectionWhenResponseContainsTransferEncodingChunkedAndResponseBody() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"); $connection->expects($this->once())->method('isReadable')->willReturn(true); $connection->expects($this->never())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $connectionManager->expects($this->once())->method('keepAlive')->with(new Uri('http://www.example.com'), $connection); @@ -747,12 +749,12 @@ public function testStreamShouldReuseConnectionWhenResponseContainsTransferEncod public function testStreamShouldNotReuseConnectionWhenResponseContainsTransferEncodingChunkedAndResponseBodyContainsInvalidData() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with("GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n"); $connection->expects($this->atMost(1))->method('isReadable')->willReturn(true); $connection->expects($this->once())->method('close'); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com', [], '', '1.1'); @@ -768,10 +770,10 @@ public function testStreamShouldNotReuseConnectionWhenResponseContainsTransferEn /** @test */ public function postRequestShouldSendAPostRequest() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('write')->with($this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\n\r\nsome post data$#")); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('POST', 'http://www.example.com', [], '', '1.0'); @@ -787,14 +789,14 @@ public function postRequestShouldSendAPostRequest() /** @test */ public function writeWithAPostRequestShouldSendToTheStream() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->exactly(3))->method('write')->withConsecutive( [$this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\n\r\nsome$#")], [$this->identicalTo("post")], [$this->identicalTo("data")] ); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('POST', 'http://www.example.com', [], '', '1.0'); @@ -812,7 +814,7 @@ public function writeWithAPostRequestShouldSendToTheStream() /** @test */ public function writeWithAPostRequestShouldSendBodyAfterHeadersAndEmitDrainEvent() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->exactly(2))->method('write')->withConsecutive( [$this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\n\r\nsomepost$#")], [$this->identicalTo("data")] @@ -821,7 +823,7 @@ public function writeWithAPostRequestShouldSendBodyAfterHeadersAndEmitDrainEvent ); $deferred = new Deferred(); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn($deferred->promise()); $requestData = new Request('POST', 'http://www.example.com', [], '', '1.0'); @@ -846,7 +848,7 @@ public function writeWithAPostRequestShouldSendBodyAfterHeadersAndEmitDrainEvent /** @test */ public function writeWithAPostRequestShouldForwardDrainEventIfFirstChunkExceedsBuffer() { - $connection = $this->getMockBuilder('React\Socket\Connection') + $connection = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->setMethods(['write']) ->getMock(); @@ -859,7 +861,7 @@ public function writeWithAPostRequestShouldForwardDrainEventIfFirstChunkExceedsB ); $deferred = new Deferred(); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn($deferred->promise()); $requestData = new Request('POST', 'http://www.example.com', [], '', '1.0'); @@ -885,22 +887,20 @@ public function writeWithAPostRequestShouldForwardDrainEventIfFirstChunkExceedsB /** @test */ public function pipeShouldPipeDataIntoTheRequestBody() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->exactly(3))->method('write')->withConsecutive( [$this->matchesRegularExpression("#^POST / HTTP/1\.0\r\nHost: www.example.com\r\n\r\nsome$#")], [$this->identicalTo("post")], [$this->identicalTo("data")] ); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('POST', 'http://www.example.com', [], '', '1.0'); $request = new ClientRequestStream($connectionManager, $requestData); - $loop = $this - ->getMockBuilder('React\EventLoop\LoopInterface') - ->getMock(); + $loop = $this->createMock(LoopInterface::class); $stream = fopen('php://memory', 'r+'); $stream = new DuplexResourceStream($stream, $loop); @@ -920,7 +920,7 @@ public function pipeShouldPipeDataIntoTheRequestBody() */ public function writeShouldStartConnecting() { - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(new Promise(function () { })); $requestData = new Request('POST', 'http://www.example.com'); @@ -934,7 +934,7 @@ public function writeShouldStartConnecting() */ public function endShouldStartConnectingAndChangeStreamIntoNonWritableMode() { - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(new Promise(function () { })); $requestData = new Request('POST', 'http://www.example.com'); @@ -950,7 +950,7 @@ public function endShouldStartConnectingAndChangeStreamIntoNonWritableMode() */ public function closeShouldEmitCloseEvent() { - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $requestData = new Request('POST', 'http://www.example.com'); $request = new ClientRequestStream($connectionManager, $requestData); @@ -964,7 +964,7 @@ public function closeShouldEmitCloseEvent() */ public function writeAfterCloseReturnsFalse() { - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $requestData = new Request('POST', 'http://www.example.com'); $request = new ClientRequestStream($connectionManager, $requestData); @@ -980,7 +980,7 @@ public function writeAfterCloseReturnsFalse() */ public function endAfterCloseIsNoOp() { - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->never())->method('connect'); $requestData = new Request('POST', 'http://www.example.com'); @@ -998,7 +998,7 @@ public function closeShouldCancelPendingConnectionAttempt() $promise = new Promise(function () {}, function () { throw new \RuntimeException(); }); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn($promise); $requestData = new Request('POST', 'http://www.example.com'); @@ -1016,7 +1016,7 @@ public function closeShouldCancelPendingConnectionAttempt() /** @test */ public function requestShouldRemoveAllListenerAfterClosed() { - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $requestData = new Request('GET', 'http://www.example.com'); $request = new ClientRequestStream($connectionManager, $requestData); @@ -1031,9 +1031,9 @@ public function requestShouldRemoveAllListenerAfterClosed() /** @test */ public function multivalueHeader() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); - $connectionManager = $this->getMockBuilder('React\Http\Io\ClientConnectionManager')->disableOriginalConstructor()->getMock(); + $connectionManager = $this->createMock(ClientConnectionManager::class); $connectionManager->expects($this->once())->method('connect')->willReturn(resolve($connection)); $requestData = new Request('GET', 'http://www.example.com'); @@ -1054,7 +1054,7 @@ public function multivalueHeader() $request->handleData("\r\nbody"); /** @var \Psr\Http\Message\ResponseInterface $response */ - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); + $this->assertInstanceOf(ResponseInterface::class, $response); $this->assertEquals('1.0', $response->getProtocolVersion()); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('OK', $response->getReasonPhrase()); diff --git a/tests/Io/ClockTest.php b/tests/Io/ClockTest.php index 8f4b90fa..318fa7ef 100644 --- a/tests/Io/ClockTest.php +++ b/tests/Io/ClockTest.php @@ -3,13 +3,14 @@ namespace React\Tests\Http\Io; use PHPUnit\Framework\TestCase; +use React\EventLoop\LoopInterface; use React\Http\Io\Clock; class ClockTest extends TestCase { public function testNowReturnsSameTimestampMultipleTimesInSameTick() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $clock = new Clock($loop); @@ -21,7 +22,7 @@ public function testNowReturnsSameTimestampMultipleTimesInSameTick() public function testNowResetsMemoizedTimestampOnFutureTick() { $tick = null; - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('futureTick')->with($this->callback(function ($cb) use (&$tick) { $tick = $cb; return true; diff --git a/tests/Io/CloseProtectionStreamTest.php b/tests/Io/CloseProtectionStreamTest.php index 4f3d35ca..f3aa346d 100644 --- a/tests/Io/CloseProtectionStreamTest.php +++ b/tests/Io/CloseProtectionStreamTest.php @@ -3,14 +3,16 @@ namespace React\Tests\Http\Io; use React\Http\Io\CloseProtectionStream; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; +use React\Stream\WritableStreamInterface; use React\Tests\Http\TestCase; class CloseProtectionStreamTest extends TestCase { public function testCloseDoesNotCloseTheInputStream() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->disableOriginalConstructor()->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->never())->method('pause'); $input->expects($this->never())->method('resume'); $input->expects($this->never())->method('close'); @@ -35,7 +37,7 @@ public function testErrorWontCloseStream() public function testResumeStreamWillResumeInputStream() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('pause'); $input->expects($this->once())->method('resume'); @@ -46,7 +48,7 @@ public function testResumeStreamWillResumeInputStream() public function testCloseResumesInputStreamIfItWasPreviouslyPaused() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('pause'); $input->expects($this->once())->method('resume'); @@ -73,7 +75,7 @@ public function testPipeStream() $input = new ThroughStream(); $protection = new CloseProtectionStream($input); - $dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); + $dest = $this->createMock(WritableStreamInterface::class); $ret = $protection->pipe($dest); @@ -132,7 +134,7 @@ public function testEndWontBeEmittedAfterClose() public function testPauseAfterCloseHasNoEffect() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->never())->method('pause'); $input->expects($this->never())->method('resume'); @@ -146,7 +148,7 @@ public function testPauseAfterCloseHasNoEffect() public function testResumeAfterCloseHasNoEffect() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->never())->method('pause'); $input->expects($this->never())->method('resume'); diff --git a/tests/Io/EmptyBodyStreamTest.php b/tests/Io/EmptyBodyStreamTest.php index 3633ff81..4ee92364 100644 --- a/tests/Io/EmptyBodyStreamTest.php +++ b/tests/Io/EmptyBodyStreamTest.php @@ -3,6 +3,7 @@ namespace React\Tests\Http\Io; use React\Http\Io\EmptyBodyStream; +use React\Stream\WritableStreamInterface; use React\Tests\Http\TestCase; class EmptyBodyStreamTest extends TestCase @@ -36,7 +37,7 @@ public function testResumeIsNoop() public function testPipeStreamReturnsDestinationStream() { - $dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); + $dest = $this->createMock(WritableStreamInterface::class); $ret = $this->bodyStream->pipe($dest); @@ -70,13 +71,13 @@ public function testCloseTwiceEmitsCloseEventAndClearsListeners() public function testTell() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->tell(); } public function testEof() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->eof(); } @@ -87,13 +88,13 @@ public function testIsSeekable() public function testWrite() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->write(''); } public function testRead() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->read(1); } @@ -126,13 +127,13 @@ public function testIsReadableReturnsFalseWhenAlreadyClosed() public function testSeek() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->seek(''); } public function testRewind() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->rewind(); } diff --git a/tests/Io/HttpBodyStreamTest.php b/tests/Io/HttpBodyStreamTest.php index 1fd269b1..c246bd96 100644 --- a/tests/Io/HttpBodyStreamTest.php +++ b/tests/Io/HttpBodyStreamTest.php @@ -3,7 +3,9 @@ namespace React\Tests\Http\Io; use React\Http\Io\HttpBodyStream; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; +use React\Stream\WritableStreamInterface; use React\Tests\Http\TestCase; class HttpBodyStreamTest extends TestCase @@ -28,7 +30,7 @@ public function testDataEmit() public function testPauseStream() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('pause'); $bodyStream = new HttpBodyStream($input, null); @@ -37,7 +39,7 @@ public function testPauseStream() public function testResumeStream() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('resume'); $bodyStream = new HttpBodyStream($input, null); @@ -46,7 +48,7 @@ public function testResumeStream() public function testPipeStream() { - $dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); + $dest = $this->createMock(WritableStreamInterface::class); $ret = $this->bodyStream->pipe($dest); @@ -107,13 +109,13 @@ public function testGetSizeCustom() public function testTell() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->tell(); } public function testEof() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->eof(); } @@ -124,13 +126,13 @@ public function testIsSeekable() public function testWrite() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->write(''); } public function testRead() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->read(''); } @@ -151,13 +153,13 @@ public function testIsReadable() public function testSeek() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->seek(''); } public function testRewind() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->bodyStream->rewind(); } diff --git a/tests/Io/IniUtilTest.php b/tests/Io/IniUtilTest.php index 0bc9a249..2e9f99c9 100644 --- a/tests/Io/IniUtilTest.php +++ b/tests/Io/IniUtilTest.php @@ -7,41 +7,39 @@ class IniUtilTest extends TestCase { - public function provideIniSizes() + public static function provideIniSizes() { - return [ - [ - '1', - 1, - ], - [ - '10', - 10, - ], - [ - '1024', - 1024, - ], - [ - '1K', - 1024, - ], - [ - '1.5M', - 1572864, - ], - [ - '64M', - 67108864, - ], - [ - '8G', - 8589934592, - ], - [ - '1T', - 1099511627776, - ], + yield [ + '1', + 1, + ]; + yield [ + '10', + 10, + ]; + yield [ + '1024', + 1024, + ]; + yield [ + '1K', + 1024, + ]; + yield [ + '1.5M', + 1572864, + ]; + yield [ + '64M', + 67108864, + ]; + yield [ + '8G', + 8589934592, + ]; + yield [ + '1T', + 1099511627776, ]; } @@ -58,16 +56,14 @@ public function testIniSizeToBytesWithInvalidSuffixReturnsNumberWithoutSuffix() $this->assertEquals('2', IniUtil::iniSizeToBytes('2x')); } - public function provideInvalidInputIniSizeToBytes() + public static function provideInvalidInputIniSizeToBytes() { - return [ - ['-1G'], - ['0G'], - ['foo'], - ['fooK'], - ['1ooL'], - ['1ooL'], - ]; + yield ['-1G']; + yield ['0G']; + yield ['foo']; + yield ['fooK']; + yield ['1ooL']; + yield ['1ooL']; } /** @@ -75,7 +71,7 @@ public function provideInvalidInputIniSizeToBytes() */ public function testInvalidInputIniSizeToBytes($input) { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); IniUtil::iniSizeToBytes($input); } } diff --git a/tests/Io/LengthLimitedStreamTest.php b/tests/Io/LengthLimitedStreamTest.php index f1761a0b..b841257a 100644 --- a/tests/Io/LengthLimitedStreamTest.php +++ b/tests/Io/LengthLimitedStreamTest.php @@ -3,7 +3,9 @@ namespace React\Tests\Http\Io; use React\Http\Io\LengthLimitedStream; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; +use React\Stream\WritableStreamInterface; use React\Tests\Http\TestCase; class LengthLimitedStreamTest extends TestCase @@ -59,7 +61,7 @@ public function testHandleError() public function testPauseStream() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('pause'); $stream = new LengthLimitedStream($input, 0); @@ -68,7 +70,7 @@ public function testPauseStream() public function testResumeStream() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('pause'); $stream = new LengthLimitedStream($input, 0); @@ -79,7 +81,7 @@ public function testResumeStream() public function testPipeStream() { $stream = new LengthLimitedStream($this->input, 0); - $dest = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); + $dest = $this->createMock(WritableStreamInterface::class); $ret = $stream->pipe($dest); diff --git a/tests/Io/MiddlewareRunnerTest.php b/tests/Io/MiddlewareRunnerTest.php index e46039bf..a2344d3a 100644 --- a/tests/Io/MiddlewareRunnerTest.php +++ b/tests/Io/MiddlewareRunnerTest.php @@ -23,7 +23,8 @@ public function testEmptyMiddlewareStackThrowsException() $middlewares = []; $middlewareStack = new MiddlewareRunner($middlewares); - $this->setExpectedException('RuntimeException', 'No middleware to run'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('No middleware to run'); $middlewareStack($request); } @@ -74,7 +75,8 @@ function (ServerRequestInterface $request) { $request = new ServerRequest('GET', 'http://example.com/'); - $this->setExpectedException('RuntimeException', 'hello'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('hello'); $middleware($request); } @@ -88,11 +90,12 @@ function (ServerRequestInterface $request) { $request = new ServerRequest('GET', 'http://example.com/'); - $this->setExpectedException('Throwable', 'hello'); + $this->expectException(\Throwable::class); + $this->expectExceptionMessage('hello'); $middleware($request); } - public function provideProcessStackMiddlewares() + public static function provideProcessStackMiddlewares() { $processStackA = new ProcessStack(); $processStackB = new ProcessStack(); @@ -101,41 +104,39 @@ public function provideProcessStackMiddlewares() $responseMiddleware = function () { return new Response(200); }; - return [ + yield [ [ - [ - $processStackA, - $responseMiddleware, - ], - 1, + $processStackA, + $responseMiddleware, ], + 1, + ]; + yield [ [ - [ - $processStackB, - $processStackB, - $responseMiddleware, - ], - 2, + $processStackB, + $processStackB, + $responseMiddleware, ], + 2, + ]; + yield [ [ - [ - $processStackC, - $processStackC, - $processStackC, - $responseMiddleware, - ], - 3, + $processStackC, + $processStackC, + $processStackC, + $responseMiddleware, ], + 3, + ]; + yield [ [ - [ - $processStackD, - $processStackD, - $processStackD, - $processStackD, - $responseMiddleware, - ], - 4, + $processStackD, + $processStackD, + $processStackD, + $processStackD, + $responseMiddleware, ], + 4, ]; } @@ -172,19 +173,17 @@ public function testProcessStack(array $middlewares, $expectedCallCount) } } - public function provideErrorHandler() + public static function provideErrorHandler() { - return [ - [ - function (\Exception $e) { - throw $e; - } - ], - [ - function (\Exception $e) { - return reject($e); - } - ] + yield [ + function (\Exception $e) { + throw $e; + } + ]; + yield [ + function (\Exception $e) { + return reject($e); + } ]; } @@ -193,7 +192,7 @@ function (\Exception $e) { */ public function testNextCanBeRunMoreThanOnceWithoutCorruptingTheMiddlewareStack($errorHandler) { - $exception = new \RuntimeException('exception'); + $exception = new \RuntimeException(\exception::class); $retryCalled = 0; $error = null; $retry = function ($request, $next) use (&$error, &$retryCalled) { @@ -276,129 +275,127 @@ function (ServerRequestInterface $request) use (&$receivedRequests) { ); } - public function provideUncommonMiddlewareArrayFormats() + public static function provideUncommonMiddlewareArrayFormats() { - return [ - [ - function () { - $sequence = ''; - - // Numeric index gap - return [ - 0 => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'A'; - - return $next($request); - }, - 2 => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'B'; - - return $next($request); - }, - 3 => function () use (&$sequence) { - return new Response(200, [], $sequence . 'C'); - }, - ]; - }, - 'ABC', - ], - [ - function () { - $sequence = ''; - - // Reversed numeric indexes - return [ - 2 => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'A'; - - return $next($request); - }, - 1 => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'B'; - - return $next($request); - }, - 0 => function () use (&$sequence) { - return new Response(200, [], $sequence . 'C'); - }, - ]; - }, - 'ABC', - ], - [ - function () { - $sequence = ''; - - // Associative array - return [ - 'middleware1' => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'A'; - - return $next($request); - }, - 'middleware2' => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'B'; - - return $next($request); - }, - 'middleware3' => function () use (&$sequence) { - return new Response(200, [], $sequence . 'C'); - }, - ]; - }, - 'ABC', - ], - [ - function () { - $sequence = ''; - - // Associative array with empty or trimmable string keys - return [ - '' => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'A'; - - return $next($request); - }, - ' ' => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'B'; - - return $next($request); - }, - ' ' => function () use (&$sequence) { - return new Response(200, [], $sequence . 'C'); - }, - ]; - }, - 'ABC', - ], - [ - function () { - $sequence = ''; - - // Mixed array keys - return [ - '' => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'A'; - - return $next($request); - }, - 0 => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'B'; - - return $next($request); - }, - 'foo' => function (ServerRequestInterface $request, $next) use (&$sequence) { - $sequence .= 'C'; - - return $next($request); - }, - 2 => function () use (&$sequence) { - return new Response(200, [], $sequence . 'D'); - }, - ]; - }, - 'ABCD', - ], + yield [ + function () { + $sequence = ''; + + // Numeric index gap + return [ + 0 => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'A'; + + return $next($request); + }, + 2 => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'B'; + + return $next($request); + }, + 3 => function () use (&$sequence) { + return new Response(200, [], $sequence . 'C'); + }, + ]; + }, + 'ABC', + ]; + yield [ + function () { + $sequence = ''; + + // Reversed numeric indexes + return [ + 2 => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'A'; + + return $next($request); + }, + 1 => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'B'; + + return $next($request); + }, + 0 => function () use (&$sequence) { + return new Response(200, [], $sequence . 'C'); + }, + ]; + }, + 'ABC', + ]; + yield [ + function () { + $sequence = ''; + + // Associative array + return [ + 'middleware1' => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'A'; + + return $next($request); + }, + 'middleware2' => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'B'; + + return $next($request); + }, + 'middleware3' => function () use (&$sequence) { + return new Response(200, [], $sequence . 'C'); + }, + ]; + }, + 'ABC', + ]; + yield [ + function () { + $sequence = ''; + + // Associative array with empty or trimmable string keys + return [ + '' => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'A'; + + return $next($request); + }, + ' ' => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'B'; + + return $next($request); + }, + ' ' => function () use (&$sequence) { + return new Response(200, [], $sequence . 'C'); + }, + ]; + }, + 'ABC', + ]; + yield [ + function () { + $sequence = ''; + + // Mixed array keys + return [ + '' => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'A'; + + return $next($request); + }, + 0 => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'B'; + + return $next($request); + }, + 'foo' => function (ServerRequestInterface $request, $next) use (&$sequence) { + $sequence .= 'C'; + + return $next($request); + }, + 2 => function () use (&$sequence) { + return new Response(200, [], $sequence . 'D'); + }, + ]; + }, + 'ABCD', ]; } diff --git a/tests/Io/MultipartParserTest.php b/tests/Io/MultipartParserTest.php index ba439760..ebc5972f 100644 --- a/tests/Io/MultipartParserTest.php +++ b/tests/Io/MultipartParserTest.php @@ -2,6 +2,7 @@ namespace React\Tests\Http\Io\Middleware; +use Psr\Http\Message\UploadedFileInterface; use React\Http\Io\MultipartParser; use React\Http\Message\ServerRequest; use React\Tests\Http\TestCase; @@ -673,7 +674,7 @@ public function testInvalidUploadFileWithoutContentTypeUsesNullValue() $this->assertCount(1, $files); $this->assertTrue(isset($files['file'])); - $this->assertInstanceOf('Psr\Http\Message\UploadedFileInterface', $files['file']); + $this->assertInstanceOf(UploadedFileInterface::class, $files['file']); /* @var $file \Psr\Http\Message\UploadedFileInterface */ $file = $files['file']; @@ -708,7 +709,7 @@ public function testInvalidUploadFileWithoutMultipleContentTypeUsesLastValue() $this->assertCount(1, $files); $this->assertTrue(isset($files['file'])); - $this->assertInstanceOf('Psr\Http\Message\UploadedFileInterface', $files['file']); + $this->assertInstanceOf(UploadedFileInterface::class, $files['file']); /* @var $file \Psr\Http\Message\UploadedFileInterface */ $file = $files['file']; @@ -742,7 +743,7 @@ public function testUploadEmptyFile() $this->assertCount(1, $files); $this->assertTrue(isset($files['file'])); - $this->assertInstanceOf('Psr\Http\Message\UploadedFileInterface', $files['file']); + $this->assertInstanceOf(UploadedFileInterface::class, $files['file']); /* @var $file \Psr\Http\Message\UploadedFileInterface */ $file = $files['file']; @@ -776,7 +777,7 @@ public function testUploadTooLargeFile() $this->assertCount(1, $files); $this->assertTrue(isset($files['file'])); - $this->assertInstanceOf('Psr\Http\Message\UploadedFileInterface', $files['file']); + $this->assertInstanceOf(UploadedFileInterface::class, $files['file']); /* @var $file \Psr\Http\Message\UploadedFileInterface */ $file = $files['file']; @@ -809,7 +810,7 @@ public function testUploadTooLargeFileWithIniLikeSize() $this->assertCount(1, $files); $this->assertTrue(isset($files['file'])); - $this->assertInstanceOf('Psr\Http\Message\UploadedFileInterface', $files['file']); + $this->assertInstanceOf(UploadedFileInterface::class, $files['file']); /* @var $file \Psr\Http\Message\UploadedFileInterface */ $file = $files['file']; @@ -842,7 +843,7 @@ public function testUploadNoFile() $this->assertCount(1, $files); $this->assertTrue(isset($files['file'])); - $this->assertInstanceOf('Psr\Http\Message\UploadedFileInterface', $files['file']); + $this->assertInstanceOf(UploadedFileInterface::class, $files['file']); /* @var $file \Psr\Http\Message\UploadedFileInterface */ $file = $files['file']; @@ -1046,7 +1047,7 @@ public function testWeOnlyParseTheAmountOfMultiPartChunksWeConfigured() $parser = new MultipartParser(); - $reflectecClass = new \ReflectionClass('\React\Http\Io\MultipartParser'); + $reflectecClass = new \ReflectionClass(MultipartParser::class); $requestProperty = $reflectecClass->getProperty('request'); $requestProperty->setAccessible(true); $cursorProperty = $reflectecClass->getProperty('cursor'); diff --git a/tests/Io/PauseBufferStreamTest.php b/tests/Io/PauseBufferStreamTest.php index 05bf3ee3..139db8fd 100644 --- a/tests/Io/PauseBufferStreamTest.php +++ b/tests/Io/PauseBufferStreamTest.php @@ -2,15 +2,16 @@ namespace React\Tests\Io; -use React\Tests\Http\TestCase; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; +use React\Tests\Http\TestCase; use React\Http\Io\PauseBufferStream; class PauseBufferStreamTest extends TestCase { public function testPauseMethodWillBePassedThroughToInput() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('pause'); $stream = new PauseBufferStream($input); @@ -19,7 +20,7 @@ public function testPauseMethodWillBePassedThroughToInput() public function testCloseMethodWillBePassedThroughToInput() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->once())->method('close'); $stream = new PauseBufferStream($input); @@ -28,7 +29,7 @@ public function testCloseMethodWillBePassedThroughToInput() public function testPauseMethodWillNotBePassedThroughToInputAfterClose() { - $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $input = $this->createMock(ReadableStreamInterface::class); $input->expects($this->never())->method('pause'); $stream = new PauseBufferStream($input); diff --git a/tests/Io/ReadableBodyStreamTest.php b/tests/Io/ReadableBodyStreamTest.php index 8ece6791..2409a6be 100644 --- a/tests/Io/ReadableBodyStreamTest.php +++ b/tests/Io/ReadableBodyStreamTest.php @@ -3,8 +3,9 @@ namespace React\Tests\Http\Io; use React\Http\Io\ReadableBodyStream; -use React\Tests\Http\TestCase; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; +use React\Tests\Http\TestCase; class ReadableBodyStreamTest extends TestCase { @@ -16,7 +17,7 @@ class ReadableBodyStreamTest extends TestCase */ public function setUpStream() { - $this->input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $this->input = $this->createMock(ReadableStreamInterface::class); $this->stream = new ReadableBodyStream($this->input); } @@ -102,7 +103,7 @@ public function testEndInputWillEmitErrorEventWhenDataDoesNotReachExpectedLength $this->input->write('hi'); $this->input->end(); - $this->assertInstanceOf('UnderflowException', $called); + $this->assertInstanceOf(\UnderflowException::class, $called); $this->assertSame('Unexpected end of response body after 2/5 bytes', $called->getMessage()); } @@ -188,7 +189,7 @@ public function testPointlessTostringReturnsEmptyString() public function testPointlessDetachThrows() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->stream->detach(); } @@ -199,7 +200,7 @@ public function testPointlessGetSizeReturnsNull() public function testPointlessTellThrows() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->stream->tell(); } @@ -210,13 +211,13 @@ public function testPointlessIsSeekableReturnsFalse() public function testPointlessSeekThrows() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->stream->seek(0); } public function testPointlessRewindThrows() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->stream->rewind(); } @@ -227,19 +228,19 @@ public function testPointlessIsWritableReturnsFalse() public function testPointlessWriteThrows() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->stream->write(''); } public function testPointlessReadThrows() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->stream->read(8192); } public function testPointlessGetContentsThrows() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $this->stream->getContents(); } diff --git a/tests/Io/RequestHeaderParserTest.php b/tests/Io/RequestHeaderParserTest.php index d15d4e7f..568fc375 100644 --- a/tests/Io/RequestHeaderParserTest.php +++ b/tests/Io/RequestHeaderParserTest.php @@ -2,20 +2,24 @@ namespace React\Tests\Http\Io; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ServerRequestInterface; +use React\Http\Io\Clock; use React\Http\Io\RequestHeaderParser; +use React\Socket\Connection; +use React\Stream\ReadableStreamInterface; use React\Tests\Http\TestCase; class RequestHeaderParserTest extends TestCase { public function testSplitShouldHappenOnDoubleCrlf() { - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); @@ -31,12 +35,12 @@ public function testSplitShouldHappenOnDoubleCrlf() public function testFeedInOneGo() { - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableOnce()); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $data = $this->createGetRequest(); @@ -45,7 +49,7 @@ public function testFeedInOneGo() public function testFeedTwoRequestsOnSeparateConnections() { - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); @@ -54,8 +58,8 @@ public function testFeedTwoRequestsOnSeparateConnections() ++$called; }); - $connection1 = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); - $connection2 = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection1 = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection2 = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection1); $parser->handle($connection2); @@ -71,7 +75,7 @@ public function testHeadersEventShouldEmitRequestAndConnection() $request = null; $conn = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', function ($parsedRequest, $connection) use (&$request, &$conn) { @@ -79,13 +83,13 @@ public function testHeadersEventShouldEmitRequestAndConnection() $conn = $connection; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $data = $this->createGetRequest(); $connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\RequestInterface', $request); + $this->assertInstanceOf(RequestInterface::class, $request); $this->assertSame('GET', $request->getMethod()); $this->assertEquals('http://example.com/', $request->getUri()); $this->assertSame('1.1', $request->getProtocolVersion()); @@ -96,21 +100,21 @@ public function testHeadersEventShouldEmitRequestAndConnection() public function testHeadersEventShouldEmitRequestWhichShouldEmitEndForStreamingBodyWithoutContentLengthFromInitialRequestBody() { - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $ended = false; $parser->on('headers', function (ServerRequestInterface $request) use (&$ended) { $body = $request->getBody(); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); $body->on('end', function () use (&$ended) { $ended = true; }); }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $data = "GET / HTTP/1.0\r\n\r\n"; @@ -121,14 +125,14 @@ public function testHeadersEventShouldEmitRequestWhichShouldEmitEndForStreamingB public function testHeadersEventShouldEmitRequestWhichShouldEmitStreamingBodyDataFromInitialRequestBody() { - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $buffer = ''; $parser->on('headers', function (ServerRequestInterface $request) use (&$buffer) { $body = $request->getBody(); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); $body->on('data', function ($chunk) use (&$buffer) { $buffer .= $chunk; @@ -138,7 +142,7 @@ public function testHeadersEventShouldEmitRequestWhichShouldEmitStreamingBodyDat }); }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $data = "POST / HTTP/1.0\r\nContent-Length: 11\r\n\r\n"; @@ -150,21 +154,21 @@ public function testHeadersEventShouldEmitRequestWhichShouldEmitStreamingBodyDat public function testHeadersEventShouldEmitRequestWhichShouldEmitStreamingBodyWithPlentyOfDataFromInitialRequestBody() { - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $buffer = ''; $parser->on('headers', function (ServerRequestInterface $request) use (&$buffer) { $body = $request->getBody(); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); $body->on('data', function ($chunk) use (&$buffer) { $buffer .= $chunk; }); }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $size = 10000; @@ -177,21 +181,21 @@ public function testHeadersEventShouldEmitRequestWhichShouldEmitStreamingBodyWit public function testHeadersEventShouldEmitRequestWhichShouldNotEmitStreamingBodyDataWithoutContentLengthFromInitialRequestBody() { - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $buffer = ''; $parser->on('headers', function (ServerRequestInterface $request) use (&$buffer) { $body = $request->getBody(); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); $body->on('data', function ($chunk) use (&$buffer) { $buffer .= $chunk; }); }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $data = "POST / HTTP/1.0\r\n\r\n"; @@ -203,21 +207,21 @@ public function testHeadersEventShouldEmitRequestWhichShouldNotEmitStreamingBody public function testHeadersEventShouldEmitRequestWhichShouldEmitStreamingBodyDataUntilContentLengthBoundaryFromInitialRequestBody() { - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $buffer = ''; $parser->on('headers', function (ServerRequestInterface $request) use (&$buffer) { $body = $request->getBody(); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); $body->on('data', function ($chunk) use (&$buffer) { $buffer .= $chunk; }); }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $data = "POST / HTTP/1.0\r\nContent-Length: 6\r\n\r\n"; @@ -231,20 +235,20 @@ public function testHeadersEventShouldParsePathAndQueryString() { $request = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', function ($parsedRequest) use (&$request) { $request = $parsedRequest; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $data = $this->createAdvancedPostRequest(); $connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\RequestInterface', $request); + $this->assertInstanceOf(RequestInterface::class, $request); $this->assertSame('POST', $request->getMethod()); $this->assertEquals('http://example.com/foo?bar=baz', $request->getUri()); $this->assertSame('1.1', $request->getProtocolVersion()); @@ -260,14 +264,14 @@ public function testHeaderEventWithShouldApplyDefaultAddressFromLocalConnectionA { $request = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', function ($parsedRequest) use (&$request) { $request = $parsedRequest; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(['getLocalAddress'])->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(['getLocalAddress'])->getMock(); $connection->expects($this->once())->method('getLocalAddress')->willReturn('tcp://127.1.1.1:8000'); $parser->handle($connection); @@ -281,14 +285,14 @@ public function testHeaderEventViaHttpsShouldApplyHttpsSchemeFromLocalTlsConnect { $request = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', function ($parsedRequest) use (&$request) { $request = $parsedRequest; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(['getLocalAddress'])->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(['getLocalAddress'])->getMock(); $connection->expects($this->once())->method('getLocalAddress')->willReturn('tls://127.1.1.1:8000'); $parser->handle($connection); @@ -303,7 +307,7 @@ public function testHeaderOverflowShouldEmitError() $error = null; $passedConnection = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -312,13 +316,13 @@ public function testHeaderOverflowShouldEmitError() $passedConnection = $connection; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $data = str_repeat('A', 8193); $connection->emit('data', [$data]); - $this->assertInstanceOf('OverflowException', $error); + $this->assertInstanceOf(\OverflowException::class, $error); $this->assertSame('Maximum header size of 8192 exceeded.', $error->getMessage()); $this->assertSame($connection, $passedConnection); } @@ -327,7 +331,7 @@ public function testInvalidEmptyRequestHeadersParseException() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -335,12 +339,12 @@ public function testInvalidEmptyRequestHeadersParseException() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame('Unable to parse invalid request-line', $error->getMessage()); } @@ -348,7 +352,7 @@ public function testInvalidMalformedRequestLineParseException() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -356,12 +360,12 @@ public function testInvalidMalformedRequestLineParseException() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET /\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame('Unable to parse invalid request-line', $error->getMessage()); } @@ -369,7 +373,7 @@ public function testInvalidMalformedRequestHeadersThrowsParseException() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -377,12 +381,12 @@ public function testInvalidMalformedRequestHeadersThrowsParseException() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET / HTTP/1.1\r\nHost : yes\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame('Unable to parse invalid request header fields', $error->getMessage()); } @@ -390,7 +394,7 @@ public function testInvalidMalformedRequestHeadersWhitespaceThrowsParseException { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -398,12 +402,12 @@ public function testInvalidMalformedRequestHeadersWhitespaceThrowsParseException $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET / HTTP/1.1\r\nHost: yes\rFoo: bar\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame('Unable to parse invalid request header fields', $error->getMessage()); } @@ -411,7 +415,7 @@ public function testInvalidAbsoluteFormSchemeEmitsError() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -419,12 +423,12 @@ public function testInvalidAbsoluteFormSchemeEmitsError() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET tcp://example.com:80/ HTTP/1.0\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame('Invalid absolute-form request-target', $error->getMessage()); } @@ -432,7 +436,7 @@ public function testOriginFormWithSchemeSeparatorInParam() { $request = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('error', $this->expectCallableNever()); @@ -440,12 +444,12 @@ public function testOriginFormWithSchemeSeparatorInParam() $request = $parsedRequest; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET /somepath?param=http://example.com HTTP/1.1\r\nHost: localhost\r\n\r\n"]); - $this->assertInstanceOf('Psr\Http\Message\RequestInterface', $request); + $this->assertInstanceOf(RequestInterface::class, $request); $this->assertSame('GET', $request->getMethod()); $this->assertEquals('http://localhost/somepath?param=http://example.com', $request->getUri()); $this->assertSame('1.1', $request->getProtocolVersion()); @@ -459,7 +463,7 @@ public function testUriStartingWithColonSlashSlashFails() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -467,12 +471,12 @@ public function testUriStartingWithColonSlashSlashFails() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET ://example.com:80/ HTTP/1.0\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame('Invalid absolute-form request-target', $error->getMessage()); } @@ -480,7 +484,7 @@ public function testInvalidAbsoluteFormWithFragmentEmitsError() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -488,12 +492,12 @@ public function testInvalidAbsoluteFormWithFragmentEmitsError() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET http://example.com:80/#home HTTP/1.0\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame('Invalid absolute-form request-target', $error->getMessage()); } @@ -501,7 +505,7 @@ public function testInvalidHeaderContainsFullUri() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -509,12 +513,12 @@ public function testInvalidHeaderContainsFullUri() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET / HTTP/1.1\r\nHost: http://user:pass@host/\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame('Invalid Host header value', $error->getMessage()); } @@ -522,7 +526,7 @@ public function testInvalidAbsoluteFormWithHostHeaderEmpty() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -530,12 +534,12 @@ public function testInvalidAbsoluteFormWithHostHeaderEmpty() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET http://example.com/ HTTP/1.1\r\nHost: \r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame('Invalid Host header value', $error->getMessage()); } @@ -543,7 +547,7 @@ public function testInvalidConnectRequestWithNonAuthorityForm() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -551,12 +555,12 @@ public function testInvalidConnectRequestWithNonAuthorityForm() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["CONNECT http://example.com:8080/ HTTP/1.1\r\nHost: example.com:8080\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame('CONNECT method MUST use authority-form request target', $error->getMessage()); } @@ -564,7 +568,7 @@ public function testInvalidHttpVersion() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -572,12 +576,12 @@ public function testInvalidHttpVersion() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET / HTTP/1.2\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame(505, $error->getCode()); $this->assertSame('Received request with invalid protocol version', $error->getMessage()); } @@ -586,7 +590,7 @@ public function testInvalidContentLengthRequestHeaderWillEmitError() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -594,12 +598,12 @@ public function testInvalidContentLengthRequestHeaderWillEmitError() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: foo\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame(400, $error->getCode()); $this->assertSame('The value of `Content-Length` is not valid', $error->getMessage()); } @@ -608,7 +612,7 @@ public function testInvalidRequestWithMultipleContentLengthRequestHeadersWillEmi { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -616,12 +620,12 @@ public function testInvalidRequestWithMultipleContentLengthRequestHeadersWillEmi $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 4\r\nContent-Length: 5\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame(400, $error->getCode()); $this->assertSame('The value of `Content-Length` is not valid', $error->getMessage()); } @@ -630,7 +634,7 @@ public function testInvalidTransferEncodingRequestHeaderWillEmitError() { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -638,12 +642,12 @@ public function testInvalidTransferEncodingRequestHeaderWillEmitError() $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET / HTTP/1.1\r\nHost: localhost\r\nTransfer-Encoding: foo\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame(501, $error->getCode()); $this->assertSame('Only chunked-encoding is allowed for Transfer-Encoding', $error->getMessage()); } @@ -652,7 +656,7 @@ public function testInvalidRequestWithBothTransferEncodingAndContentLengthWillEm { $error = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); $parser->on('headers', $this->expectCallableNever()); @@ -660,12 +664,12 @@ public function testInvalidRequestWithBothTransferEncodingAndContentLengthWillEm $error = $message; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET / HTTP/1.1\r\nHost: localhost\r\nTransfer-Encoding: chunked\r\nContent-Length: 0\r\n\r\n"]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); $this->assertSame(400, $error->getCode()); $this->assertSame('Using both `Transfer-Encoding: chunked` and `Content-Length` is not allowed', $error->getMessage()); } @@ -674,7 +678,7 @@ public function testServerParamsWillBeSetOnHttpsRequest() { $request = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $clock->expects($this->once())->method('now')->willReturn(1652972091.3958); $parser = new RequestHeaderParser($clock); @@ -683,7 +687,7 @@ public function testServerParamsWillBeSetOnHttpsRequest() $request = $parsedRequest; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(['getLocalAddress', 'getRemoteAddress'])->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(['getLocalAddress', 'getRemoteAddress'])->getMock(); $connection->expects($this->once())->method('getLocalAddress')->willReturn('tls://127.1.1.1:8000'); $connection->expects($this->once())->method('getRemoteAddress')->willReturn('tls://192.168.1.1:8001'); $parser->handle($connection); @@ -707,7 +711,7 @@ public function testServerParamsWillBeSetOnHttpRequest() { $request = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $clock->expects($this->once())->method('now')->willReturn(1652972091.3958); $parser = new RequestHeaderParser($clock); @@ -716,7 +720,7 @@ public function testServerParamsWillBeSetOnHttpRequest() $request = $parsedRequest; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(['getLocalAddress', 'getRemoteAddress'])->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(['getLocalAddress', 'getRemoteAddress'])->getMock(); $connection->expects($this->once())->method('getLocalAddress')->willReturn('tcp://127.1.1.1:8000'); $connection->expects($this->once())->method('getRemoteAddress')->willReturn('tcp://192.168.1.1:8001'); $parser->handle($connection); @@ -740,7 +744,7 @@ public function testServerParamsWillNotSetRemoteAddressForUnixDomainSockets() { $request = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $clock->expects($this->once())->method('now')->willReturn(1652972091.3958); $parser = new RequestHeaderParser($clock); @@ -749,7 +753,7 @@ public function testServerParamsWillNotSetRemoteAddressForUnixDomainSockets() $request = $parsedRequest; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(['getLocalAddress', 'getRemoteAddress'])->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(['getLocalAddress', 'getRemoteAddress'])->getMock(); $connection->expects($this->once())->method('getLocalAddress')->willReturn('unix://./server.sock'); $connection->expects($this->once())->method('getRemoteAddress')->willReturn(null); $parser->handle($connection); @@ -773,7 +777,7 @@ public function testServerParamsWontBeSetOnMissingUrls() { $request = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $clock->expects($this->once())->method('now')->willReturn(1652972091.3958); $parser = new RequestHeaderParser($clock); @@ -782,7 +786,7 @@ public function testServerParamsWontBeSetOnMissingUrls() $request = $parsedRequest; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET /foo HTTP/1.0\r\nHost: example.com\r\n\r\n"]); @@ -801,12 +805,12 @@ public function testServerParamsWontBeSetOnMissingUrls() public function testServerParamsWillBeReusedForMultipleRequestsFromSameConnection() { - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $clock->expects($this->exactly(2))->method('now')->willReturn(1652972091.3958); $parser = new RequestHeaderParser($clock); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(['getLocalAddress', 'getRemoteAddress'])->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(['getLocalAddress', 'getRemoteAddress'])->getMock(); $connection->expects($this->once())->method('getLocalAddress')->willReturn('tcp://127.1.1.1:8000'); $connection->expects($this->once())->method('getRemoteAddress')->willReturn('tcp://192.168.1.1:8001'); @@ -837,11 +841,11 @@ public function testServerParamsWillBeReusedForMultipleRequestsFromSameConnectio public function testServerParamsWillBeRememberedUntilConnectionIsClosed() { - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(['getLocalAddress', 'getRemoteAddress'])->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(['getLocalAddress', 'getRemoteAddress'])->getMock(); $parser->handle($connection); $connection->emit('data', ["GET /foo HTTP/1.0\r\nHost: example.com\r\n\r\n"]); @@ -859,7 +863,7 @@ public function testQueryParmetersWillBeSet() { $request = null; - $clock = $this->getMockBuilder('React\Http\Io\Clock')->disableOriginalConstructor()->getMock(); + $clock = $this->createMock(Clock::class); $parser = new RequestHeaderParser($clock); @@ -867,7 +871,7 @@ public function testQueryParmetersWillBeSet() $request = $parsedRequest; }); - $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); + $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); $connection->emit('data', ["GET /foo.php?hello=world&test=this HTTP/1.0\r\nHost: example.com\r\n\r\n"]); diff --git a/tests/Io/SenderTest.php b/tests/Io/SenderTest.php index 59bb9719..df4c5359 100644 --- a/tests/Io/SenderTest.php +++ b/tests/Io/SenderTest.php @@ -3,13 +3,17 @@ namespace React\Tests\Http\Io; use Psr\Http\Message\RequestInterface; +use React\EventLoop\LoopInterface; use React\Http\Client\Client as HttpClient; use React\Http\Io\ClientConnectionManager; +use React\Http\Io\ClientRequestStream; use React\Http\Io\EmptyBodyStream; use React\Http\Io\ReadableBodyStream; use React\Http\Io\Sender; use React\Http\Message\Request; use React\Promise\Promise; +use React\Socket\ConnectionInterface; +use React\Socket\ConnectorInterface; use React\Stream\ThroughStream; use React\Tests\Http\TestCase; use function React\Promise\reject; @@ -25,19 +29,19 @@ class SenderTest extends TestCase */ public function setUpLoop() { - $this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $this->loop = $this->createMock(LoopInterface::class); } public function testCreateFromLoop() { $sender = Sender::createFromLoop($this->loop, null); - $this->assertInstanceOf('React\Http\Io\Sender', $sender); + $this->assertInstanceOf(Sender::class, $sender); } public function testSenderRejectsInvalidUri() { - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->never())->method('connect'); $sender = new Sender(new HttpClient(new ClientConnectionManager($connector, $this->loop))); @@ -51,12 +55,12 @@ public function testSenderRejectsInvalidUri() $exception = $e; }); - $this->assertInstanceOf('InvalidArgumentException', $exception); + $this->assertInstanceOf(\InvalidArgumentException::class, $exception); } public function testSenderConnectorRejection() { - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->willReturn(reject(new \RuntimeException('Rejected'))); $sender = new Sender(new HttpClient(new ClientConnectionManager($connector, $this->loop))); @@ -70,15 +74,15 @@ public function testSenderConnectorRejection() $exception = $e; }); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); } public function testSendPostWillAutomaticallySendContentLengthHeader() { - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->with($this->callback(function (RequestInterface $request) { return $request->getHeaderLine('Content-Length') === '5'; - }))->willReturn($this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock()); + }))->willReturn($this->createMock(ClientRequestStream::class)); $sender = new Sender($client); @@ -88,10 +92,10 @@ public function testSendPostWillAutomaticallySendContentLengthHeader() public function testSendPostWillAutomaticallySendContentLengthZeroHeaderForEmptyRequestBody() { - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->with($this->callback(function (RequestInterface $request) { return $request->getHeaderLine('Content-Length') === '0'; - }))->willReturn($this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock()); + }))->willReturn($this->createMock(ClientRequestStream::class)); $sender = new Sender($client); @@ -101,10 +105,10 @@ public function testSendPostWillAutomaticallySendContentLengthZeroHeaderForEmpty public function testSendPostStreamWillAutomaticallySendTransferEncodingChunked() { - $outgoing = $this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock(); + $outgoing = $this->createMock(ClientRequestStream::class); $outgoing->expects($this->once())->method('write')->with(""); - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->with($this->callback(function (RequestInterface $request) { return $request->getHeaderLine('Transfer-Encoding') === 'chunked'; }))->willReturn($outgoing); @@ -118,11 +122,11 @@ public function testSendPostStreamWillAutomaticallySendTransferEncodingChunked() public function testSendPostStreamWillAutomaticallyPipeChunkEncodeBodyForWriteAndRespectRequestThrottling() { - $outgoing = $this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock(); + $outgoing = $this->createMock(ClientRequestStream::class); $outgoing->expects($this->once())->method('isWritable')->willReturn(true); $outgoing->expects($this->exactly(2))->method('write')->withConsecutive([""], ["5\r\nhello\r\n"])->willReturn(false); - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->willReturn($outgoing); $sender = new Sender($client); @@ -137,12 +141,12 @@ public function testSendPostStreamWillAutomaticallyPipeChunkEncodeBodyForWriteAn public function testSendPostStreamWillAutomaticallyPipeChunkEncodeBodyForEnd() { - $outgoing = $this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock(); + $outgoing = $this->createMock(ClientRequestStream::class); $outgoing->expects($this->once())->method('isWritable')->willReturn(true); $outgoing->expects($this->exactly(2))->method('write')->withConsecutive([""], ["0\r\n\r\n"])->willReturn(false); $outgoing->expects($this->once())->method('end')->with(null); - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->willReturn($outgoing); $sender = new Sender($client); @@ -156,13 +160,13 @@ public function testSendPostStreamWillAutomaticallyPipeChunkEncodeBodyForEnd() public function testSendPostStreamWillRejectWhenRequestBodyEmitsErrorEvent() { - $outgoing = $this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock(); + $outgoing = $this->createMock(ClientRequestStream::class); $outgoing->expects($this->once())->method('isWritable')->willReturn(true); $outgoing->expects($this->once())->method('write')->with("")->willReturn(false); $outgoing->expects($this->never())->method('end'); $outgoing->expects($this->once())->method('close'); - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->willReturn($outgoing); $sender = new Sender($client); @@ -179,20 +183,20 @@ public function testSendPostStreamWillRejectWhenRequestBodyEmitsErrorEvent() $exception = $e; }); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); $this->assertEquals('Request failed because request body reported an error', $exception->getMessage()); $this->assertSame($expected, $exception->getPrevious()); } public function testSendPostStreamWillRejectWhenRequestBodyClosesWithoutEnd() { - $outgoing = $this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock(); + $outgoing = $this->createMock(ClientRequestStream::class); $outgoing->expects($this->once())->method('isWritable')->willReturn(true); $outgoing->expects($this->once())->method('write')->with("")->willReturn(false); $outgoing->expects($this->never())->method('end'); $outgoing->expects($this->once())->method('close'); - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->willReturn($outgoing); $sender = new Sender($client); @@ -208,19 +212,19 @@ public function testSendPostStreamWillRejectWhenRequestBodyClosesWithoutEnd() $exception = $e; }); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); $this->assertEquals('Request failed because request body closed unexpectedly', $exception->getMessage()); } public function testSendPostStreamWillNotRejectWhenRequestBodyClosesAfterEnd() { - $outgoing = $this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock(); + $outgoing = $this->createMock(ClientRequestStream::class); $outgoing->expects($this->once())->method('isWritable')->willReturn(true); $outgoing->expects($this->exactly(2))->method('write')->withConsecutive([""], ["0\r\n\r\n"])->willReturn(false); $outgoing->expects($this->once())->method('end'); $outgoing->expects($this->never())->method('close'); - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->willReturn($outgoing); $sender = new Sender($client); @@ -242,10 +246,10 @@ public function testSendPostStreamWillNotRejectWhenRequestBodyClosesAfterEnd() public function testSendPostStreamWithExplicitContentLengthWillSendHeaderAsIs() { - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->with($this->callback(function (RequestInterface $request) { return $request->getHeaderLine('Content-Length') === '100'; - }))->willReturn($this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock()); + }))->willReturn($this->createMock(ClientRequestStream::class)); $sender = new Sender($client); @@ -256,10 +260,10 @@ public function testSendPostStreamWithExplicitContentLengthWillSendHeaderAsIs() public function testSendGetWillNotPassContentLengthHeaderForEmptyRequestBody() { - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->with($this->callback(function (RequestInterface $request) { return !$request->hasHeader('Content-Length'); - }))->willReturn($this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock()); + }))->willReturn($this->createMock(ClientRequestStream::class)); $sender = new Sender($client); @@ -269,10 +273,10 @@ public function testSendGetWillNotPassContentLengthHeaderForEmptyRequestBody() public function testSendGetWithEmptyBodyStreamWillNotPassContentLengthOrTransferEncodingHeader() { - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->with($this->callback(function (RequestInterface $request) { return !$request->hasHeader('Content-Length') && !$request->hasHeader('Transfer-Encoding'); - }))->willReturn($this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock()); + }))->willReturn($this->createMock(ClientRequestStream::class)); $sender = new Sender($client); @@ -284,10 +288,10 @@ public function testSendGetWithEmptyBodyStreamWillNotPassContentLengthOrTransfer public function testSendCustomMethodWillNotPassContentLengthHeaderForEmptyRequestBody() { - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->with($this->callback(function (RequestInterface $request) { return !$request->hasHeader('Content-Length'); - }))->willReturn($this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock()); + }))->willReturn($this->createMock(ClientRequestStream::class)); $sender = new Sender($client); @@ -297,10 +301,10 @@ public function testSendCustomMethodWillNotPassContentLengthHeaderForEmptyReques public function testSendCustomMethodWithExplicitContentLengthZeroWillBePassedAsIs() { - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->with($this->callback(function (RequestInterface $request) { return $request->getHeaderLine('Content-Length') === '0'; - }))->willReturn($this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock()); + }))->willReturn($this->createMock(ClientRequestStream::class)); $sender = new Sender($client); @@ -311,10 +315,10 @@ public function testSendCustomMethodWithExplicitContentLengthZeroWillBePassedAsI /** @test */ public function getRequestWithUserAndPassShouldSendAGetRequestWithBasicAuthorizationHeader() { - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->with($this->callback(function (RequestInterface $request) { return $request->getHeaderLine('Authorization') === 'Basic am9objpkdW1teQ=='; - }))->willReturn($this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock()); + }))->willReturn($this->createMock(ClientRequestStream::class)); $sender = new Sender($client); @@ -325,10 +329,10 @@ public function getRequestWithUserAndPassShouldSendAGetRequestWithBasicAuthoriza /** @test */ public function getRequestWithUserAndPassShouldSendAGetRequestWithGivenAuthorizationHeaderBasicAuthorizationHeader() { - $client = $this->getMockBuilder('React\Http\Client\Client')->disableOriginalConstructor()->getMock(); + $client = $this->createMock(HttpClient::class); $client->expects($this->once())->method('request')->with($this->callback(function (RequestInterface $request) { return $request->getHeaderLine('Authorization') === 'bearer abc123'; - }))->willReturn($this->getMockBuilder('React\Http\Io\ClientRequestStream')->disableOriginalConstructor()->getMock()); + }))->willReturn($this->createMock(ClientRequestStream::class)); $sender = new Sender($client); @@ -342,7 +346,7 @@ public function testCancelRequestWillCancelConnector() throw new \RuntimeException(); }); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->willReturn($promise); $sender = new Sender(new HttpClient(new ClientConnectionManager($connector, $this->loop))); @@ -357,15 +361,15 @@ public function testCancelRequestWillCancelConnector() $exception = $e; }); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); } public function testCancelRequestWillCloseConnection() { - $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); + $connection = $this->createMock(ConnectionInterface::class); $connection->expects($this->once())->method('close'); - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); + $connector = $this->createMock(ConnectorInterface::class); $connector->expects($this->once())->method('connect')->willReturn(resolve($connection)); $sender = new Sender(new HttpClient(new ClientConnectionManager($connector, $this->loop))); @@ -380,6 +384,6 @@ public function testCancelRequestWillCloseConnection() $exception = $e; }); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); } } diff --git a/tests/Io/StreamingServerTest.php b/tests/Io/StreamingServerTest.php index 3b5f28f4..a61d1425 100644 --- a/tests/Io/StreamingServerTest.php +++ b/tests/Io/StreamingServerTest.php @@ -4,11 +4,14 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Message\StreamInterface; use React\EventLoop\Loop; +use React\Http\Io\RequestHeaderParser; use React\Http\Io\StreamingServer; use React\Http\Message\Response; use React\Http\Message\ServerRequest; use React\Promise\Promise; +use React\Socket\Connection; use React\Stream\ThroughStream; use React\Tests\Http\SocketServerStub; use React\Tests\Http\TestCase; @@ -35,7 +38,7 @@ public function setUpConnectionMockAndSocket() private function mockConnection(array $additionalMethods = null) { - $connection = $this->getMockBuilder('React\Socket\Connection') + $connection = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->setMethods(array_merge( [ @@ -125,7 +128,7 @@ public function testRequestEvent() $serverParams = $requestAssertion->getServerParams(); $this->assertSame(1, $i); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('GET', $requestAssertion->getMethod()); $this->assertSame('/', $requestAssertion->getRequestTarget()); $this->assertSame('/', $requestAssertion->getUri()->getPath()); @@ -158,7 +161,7 @@ public function testRequestEventWithSingleRequestHandlerArray() $serverParams = $requestAssertion->getServerParams(); $this->assertSame(1, $i); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('GET', $requestAssertion->getMethod()); $this->assertSame('/', $requestAssertion->getRequestTarget()); $this->assertSame('/', $requestAssertion->getUri()->getPath()); @@ -181,7 +184,7 @@ public function testRequestGetWithHostAndCustomPort() $data = "GET / HTTP/1.1\r\nHost: example.com:8080\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('GET', $requestAssertion->getMethod()); $this->assertSame('/', $requestAssertion->getRequestTarget()); $this->assertSame('/', $requestAssertion->getUri()->getPath()); @@ -203,7 +206,7 @@ public function testRequestGetWithHostAndHttpsPort() $data = "GET / HTTP/1.1\r\nHost: example.com:443\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('GET', $requestAssertion->getMethod()); $this->assertSame('/', $requestAssertion->getRequestTarget()); $this->assertSame('/', $requestAssertion->getUri()->getPath()); @@ -225,7 +228,7 @@ public function testRequestGetWithHostAndDefaultPortWillBeIgnored() $data = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('GET', $requestAssertion->getMethod()); $this->assertSame('/', $requestAssertion->getRequestTarget()); $this->assertSame('/', $requestAssertion->getUri()->getPath()); @@ -247,7 +250,7 @@ public function testRequestGetHttp10WithoutHostWillBeIgnored() $data = "GET / HTTP/1.0\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('GET', $requestAssertion->getMethod()); $this->assertSame('/', $requestAssertion->getRequestTarget()); $this->assertSame('/', $requestAssertion->getUri()->getPath()); @@ -282,7 +285,7 @@ public function testRequestOptionsAsterisk() $data = "OPTIONS * HTTP/1.1\r\nHost: example.com\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('OPTIONS', $requestAssertion->getMethod()); $this->assertSame('*', $requestAssertion->getRequestTarget()); $this->assertSame('', $requestAssertion->getUri()->getPath()); @@ -315,7 +318,7 @@ public function testRequestConnectAuthorityForm() $data = "CONNECT example.com:443 HTTP/1.1\r\nHost: example.com:443\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('CONNECT', $requestAssertion->getMethod()); $this->assertSame('example.com:443', $requestAssertion->getRequestTarget()); $this->assertSame('', $requestAssertion->getUri()->getPath()); @@ -337,7 +340,7 @@ public function testRequestConnectWithoutHostWillBePassesAsIs() $data = "CONNECT example.com:443 HTTP/1.1\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('CONNECT', $requestAssertion->getMethod()); $this->assertSame('example.com:443', $requestAssertion->getRequestTarget()); $this->assertSame('', $requestAssertion->getUri()->getPath()); @@ -359,7 +362,7 @@ public function testRequestConnectAuthorityFormWithDefaultPortWillBePassedAsIs() $data = "CONNECT example.com:80 HTTP/1.1\r\nHost: example.com:80\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('CONNECT', $requestAssertion->getMethod()); $this->assertSame('example.com:80', $requestAssertion->getRequestTarget()); $this->assertSame('', $requestAssertion->getUri()->getPath()); @@ -381,7 +384,7 @@ public function testRequestConnectAuthorityFormNonMatchingHostWillBePassedAsIs() $data = "CONNECT example.com:80 HTTP/1.1\r\nHost: other.example.org\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('CONNECT', $requestAssertion->getMethod()); $this->assertSame('example.com:80', $requestAssertion->getRequestTarget()); $this->assertSame('', $requestAssertion->getUri()->getPath()); @@ -433,7 +436,7 @@ public function testRequestWithoutHostEventUsesSocketAddress() $data = "GET /test HTTP/1.0\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('GET', $requestAssertion->getMethod()); $this->assertSame('/test', $requestAssertion->getRequestTarget()); $this->assertEquals('http://127.0.0.1/test', $requestAssertion->getUri()); @@ -454,7 +457,7 @@ public function testRequestAbsoluteEvent() $data = "GET http://example.com/test HTTP/1.1\r\nHost: example.com\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('GET', $requestAssertion->getMethod()); $this->assertSame('http://example.com/test', $requestAssertion->getRequestTarget()); $this->assertEquals('http://example.com/test', $requestAssertion->getUri()); @@ -476,7 +479,7 @@ public function testRequestAbsoluteNonMatchingHostWillBePassedAsIs() $data = "GET http://example.com/test HTTP/1.1\r\nHost: other.example.org\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('GET', $requestAssertion->getMethod()); $this->assertSame('http://example.com/test', $requestAssertion->getRequestTarget()); $this->assertEquals('http://example.com/test', $requestAssertion->getUri()); @@ -510,7 +513,7 @@ public function testRequestOptionsAsteriskEvent() $data = "OPTIONS * HTTP/1.1\r\nHost: example.com\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('OPTIONS', $requestAssertion->getMethod()); $this->assertSame('*', $requestAssertion->getRequestTarget()); $this->assertEquals('http://example.com', $requestAssertion->getUri()); @@ -532,7 +535,7 @@ public function testRequestOptionsAbsoluteEvent() $data = "OPTIONS http://example.com HTTP/1.1\r\nHost: example.com\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $requestAssertion); + $this->assertInstanceOf(ServerRequestInterface::class, $requestAssertion); $this->assertSame('OPTIONS', $requestAssertion->getMethod()); $this->assertSame('http://example.com', $requestAssertion->getRequestTarget()); $this->assertEquals('http://example.com', $requestAssertion->getUri()); @@ -698,12 +701,10 @@ public function testResponseContainsServerHeader() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -712,7 +713,7 @@ function ($data) use (&$buffer) { $data = $this->createGetRequest(); $this->connection->emit('data', [$data]); - $this->assertContainsString("\r\nServer: ReactPHP/1\r\n", $buffer); + $this->assertStringContainsString("\r\nServer: ReactPHP/1\r\n", $buffer); } public function testResponsePendingPromiseWillNotSendAnything() @@ -728,12 +729,10 @@ public function testResponsePendingPromiseWillNotSendAnything() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -758,12 +757,10 @@ public function testResponsePendingPromiseWillBeCancelledIfConnectionCloses() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -794,12 +791,10 @@ public function testResponseBodyStreamAlreadyClosedWillSendEmptyBodyChunkedEncod $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -829,12 +824,10 @@ public function testResponseBodyStreamEndingWillSendEmptyBodyChunkedEncoded() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -867,12 +860,10 @@ public function testResponseBodyStreamAlreadyClosedWillSendEmptyBodyPlainHttp10( $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -903,15 +894,13 @@ public function testResponseStreamWillBeClosedIfConnectionIsAlreadyClosed() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); - $this->connection = $this->getMockBuilder('React\Socket\Connection') + $this->connection = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->setMethods( [ @@ -980,12 +969,10 @@ public function testResponseUpgradeInResponseCanBeUsedToAdvertisePossibleUpgrade $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1015,12 +1002,10 @@ public function testResponseUpgradeWishInRequestCanBeIgnoredByReturningNormalRes $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1053,12 +1038,10 @@ public function testResponseUpgradeSwitchingProtocolIncludesConnectionUpgradeHea $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1091,12 +1074,10 @@ public function testResponseUpgradeSwitchingProtocolWithStreamWillPipeDataToConn $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1128,12 +1109,10 @@ public function testResponseConnectMethodStreamWillPipeDataToConnection() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1185,12 +1164,10 @@ public function testResponseContainsSameRequestProtocolVersionAndChunkedBodyForH $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1199,8 +1176,8 @@ function ($data) use (&$buffer) { $data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertContainsString("bye", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("bye", $buffer); } public function testResponseContainsSameRequestProtocolVersionAndRawBodyForHttp10() @@ -1218,12 +1195,10 @@ public function testResponseContainsSameRequestProtocolVersionAndRawBodyForHttp1 $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1232,9 +1207,9 @@ function ($data) use (&$buffer) { $data = "GET / HTTP/1.0\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.0 200 OK\r\n", $buffer); - $this->assertContainsString("\r\n\r\n", $buffer); - $this->assertContainsString("bye", $buffer); + $this->assertStringContainsString("HTTP/1.0 200 OK\r\n", $buffer); + $this->assertStringContainsString("\r\n\r\n", $buffer); + $this->assertStringContainsString("bye", $buffer); } public function testResponseContainsNoResponseBodyForHeadRequest() @@ -1251,12 +1226,10 @@ public function testResponseContainsNoResponseBodyForHeadRequest() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1265,9 +1238,9 @@ function ($data) use (&$buffer) { $data = "HEAD / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertContainsString("\r\nContent-Length: 3\r\n", $buffer); - $this->assertNotContainsString("bye", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("\r\nContent-Length: 3\r\n", $buffer); + $this->assertStringNotContainsString("bye", $buffer); } public function testResponseContainsNoResponseBodyForHeadRequestWithStreamingResponse() @@ -1287,12 +1260,10 @@ public function testResponseContainsNoResponseBodyForHeadRequestWithStreamingRes $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1301,8 +1272,8 @@ function ($data) use (&$buffer) { $data = "HEAD / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertContainsString("\r\nContent-Length: 3\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("\r\nContent-Length: 3\r\n", $buffer); } public function testResponseContainsNoResponseBodyAndNoContentLengthForNoContentStatus() @@ -1319,12 +1290,10 @@ public function testResponseContainsNoResponseBodyAndNoContentLengthForNoContent $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1333,9 +1302,9 @@ function ($data) use (&$buffer) { $data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 204 No Content\r\n", $buffer); - $this->assertNotContainsString("\r\nContent-Length: 3\r\n", $buffer); - $this->assertNotContainsString("bye", $buffer); + $this->assertStringContainsString("HTTP/1.1 204 No Content\r\n", $buffer); + $this->assertStringNotContainsString("\r\nContent-Length: 3\r\n", $buffer); + $this->assertStringNotContainsString("bye", $buffer); } public function testResponseContainsNoResponseBodyAndNoContentLengthForNoContentStatusResponseWithStreamingBody() @@ -1355,12 +1324,10 @@ public function testResponseContainsNoResponseBodyAndNoContentLengthForNoContent $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1369,8 +1336,8 @@ function ($data) use (&$buffer) { $data = "HEAD / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 204 No Content\r\n", $buffer); - $this->assertNotContainsString("\r\nContent-Length: 3\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 204 No Content\r\n", $buffer); + $this->assertStringNotContainsString("\r\nContent-Length: 3\r\n", $buffer); } public function testResponseContainsNoContentLengthHeaderForNotModifiedStatus() @@ -1387,12 +1354,10 @@ public function testResponseContainsNoContentLengthHeaderForNotModifiedStatus() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1401,8 +1366,8 @@ function ($data) use (&$buffer) { $data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 304 Not Modified\r\n", $buffer); - $this->assertNotContainsString("\r\nContent-Length: 0\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 304 Not Modified\r\n", $buffer); + $this->assertStringNotContainsString("\r\nContent-Length: 0\r\n", $buffer); } public function testResponseContainsExplicitContentLengthHeaderForNotModifiedStatus() @@ -1419,12 +1384,10 @@ public function testResponseContainsExplicitContentLengthHeaderForNotModifiedSta $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1433,8 +1396,8 @@ function ($data) use (&$buffer) { $data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 304 Not Modified\r\n", $buffer); - $this->assertContainsString("\r\nContent-Length: 3\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 304 Not Modified\r\n", $buffer); + $this->assertStringContainsString("\r\nContent-Length: 3\r\n", $buffer); } public function testResponseContainsExplicitContentLengthHeaderForHeadRequests() @@ -1451,12 +1414,10 @@ public function testResponseContainsExplicitContentLengthHeaderForHeadRequests() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1465,8 +1426,8 @@ function ($data) use (&$buffer) { $data = "HEAD / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertContainsString("\r\nContent-Length: 3\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("\r\nContent-Length: 3\r\n", $buffer); } public function testResponseContainsNoResponseBodyForNotModifiedStatus() @@ -1483,12 +1444,10 @@ public function testResponseContainsNoResponseBodyForNotModifiedStatus() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1497,9 +1456,9 @@ function ($data) use (&$buffer) { $data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 304 Not Modified\r\n", $buffer); - $this->assertContainsString("\r\nContent-Length: 3\r\n", $buffer); - $this->assertNotContainsString("bye", $buffer); + $this->assertStringContainsString("HTTP/1.1 304 Not Modified\r\n", $buffer); + $this->assertStringContainsString("\r\nContent-Length: 3\r\n", $buffer); + $this->assertStringNotContainsString("bye", $buffer); } public function testResponseContainsNoResponseBodyForNotModifiedStatusWithStreamingBody() @@ -1519,12 +1478,10 @@ public function testResponseContainsNoResponseBodyForNotModifiedStatusWithStream $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1533,8 +1490,8 @@ function ($data) use (&$buffer) { $data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 304 Not Modified\r\n", $buffer); - $this->assertContainsString("\r\nContent-Length: 3\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 304 Not Modified\r\n", $buffer); + $this->assertStringContainsString("\r\nContent-Length: 3\r\n", $buffer); } public function testRequestInvalidHttpProtocolVersionWillEmitErrorAndSendErrorResponse() @@ -1550,12 +1507,10 @@ public function testRequestInvalidHttpProtocolVersionWillEmitErrorAndSendErrorRe $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1564,11 +1519,11 @@ function ($data) use (&$buffer) { $data = "GET / HTTP/1.2\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); - $this->assertContainsString("HTTP/1.1 505 HTTP Version Not Supported\r\n", $buffer); - $this->assertContainsString("\r\n\r\n", $buffer); - $this->assertContainsString("Error 505: HTTP Version Not Supported", $buffer); + $this->assertStringContainsString("HTTP/1.1 505 HTTP Version Not Supported\r\n", $buffer); + $this->assertStringContainsString("\r\n\r\n", $buffer); + $this->assertStringContainsString("Error 505: HTTP Version Not Supported", $buffer); } public function testRequestOverflowWillEmitErrorAndSendErrorResponse() @@ -1584,12 +1539,10 @@ public function testRequestOverflowWillEmitErrorAndSendErrorResponse() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1599,10 +1552,10 @@ function ($data) use (&$buffer) { $data .= str_repeat('A', 8193 - strlen($data)) . "\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('OverflowException', $error); + $this->assertInstanceOf(\OverflowException::class, $error); - $this->assertContainsString("HTTP/1.1 431 Request Header Fields Too Large\r\n", $buffer); - $this->assertContainsString("\r\n\r\nError 431: Request Header Fields Too Large", $buffer); + $this->assertStringContainsString("HTTP/1.1 431 Request Header Fields Too Large\r\n", $buffer); + $this->assertStringContainsString("\r\n\r\nError 431: Request Header Fields Too Large", $buffer); } public function testRequestInvalidWillEmitErrorAndSendErrorResponse() @@ -1618,12 +1571,10 @@ public function testRequestInvalidWillEmitErrorAndSendErrorResponse() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -1632,10 +1583,10 @@ function ($data) use (&$buffer) { $data = "bad request\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertInstanceOf('InvalidArgumentException', $error); + $this->assertInstanceOf(\InvalidArgumentException::class, $error); - $this->assertContainsString("HTTP/1.1 400 Bad Request\r\n", $buffer); - $this->assertContainsString("\r\n\r\nError 400: Bad Request", $buffer); + $this->assertStringContainsString("HTTP/1.1 400 Bad Request\r\n", $buffer); + $this->assertStringContainsString("\r\n\r\nError 400: Bad Request", $buffer); } public function testRequestContentLengthBodyDataWillEmitDataEventOnRequestStream() @@ -1959,7 +1910,7 @@ public function testRequestZeroContentLengthWillEmitEndAndAdditionalDataWillBeIg public function testRequestInvalidChunkHeaderTooLongWillEmitErrorOnRequestStream() { - $errorEvent = $this->expectCallableOnceWith($this->isInstanceOf('Exception')); + $errorEvent = $this->expectCallableOnceWith($this->isInstanceOf(\Exception::class)); $server = new StreamingServer(Loop::get(), function ($request) use ($errorEvent){ $request->getBody()->on('error', $errorEvent); return resolve(new Response()); @@ -1984,7 +1935,7 @@ public function testRequestInvalidChunkHeaderTooLongWillEmitErrorOnRequestStream public function testRequestInvalidChunkBodyTooLongWillEmitErrorOnRequestStream() { - $errorEvent = $this->expectCallableOnceWith($this->isInstanceOf('Exception')); + $errorEvent = $this->expectCallableOnceWith($this->isInstanceOf(\Exception::class)); $server = new StreamingServer(Loop::get(), function ($request) use ($errorEvent){ $request->getBody()->on('error', $errorEvent); }); @@ -2006,7 +1957,7 @@ public function testRequestInvalidChunkBodyTooLongWillEmitErrorOnRequestStream() public function testRequestUnexpectedEndOfRequestWithChunkedTransferConnectionWillEmitErrorOnRequestStream() { - $errorEvent = $this->expectCallableOnceWith($this->isInstanceOf('Exception')); + $errorEvent = $this->expectCallableOnceWith($this->isInstanceOf(\Exception::class)); $server = new StreamingServer(Loop::get(), function ($request) use ($errorEvent){ $request->getBody()->on('error', $errorEvent); }); @@ -2029,7 +1980,7 @@ public function testRequestUnexpectedEndOfRequestWithChunkedTransferConnectionWi public function testRequestInvalidChunkHeaderWillEmitErrorOnRequestStream() { - $errorEvent = $this->expectCallableOnceWith($this->isInstanceOf('Exception')); + $errorEvent = $this->expectCallableOnceWith($this->isInstanceOf(\Exception::class)); $server = new StreamingServer(Loop::get(), function ($request) use ($errorEvent){ $request->getBody()->on('error', $errorEvent); }); @@ -2051,7 +2002,7 @@ public function testRequestInvalidChunkHeaderWillEmitErrorOnRequestStream() public function testRequestUnexpectedEndOfRequestWithContentLengthWillEmitErrorOnRequestStream() { - $errorEvent = $this->expectCallableOnceWith($this->isInstanceOf('Exception')); + $errorEvent = $this->expectCallableOnceWith($this->isInstanceOf(\Exception::class)); $server = new StreamingServer(Loop::get(), function ($request) use ($errorEvent){ $request->getBody()->on('error', $errorEvent); }); @@ -2134,12 +2085,10 @@ public function testResponseWithBodyStreamWillUseChunkedTransferEncodingByDefaul $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2150,8 +2099,8 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); $stream->emit('data', ['hello']); - $this->assertContainsString("Transfer-Encoding: chunked", $buffer); - $this->assertContainsString("hello", $buffer); + $this->assertStringContainsString("Transfer-Encoding: chunked", $buffer); + $this->assertStringContainsString("hello", $buffer); } public function testResponseWithBodyStringWillOverwriteExplicitContentLengthAndTransferEncoding() @@ -2171,12 +2120,10 @@ public function testResponseWithBodyStringWillOverwriteExplicitContentLengthAndT $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2186,14 +2133,14 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertNotContainsString("Transfer-Encoding: chunked", $buffer); - $this->assertContainsString("Content-Length: 5", $buffer); - $this->assertContainsString("hello", $buffer); + $this->assertStringNotContainsString("Transfer-Encoding: chunked", $buffer); + $this->assertStringContainsString("Content-Length: 5", $buffer); + $this->assertStringContainsString("hello", $buffer); } public function testResponseContainsResponseBodyWithTransferEncodingChunkedForBodyWithUnknownSize() { - $body = $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(); + $body = $this->createMock(StreamInterface::class); $body->expects($this->once())->method('getSize')->willReturn(null); $body->expects($this->once())->method('__toString')->willReturn('body'); @@ -2209,12 +2156,10 @@ public function testResponseContainsResponseBodyWithTransferEncodingChunkedForBo $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2223,14 +2168,14 @@ function ($data) use (&$buffer) { $data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("Transfer-Encoding: chunked", $buffer); - $this->assertNotContainsString("Content-Length:", $buffer); - $this->assertContainsString("body", $buffer); + $this->assertStringContainsString("Transfer-Encoding: chunked", $buffer); + $this->assertStringNotContainsString("Content-Length:", $buffer); + $this->assertStringContainsString("body", $buffer); } public function testResponseContainsResponseBodyWithPlainBodyWithUnknownSizeForLegacyHttp10() { - $body = $this->getMockBuilder('Psr\Http\Message\StreamInterface')->getMock(); + $body = $this->createMock(StreamInterface::class); $body->expects($this->once())->method('getSize')->willReturn(null); $body->expects($this->once())->method('__toString')->willReturn('body'); @@ -2246,12 +2191,10 @@ public function testResponseContainsResponseBodyWithPlainBodyWithUnknownSizeForL $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2260,9 +2203,9 @@ function ($data) use (&$buffer) { $data = "GET / HTTP/1.0\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', [$data]); - $this->assertNotContainsString("Transfer-Encoding: chunked", $buffer); - $this->assertNotContainsString("Content-Length:", $buffer); - $this->assertContainsString("body", $buffer); + $this->assertStringNotContainsString("Transfer-Encoding: chunked", $buffer); + $this->assertStringNotContainsString("Content-Length:", $buffer); + $this->assertStringContainsString("body", $buffer); } public function testResponseWithCustomTransferEncodingWillBeIgnoredAndUseChunkedTransferEncodingInstead() @@ -2282,12 +2225,10 @@ public function testResponseWithCustomTransferEncodingWillBeIgnoredAndUseChunked $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2298,9 +2239,9 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); $stream->emit('data', ['hello']); - $this->assertContainsString('Transfer-Encoding: chunked', $buffer); - $this->assertNotContainsString('Transfer-Encoding: custom', $buffer); - $this->assertContainsString("5\r\nhello\r\n", $buffer); + $this->assertStringContainsString('Transfer-Encoding: chunked', $buffer); + $this->assertStringNotContainsString('Transfer-Encoding: custom', $buffer); + $this->assertStringContainsString("5\r\nhello\r\n", $buffer); } public function testResponseWithoutExplicitDateHeaderWillAddCurrentDateFromClock() @@ -2321,12 +2262,10 @@ public function testResponseWithoutExplicitDateHeaderWillAddCurrentDateFromClock $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2336,9 +2275,9 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertContainsString("Date: Thu, 19 May 2022 14:54:51 GMT\r\n", $buffer); - $this->assertContainsString("\r\n\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("Date: Thu, 19 May 2022 14:54:51 GMT\r\n", $buffer); + $this->assertStringContainsString("\r\n\r\n", $buffer); } public function testResponseWithCustomDateHeaderOverwritesDefault() @@ -2354,12 +2293,10 @@ public function testResponseWithCustomDateHeaderOverwritesDefault() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2369,9 +2306,9 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertContainsString("Date: Tue, 15 Nov 1994 08:12:31 GMT\r\n", $buffer); - $this->assertContainsString("\r\n\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("Date: Tue, 15 Nov 1994 08:12:31 GMT\r\n", $buffer); + $this->assertStringContainsString("\r\n\r\n", $buffer); } public function testResponseWithEmptyDateHeaderRemovesDateHeader() @@ -2387,12 +2324,10 @@ public function testResponseWithEmptyDateHeaderRemovesDateHeader() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2402,9 +2337,9 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertNotContainsString("Date:", $buffer); - $this->assertContainsString("\r\n\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringNotContainsString("Date:", $buffer); + $this->assertStringContainsString("\r\n\r\n", $buffer); } public function testResponseCanContainMultipleCookieHeaders() @@ -2427,12 +2362,10 @@ public function testResponseCanContainMultipleCookieHeaders() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2455,12 +2388,10 @@ public function testReponseWithExpectContinueRequestContainsContinueWithLaterRes $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2473,8 +2404,8 @@ function ($data) use (&$buffer) { $data .= "\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 100 Continue\r\n", $buffer); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 100 Continue\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); } public function testResponseWithExpectContinueRequestWontSendContinueForHttp10() @@ -2487,12 +2418,10 @@ public function testResponseWithExpectContinueRequestWontSendContinueForHttp10() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2503,13 +2432,13 @@ function ($data) use (&$buffer) { $data .= "\r\n"; $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.0 200 OK\r\n", $buffer); - $this->assertNotContainsString("HTTP/1.1 100 Continue\r\n\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.0 200 OK\r\n", $buffer); + $this->assertStringNotContainsString("HTTP/1.1 100 Continue\r\n\r\n", $buffer); } public function testInvalidCallbackFunctionLeadsToException() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new StreamingServer(Loop::get(), 'invalid'); } @@ -2529,12 +2458,10 @@ public function testResponseBodyStreamWillStreamDataWithChunkedTransferEncoding( $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2546,10 +2473,10 @@ function ($data) use (&$buffer) { $input->emit('data', ['1']); $input->emit('data', ['23']); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertContainsString("\r\n\r\n", $buffer); - $this->assertContainsString("1\r\n1\r\n", $buffer); - $this->assertContainsString("2\r\n23\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("\r\n\r\n", $buffer); + $this->assertStringContainsString("1\r\n1\r\n", $buffer); + $this->assertStringContainsString("2\r\n23\r\n", $buffer); } public function testResponseBodyStreamWithContentLengthWillStreamTillLengthWithoutTransferEncoding() @@ -2568,12 +2495,10 @@ public function testResponseBodyStreamWithContentLengthWillStreamTillLengthWitho $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2585,11 +2510,11 @@ function ($data) use (&$buffer) { $input->emit('data', ['hel']); $input->emit('data', ['lo']); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertContainsString("Content-Length: 5\r\n", $buffer); - $this->assertNotContainsString("Transfer-Encoding", $buffer); - $this->assertContainsString("\r\n\r\n", $buffer); - $this->assertContainsString("hello", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("Content-Length: 5\r\n", $buffer); + $this->assertStringNotContainsString("Transfer-Encoding", $buffer); + $this->assertStringContainsString("\r\n\r\n", $buffer); + $this->assertStringContainsString("hello", $buffer); } public function testResponseWithResponsePromise() @@ -2602,12 +2527,10 @@ public function testResponseWithResponsePromise() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2616,8 +2539,8 @@ function ($data) use (&$buffer) { $data = $this->createGetRequest(); $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertContainsString("\r\n\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("\r\n\r\n", $buffer); } public function testResponseReturnInvalidTypeWillResultInError() @@ -2635,12 +2558,10 @@ public function testResponseReturnInvalidTypeWillResultInError() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2650,8 +2571,8 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertStringContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); + $this->assertInstanceOf(\RuntimeException::class, $exception); } public function testResponseResolveWrongTypeInPromiseWillResultInError() @@ -2664,12 +2585,10 @@ public function testResponseResolveWrongTypeInPromiseWillResultInError() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2679,7 +2598,7 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); } public function testResponseRejectedPromiseWillResultInErrorMessage() @@ -2695,12 +2614,10 @@ public function testResponseRejectedPromiseWillResultInErrorMessage() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2710,7 +2627,7 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); } public function testResponseExceptionInCallbackWillResultInErrorMessage() @@ -2726,12 +2643,10 @@ public function testResponseExceptionInCallbackWillResultInErrorMessage() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2741,7 +2656,7 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); } public function testResponseWithContentLengthHeaderForStringBodyOverwritesTransferEncoding() @@ -2758,12 +2673,10 @@ public function testResponseWithContentLengthHeaderForStringBodyOverwritesTransf $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2773,11 +2686,11 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); - $this->assertContainsString("Content-Length: 5\r\n", $buffer); - $this->assertContainsString("hello", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("Content-Length: 5\r\n", $buffer); + $this->assertStringContainsString("hello", $buffer); - $this->assertNotContainsString("Transfer-Encoding", $buffer); + $this->assertStringNotContainsString("Transfer-Encoding", $buffer); } public function testResponseWillBeHandled() @@ -2790,12 +2703,10 @@ public function testResponseWillBeHandled() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2805,7 +2716,7 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertStringContainsString("HTTP/1.1 200 OK\r\n", $buffer); } public function testResponseExceptionThrowInCallBackFunctionWillResultInErrorMessage() @@ -2823,12 +2734,10 @@ public function testResponseExceptionThrowInCallBackFunctionWillResultInErrorMes $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2838,8 +2747,8 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertInstanceOf('RuntimeException', $exception); - $this->assertContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); + $this->assertInstanceOf(\RuntimeException::class, $exception); + $this->assertStringContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); $this->assertEquals('hello', $exception->getPrevious()->getMessage()); } @@ -2858,12 +2767,10 @@ public function testResponseThrowableThrowInCallBackFunctionWillResultInErrorMes $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2881,8 +2788,8 @@ function ($data) use (&$buffer) { ); } - $this->assertInstanceOf('RuntimeException', $exception); - $this->assertContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); + $this->assertInstanceOf(\RuntimeException::class, $exception); + $this->assertStringContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); $this->assertEquals('hello', $exception->getPrevious()->getMessage()); } @@ -2903,12 +2810,10 @@ public function testResponseRejectOfNonExceptionWillResultInErrorMessage() $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -2918,54 +2823,52 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertStringContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); + $this->assertInstanceOf(\RuntimeException::class, $exception); } public static function provideInvalidResponse() { $response = new Response(200, [], '', '1.1', 'OK'); - return [ - [ - $response->withStatus(99, 'OK') - ], - [ - $response->withStatus(1000, 'OK') - ], - [ - $response->withStatus(200, "Invald\r\nReason: Yes") - ], - [ - $response->withHeader('Invalid', "Yes\r\n") - ], - [ - $response->withHeader('Invalid', "Yes\n") - ], - [ - $response->withHeader('Invalid', "Yes\r") - ], - [ - $response->withHeader("Inva\r\nlid", 'Yes') - ], - [ - $response->withHeader("Inva\nlid", 'Yes') - ], - [ - $response->withHeader("Inva\rlid", 'Yes') - ], - [ - $response->withHeader('Inva Lid', 'Yes') - ], - [ - $response->withHeader('Inva:Lid', 'Yes') - ], - [ - $response->withHeader('Invalid', "Val\0ue") - ], - [ - $response->withHeader("Inva\0lid", 'Yes') - ] + yield [ + $response->withStatus(99, 'OK') + ]; + yield [ + $response->withStatus(1000, 'OK') + ]; + yield [ + $response->withStatus(200, "Invald\r\nReason: Yes") + ]; + yield [ + $response->withHeader('Invalid', "Yes\r\n") + ]; + yield [ + $response->withHeader('Invalid', "Yes\n") + ]; + yield [ + $response->withHeader('Invalid', "Yes\r") + ]; + yield [ + $response->withHeader("Inva\r\nlid", 'Yes') + ]; + yield [ + $response->withHeader("Inva\nlid", 'Yes') + ]; + yield [ + $response->withHeader("Inva\rlid", 'Yes') + ]; + yield [ + $response->withHeader('Inva Lid', 'Yes') + ]; + yield [ + $response->withHeader('Inva:Lid', 'Yes') + ]; + yield [ + $response->withHeader('Invalid', "Val\0ue") + ]; + yield [ + $response->withHeader("Inva\0lid", 'Yes') ]; } @@ -2988,12 +2891,10 @@ public function testInvalidResponseObjectWillResultInErrorMessage(ResponseInterf $this->connection ->expects($this->any()) ->method('write') - ->will( - $this->returnCallback( - function ($data) use (&$buffer) { - $buffer .= $data; - } - ) + ->willReturnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } ); $server->listen($this->socket); @@ -3003,8 +2904,8 @@ function ($data) use (&$buffer) { $this->connection->emit('data', [$data]); - $this->assertContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); - $this->assertInstanceOf('InvalidArgumentException', $exception); + $this->assertStringContainsString("HTTP/1.1 500 Internal Server Error\r\n", $buffer); + $this->assertInstanceOf(\InvalidArgumentException::class, $exception); } public function testRequestServerRequestParams() @@ -3147,7 +3048,7 @@ public function testNewConnectionWillInvokeParserOnce() { $server = new StreamingServer(Loop::get(), $this->expectCallableNever()); - $parser = $this->getMockBuilder('React\Http\Io\RequestHeaderParser')->disableOriginalConstructor()->getMock(); + $parser = $this->createMock(RequestHeaderParser::class); $parser->expects($this->once())->method('handle'); $ref = new \ReflectionProperty($server, 'parser'); @@ -3164,7 +3065,7 @@ public function testNewConnectionWillInvokeParserOnceAndInvokeRequestHandlerWhen $server = new StreamingServer(Loop::get(), $this->expectCallableOnceWith($request)); - $parser = $this->getMockBuilder('React\Http\Io\RequestHeaderParser')->disableOriginalConstructor()->getMock(); + $parser = $this->createMock(RequestHeaderParser::class); $parser->expects($this->once())->method('handle'); $ref = new \ReflectionProperty($server, 'parser'); @@ -3187,7 +3088,7 @@ public function testNewConnectionWillInvokeParserOnceAndInvokeRequestHandlerWhen $server = new StreamingServer(Loop::get(), $this->expectCallableOnceWith($request)); - $parser = $this->getMockBuilder('React\Http\Io\RequestHeaderParser')->disableOriginalConstructor()->getMock(); + $parser = $this->createMock(RequestHeaderParser::class); $parser->expects($this->once())->method('handle'); $ref = new \ReflectionProperty($server, 'parser'); @@ -3212,7 +3113,7 @@ public function testNewConnectionWillInvokeParserOnceAndInvokeRequestHandlerWhen return new Response(200, ['Connection' => 'close']); }); - $parser = $this->getMockBuilder('React\Http\Io\RequestHeaderParser')->disableOriginalConstructor()->getMock(); + $parser = $this->createMock(RequestHeaderParser::class); $parser->expects($this->once())->method('handle'); $ref = new \ReflectionProperty($server, 'parser'); @@ -3237,7 +3138,7 @@ public function testNewConnectionWillInvokeParserTwiceAfterInvokingRequestHandle return new Response(); }); - $parser = $this->getMockBuilder('React\Http\Io\RequestHeaderParser')->disableOriginalConstructor()->getMock(); + $parser = $this->createMock(RequestHeaderParser::class); $parser->expects($this->exactly(2))->method('handle'); $ref = new \ReflectionProperty($server, 'parser'); @@ -3262,7 +3163,7 @@ public function testNewConnectionWillInvokeParserTwiceAfterInvokingRequestHandle return new Response(); }); - $parser = $this->getMockBuilder('React\Http\Io\RequestHeaderParser')->disableOriginalConstructor()->getMock(); + $parser = $this->createMock(RequestHeaderParser::class); $parser->expects($this->exactly(2))->method('handle'); $ref = new \ReflectionProperty($server, 'parser'); @@ -3288,7 +3189,7 @@ public function testNewConnectionWillInvokeParserOnceAfterInvokingRequestHandler return new Response(200, [], $body); }); - $parser = $this->getMockBuilder('React\Http\Io\RequestHeaderParser')->disableOriginalConstructor()->getMock(); + $parser = $this->createMock(RequestHeaderParser::class); $parser->expects($this->once())->method('handle'); $ref = new \ReflectionProperty($server, 'parser'); @@ -3314,7 +3215,7 @@ public function testNewConnectionWillInvokeParserTwiceAfterInvokingRequestHandle return new Response(200, [], $body); }); - $parser = $this->getMockBuilder('React\Http\Io\RequestHeaderParser')->disableOriginalConstructor()->getMock(); + $parser = $this->createMock(RequestHeaderParser::class); $parser->expects($this->exactly(2))->method('handle'); $ref = new \ReflectionProperty($server, 'parser'); diff --git a/tests/Io/TransactionTest.php b/tests/Io/TransactionTest.php index b4825024..3833cfd3 100644 --- a/tests/Io/TransactionTest.php +++ b/tests/Io/TransactionTest.php @@ -5,7 +5,10 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use React\EventLoop\LoopInterface; +use React\EventLoop\TimerInterface; use React\Http\Io\ReadableBodyStream; +use React\Http\Io\Sender; use React\Http\Io\Transaction; use React\Http\Message\Request; use React\Http\Message\Response; @@ -13,6 +16,8 @@ use React\EventLoop\Loop; use React\Promise\Deferred; use React\Promise\Promise; +use React\Promise\PromiseInterface; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; use React\Tests\Http\TestCase; use function React\Async\await; @@ -24,12 +29,12 @@ class TransactionTest extends TestCase public function testWithOptionsReturnsNewInstanceWithChangedOption() { $sender = $this->makeSenderMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $transaction = new Transaction($sender, $loop); $new = $transaction->withOptions(['followRedirects' => false]); - $this->assertInstanceOf('React\Http\Io\Transaction', $new); + $this->assertInstanceOf(Transaction::class, $new); $this->assertNotSame($transaction, $new); $ref = new \ReflectionProperty($new, 'followRedirects'); @@ -41,7 +46,7 @@ public function testWithOptionsReturnsNewInstanceWithChangedOption() public function testWithOptionsDoesNotChangeOriginalInstance() { $sender = $this->makeSenderMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $transaction = new Transaction($sender, $loop); $transaction->withOptions(['followRedirects' => false]); @@ -55,7 +60,7 @@ public function testWithOptionsDoesNotChangeOriginalInstance() public function testWithOptionsNullValueReturnsNewInstanceWithDefaultOption() { $sender = $this->makeSenderMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['followRedirects' => false]); @@ -69,34 +74,34 @@ public function testWithOptionsNullValueReturnsNewInstanceWithDefaultOption() public function testTimeoutExplicitOptionWillStartTimeoutTimer() { - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->with(2, $this->anything())->willReturn($timer); $loop->expects($this->never())->method('cancelTimer'); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(new Promise(function () { })); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn(new Promise(function () { })); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 2]); $promise = $transaction->send($request); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); } public function testTimeoutImplicitFromIniWillStartTimeoutTimer() { - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->with(2, $this->anything())->willReturn($timer); $loop->expects($this->never())->method('cancelTimer'); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(new Promise(function () { })); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn(new Promise(function () { })); $transaction = new Transaction($sender, $loop); @@ -105,24 +110,24 @@ public function testTimeoutImplicitFromIniWillStartTimeoutTimer() $promise = $transaction->send($request); ini_set('default_socket_timeout', $old); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); } public function testTimeoutExplicitOptionWillRejectWhenTimerFires() { $timeout = null; - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->with(2, $this->callback(function ($cb) use (&$timeout) { $timeout = $cb; return true; }))->willReturn($timer); $loop->expects($this->never())->method('cancelTimer'); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(new Promise(function () { })); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn(new Promise(function () { })); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 2]); @@ -136,42 +141,42 @@ public function testTimeoutExplicitOptionWillRejectWhenTimerFires() $exception = $e; }); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); $this->assertEquals('Request timed out after 2 seconds', $exception->getMessage()); } public function testTimeoutExplicitOptionWillNotStartTimeoutWhenSenderResolvesImmediately() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->never())->method('addTimer'); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); $response = new Response(200, [], ''); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(resolve($response)); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn(resolve($response)); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 0.001]); $promise = $transaction->send($request); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); $promise->then($this->expectCallableOnceWith($response)); } public function testTimeoutExplicitOptionWillCancelTimeoutTimerWhenSenderResolvesLaterOn() { - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->willReturn($timer); $loop->expects($this->once())->method('cancelTimer')->with($timer); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); $response = new Response(200, [], ''); $deferred = new Deferred(); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn($deferred->promise()); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn($deferred->promise()); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 0.001]); @@ -179,41 +184,41 @@ public function testTimeoutExplicitOptionWillCancelTimeoutTimerWhenSenderResolve $deferred->resolve($response); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); $promise->then($this->expectCallableOnceWith($response)); } public function testTimeoutExplicitOptionWillNotStartTimeoutWhenSenderRejectsImmediately() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->never())->method('addTimer'); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); $exception = new \RuntimeException(); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(reject($exception)); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn(reject($exception)); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 0.001]); $promise = $transaction->send($request); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); $promise->then(null, $this->expectCallableOnceWith($exception)); } public function testTimeoutExplicitOptionWillCancelTimeoutTimerWhenSenderRejectsLaterOn() { - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->willReturn($timer); $loop->expects($this->once())->method('cancelTimer')->with($timer); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); $deferred = new Deferred(); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn($deferred->promise()); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn($deferred->promise()); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 0.001]); @@ -222,49 +227,49 @@ public function testTimeoutExplicitOptionWillCancelTimeoutTimerWhenSenderRejects $exception = new \RuntimeException(); $deferred->reject($exception); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); $promise->then(null, $this->expectCallableOnceWith($exception)); } public function testTimeoutExplicitNegativeWillNotStartTimeoutTimer() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->never())->method('addTimer'); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(new Promise(function () { })); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn(new Promise(function () { })); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => -1]); $promise = $transaction->send($request); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); } public function testTimeoutExplicitOptionWillNotStartTimeoutTimerWhenRequestBodyIsStreaming() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->never())->method('addTimer'); $stream = new ThroughStream(); $request = new Request('POST', 'http://example.com', [], new ReadableBodyStream($stream)); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(new Promise(function () { })); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn(new Promise(function () { })); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 2]); $promise = $transaction->send($request); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); } public function testTimeoutExplicitOptionWillStartTimeoutTimerWhenStreamingRequestBodyIsAlreadyClosed() { - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->with(2, $this->anything())->willReturn($timer); $loop->expects($this->never())->method('cancelTimer'); @@ -272,28 +277,28 @@ public function testTimeoutExplicitOptionWillStartTimeoutTimerWhenStreamingReque $stream->close(); $request = new Request('POST', 'http://example.com', [], new ReadableBodyStream($stream)); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(new Promise(function () { })); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn(new Promise(function () { })); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 2]); $promise = $transaction->send($request); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); } public function testTimeoutExplicitOptionWillStartTimeoutTimerWhenStreamingRequestBodyClosesWhileSenderIsStillPending() { - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->with(2, $this->anything())->willReturn($timer); $loop->expects($this->never())->method('cancelTimer'); $stream = new ThroughStream(); $request = new Request('POST', 'http://example.com', [], new ReadableBodyStream($stream)); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(new Promise(function () { })); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn(new Promise(function () { })); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 2]); @@ -301,20 +306,20 @@ public function testTimeoutExplicitOptionWillStartTimeoutTimerWhenStreamingReque $stream->close(); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); } public function testTimeoutExplicitOptionWillNotStartTimeoutTimerWhenStreamingRequestBodyClosesAfterSenderRejects() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->never())->method('addTimer'); $stream = new ThroughStream(); $request = new Request('POST', 'http://example.com', [], new ReadableBodyStream($stream)); $deferred = new Deferred(); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn($deferred->promise()); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn($deferred->promise()); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 2]); @@ -323,7 +328,7 @@ public function testTimeoutExplicitOptionWillNotStartTimeoutTimerWhenStreamingRe $deferred->reject(new \RuntimeException('Request failed')); $stream->close(); - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); + $this->assertInstanceOf(PromiseInterface::class, $promise); $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection } @@ -331,8 +336,8 @@ public function testTimeoutExplicitOptionWillNotStartTimeoutTimerWhenStreamingRe public function testTimeoutExplicitOptionWillRejectWhenTimerFiresAfterStreamingRequestBodyCloses() { $timeout = null; - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->with(2, $this->callback(function ($cb) use (&$timeout) { $timeout = $cb; return true; @@ -342,8 +347,8 @@ public function testTimeoutExplicitOptionWillRejectWhenTimerFiresAfterStreamingR $stream = new ThroughStream(); $request = new Request('POST', 'http://example.com', [], new ReadableBodyStream($stream)); - $sender = $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(new Promise(function () { })); + $sender = $this->createMock(Sender::class); + $sender->expects($this->once())->method('send')->with($request)->willReturn(new Promise(function () { })); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => 2]); @@ -359,19 +364,19 @@ public function testTimeoutExplicitOptionWillRejectWhenTimerFiresAfterStreamingR $exception = $e; }); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); $this->assertEquals('Request timed out after 2 seconds', $exception->getMessage()); } public function testReceivingErrorResponseWillRejectWithResponseException() { - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); $response = new Response(404); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); // mock sender to resolve promise with the given $response in response to the given $request $sender = $this->makeSenderMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(resolve($response)); + $sender->expects($this->once())->method('send')->with($request)->willReturn(resolve($response)); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['timeout' => -1]); @@ -395,12 +400,12 @@ public function testReceivingStreamingBodyWillResolveWithBufferedResponseByDefau $stream->close(); }); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); $response = new Response(200, [], new ReadableBodyStream($stream)); // mock sender to resolve promise with the given $response in response to the given $request $sender = $this->makeSenderMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(resolve($response)); + $sender->expects($this->once())->method('send')->with($request)->willReturn(resolve($response)); $transaction = new Transaction($sender, Loop::get()); $promise = $transaction->send($request); @@ -416,13 +421,13 @@ public function testReceivingStreamingBodyWithContentLengthExceedingMaximumRespo $stream = new ThroughStream(); $stream->on('close', $this->expectCallableOnce()); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); $response = new Response(200, ['Content-Length' => '100000000'], new ReadableBodyStream($stream, 100000000)); // mock sender to resolve promise with the given $response in response to the given $request $sender = $this->makeSenderMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(resolve($response)); + $sender->expects($this->once())->method('send')->with($request)->willReturn(resolve($response)); $transaction = new Transaction($sender, Loop::get()); @@ -436,7 +441,7 @@ public function testReceivingStreamingBodyWithContentLengthExceedingMaximumRespo $this->assertFalse($stream->isWritable()); assert($exception instanceof \OverflowException); - $this->assertInstanceOf('OverflowException', $exception); + $this->assertInstanceOf(\OverflowException::class, $exception); $this->assertEquals('Response body size of 100000000 bytes exceeds maximum of 16777216 bytes', $exception->getMessage()); $this->assertEquals(defined('SOCKET_EMSGSIZE') ? \SOCKET_EMSGSIZE : 90, $exception->getCode()); $this->assertNull($exception->getPrevious()); @@ -447,13 +452,13 @@ public function testReceivingStreamingBodyWithContentsExceedingMaximumResponseBu $stream = new ThroughStream(); $stream->on('close', $this->expectCallableOnce()); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); $response = new Response(200, [], new ReadableBodyStream($stream)); // mock sender to resolve promise with the given $response in response to the given $request $sender = $this->makeSenderMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(resolve($response)); + $sender->expects($this->once())->method('send')->with($request)->willReturn(resolve($response)); $transaction = new Transaction($sender, Loop::get()); $transaction = $transaction->withOptions(['maximumSize' => 10]); @@ -469,7 +474,7 @@ public function testReceivingStreamingBodyWithContentsExceedingMaximumResponseBu $this->assertFalse($stream->isWritable()); assert($exception instanceof \OverflowException); - $this->assertInstanceOf('OverflowException', $exception); + $this->assertInstanceOf(\OverflowException::class, $exception); $this->assertEquals('Response body size exceeds maximum of 10 bytes', $exception->getMessage()); $this->assertEquals(defined('SOCKET_EMSGSIZE') ? \SOCKET_EMSGSIZE : 90, $exception->getCode()); $this->assertNull($exception->getPrevious()); @@ -481,12 +486,12 @@ public function testReceivingStreamingBodyWillRejectWhenStreamEmitsError() throw new \UnexpectedValueException('Unexpected ' . $data, 42); }); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); $response = new Response(200, [], new ReadableBodyStream($stream)); // mock sender to resolve promise with the given $response in response to the given $request $sender = $this->makeSenderMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(resolve($response)); + $sender->expects($this->once())->method('send')->with($request)->willReturn(resolve($response)); $transaction = new Transaction($sender, Loop::get()); $promise = $transaction->send($request); @@ -501,25 +506,25 @@ public function testReceivingStreamingBodyWillRejectWhenStreamEmitsError() $this->assertFalse($stream->isWritable()); assert($exception instanceof \RuntimeException); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); $this->assertEquals('Error while buffering response body: Unexpected Foo', $exception->getMessage()); $this->assertEquals(42, $exception->getCode()); - $this->assertInstanceOf('UnexpectedValueException', $exception->getPrevious()); + $this->assertInstanceOf(\UnexpectedValueException::class, $exception->getPrevious()); } public function testCancelBufferingResponseWillCloseStreamAndReject() { - $stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); + $stream = $this->createMock(ReadableStreamInterface::class); $stream->expects($this->any())->method('isReadable')->willReturn(true); $stream->expects($this->once())->method('close'); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); + $request = $this->createMock(RequestInterface::class); $response = new Response(200, [], new ReadableBodyStream($stream)); // mock sender to resolve promise with the given $response in response to the given $request $deferred = new Deferred(); $sender = $this->makeSenderMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn($deferred->promise()); + $sender->expects($this->once())->method('send')->with($request)->willReturn($deferred->promise()); $transaction = new Transaction($sender, Loop::get()); $promise = $transaction->send($request); @@ -533,7 +538,7 @@ public function testCancelBufferingResponseWillCloseStreamAndReject() }); assert($exception instanceof \RuntimeException); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); $this->assertEquals('Cancelled buffering response body', $exception->getMessage()); $this->assertEquals(0, $exception->getCode()); $this->assertNull($exception->getPrevious()); @@ -541,14 +546,14 @@ public function testCancelBufferingResponseWillCloseStreamAndReject() public function testReceivingStreamingBodyWillResolveWithStreamingResponseIfStreamingIsEnabled() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); - $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); - $response = new Response(200, [], new ReadableBodyStream($this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock())); + $request = $this->createMock(RequestInterface::class); + $response = new Response(200, [], new ReadableBodyStream($this->createMock(ReadableStreamInterface::class))); // mock sender to resolve promise with the given $response in response to the given $request $sender = $this->makeSenderMock(); - $sender->expects($this->once())->method('send')->with($this->equalTo($request))->willReturn(resolve($response)); + $sender->expects($this->once())->method('send')->with($request)->willReturn(resolve($response)); $transaction = new Transaction($sender, $loop); $transaction = $transaction->withOptions(['streaming' => true, 'timeout' => -1]); @@ -566,7 +571,7 @@ public function testReceivingStreamingBodyWillResolveWithStreamingResponseIfStre public function testResponseCode304WithoutLocationWillResolveWithResponseAsIs() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); // conditional GET request will respond with 304 (Not Modified $request = new Request('GET', 'http://example.com', ['If-None-Match' => '"abc"']); @@ -583,7 +588,7 @@ public function testResponseCode304WithoutLocationWillResolveWithResponseAsIs() public function testCustomRedirectResponseCode333WillFollowLocationHeaderAndSendRedirectedRequest() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); // original GET request will respond with custom 333 redirect status code and follow location header $requestOriginal = new Request('GET', 'http://example.com'); @@ -605,7 +610,7 @@ public function testCustomRedirectResponseCode333WillFollowLocationHeaderAndSend public function testFollowingRedirectWithSpecifiedHeaders() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $customHeaders = ['User-Agent' => 'Chrome']; $requestWithUserAgent = new Request('GET', 'http://example.com', $customHeaders); @@ -635,7 +640,7 @@ public function testFollowingRedirectWithSpecifiedHeaders() public function testRemovingAuthorizationHeaderWhenChangingHostnamesDuringRedirect() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $customHeaders = ['Authorization' => 'secret']; $requestWithAuthorization = new Request('GET', 'http://example.com', $customHeaders); @@ -665,7 +670,7 @@ public function testRemovingAuthorizationHeaderWhenChangingHostnamesDuringRedire public function testAuthorizationHeaderIsForwardedWhenRedirectingToSameDomain() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $customHeaders = ['Authorization' => 'secret']; $requestWithAuthorization = new Request('GET', 'http://example.com', $customHeaders); @@ -695,7 +700,7 @@ public function testAuthorizationHeaderIsForwardedWhenRedirectingToSameDomain() public function testAuthorizationHeaderIsForwardedWhenLocationContainsAuthentication() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $request = new Request('GET', 'http://example.com'); $sender = $this->makeSenderMock(); @@ -725,7 +730,7 @@ public function testAuthorizationHeaderIsForwardedWhenLocationContainsAuthentica public function testSomeRequestHeadersShouldBeRemovedWhenRedirecting() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $customHeaders = [ 'Content-Type' => 'text/html; charset=utf-8', @@ -760,7 +765,7 @@ public function testSomeRequestHeadersShouldBeRemovedWhenRedirecting() public function testRequestMethodShouldBeChangedWhenRedirectingWithSeeOther() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $customHeaders = [ 'Content-Type' => 'text/html; charset=utf-8', @@ -796,7 +801,7 @@ public function testRequestMethodShouldBeChangedWhenRedirectingWithSeeOther() public function testRequestMethodAndBodyShouldNotBeChangedWhenRedirectingWith307Or308() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $customHeaders = [ 'Content-Type' => 'text/html; charset=utf-8', @@ -839,7 +844,7 @@ public function testRequestMethodAndBodyShouldNotBeChangedWhenRedirectingWith307 public function testRedirectingStreamingBodyWith307Or308ShouldThrowCantRedirectStreamException() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $customHeaders = [ 'Content-Type' => 'text/html; charset=utf-8', @@ -874,7 +879,7 @@ public function testRedirectingStreamingBodyWith307Or308ShouldThrowCantRedirectS public function testCancelTransactionWillCancelRequest() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $request = new Request('GET', 'http://example.com'); $sender = $this->makeSenderMock(); @@ -892,8 +897,8 @@ public function testCancelTransactionWillCancelRequest() public function testCancelTransactionWillCancelTimeoutTimer() { - $timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock(); - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $timer = $this->createMock(TimerInterface::class); + $loop = $this->createMock(LoopInterface::class); $loop->expects($this->once())->method('addTimer')->willReturn($timer); $loop->expects($this->once())->method('cancelTimer')->with($timer); @@ -914,7 +919,7 @@ public function testCancelTransactionWillCancelTimeoutTimer() public function testCancelTransactionWillCancelRedirectedRequest() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $request = new Request('GET', 'http://example.com'); $sender = $this->makeSenderMock(); @@ -941,7 +946,7 @@ public function testCancelTransactionWillCancelRedirectedRequest() public function testCancelTransactionWillCancelRedirectedRequestAgain() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $request = new Request('GET', 'http://example.com'); $sender = $this->makeSenderMock(); @@ -971,7 +976,7 @@ public function testCancelTransactionWillCancelRedirectedRequestAgain() public function testCancelTransactionWillCloseBufferingStream() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $request = new Request('GET', 'http://example.com'); $sender = $this->makeSenderMock(); @@ -994,7 +999,7 @@ public function testCancelTransactionWillCloseBufferingStream() public function testCancelTransactionWillCloseBufferingStreamAgain() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $request = new Request('GET', 'http://example.com'); $sender = $this->makeSenderMock(); @@ -1015,7 +1020,7 @@ public function testCancelTransactionWillCloseBufferingStreamAgain() public function testCancelTransactionShouldCancelSendingPromise() { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $loop = $this->createMock(LoopInterface::class); $request = new Request('GET', 'http://example.com'); $sender = $this->makeSenderMock(); @@ -1045,6 +1050,6 @@ public function testCancelTransactionShouldCancelSendingPromise() */ private function makeSenderMock() { - return $this->getMockBuilder('React\Http\Io\Sender')->disableOriginalConstructor()->getMock(); + return $this->createMock(Sender::class); } } diff --git a/tests/Io/UploadedFileTest.php b/tests/Io/UploadedFileTest.php index adbed51c..529b75af 100644 --- a/tests/Io/UploadedFileTest.php +++ b/tests/Io/UploadedFileTest.php @@ -8,14 +8,12 @@ class UploadedFileTest extends TestCase { - public function failtyErrorProvider() + public static function failtyErrorProvider() { - return [ - ['a'], - [null], - [-1], - [9] - ]; + yield ['a']; + yield [null]; + yield [-1]; + yield [9]; } /** @@ -25,7 +23,8 @@ public function testFailtyError($error) { $stream = new BufferedBody(''); - $this->setExpectedException('InvalidArgumentException', 'Invalid error code, must be an UPLOAD_ERR_* constant'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid error code, must be an UPLOAD_ERR_* constant'); new UploadedFile($stream, 0, $error, 'foo.bar', 'foo/bar'); } @@ -34,7 +33,8 @@ public function testNoMoveFile() $stream = new BufferedBody(''); $uploadedFile = new UploadedFile($stream, 0, UPLOAD_ERR_OK, 'foo.bar', 'foo/bar'); - $this->setExpectedException('RuntimeException', 'Not implemented'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Not implemented'); $uploadedFile->moveTo('bar.foo'); } @@ -54,7 +54,8 @@ public function testGetStreamOnFailedUpload() $stream = new BufferedBody(''); $uploadedFile = new UploadedFile($stream, 0, UPLOAD_ERR_NO_FILE, 'foo.bar', 'foo/bar'); - $this->setExpectedException('RuntimeException', 'Cannot retrieve stream due to upload error'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Cannot retrieve stream due to upload error'); $uploadedFile->getStream(); } } diff --git a/tests/Message/RequestTest.php b/tests/Message/RequestTest.php index 543ddb88..148536a0 100644 --- a/tests/Message/RequestTest.php +++ b/tests/Message/RequestTest.php @@ -2,8 +2,10 @@ namespace React\Tests\Http\Message; +use Psr\Http\Message\StreamInterface; use React\Http\Io\HttpBodyStream; use React\Http\Message\Request; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; use React\Tests\Http\TestCase; @@ -33,8 +35,8 @@ public function testConstructWithStreamingRequestBodyReturnsBodyWhichImplementsR ); $body = $request->getBody(); - $this->assertInstanceOf('Psr\Http\Message\StreamInterface', $body); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(StreamInterface::class, $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); $this->assertNull($body->getSize()); } @@ -52,7 +54,8 @@ public function testConstructWithHttpBodyStreamReturnsBodyAsIs() public function testConstructWithNullBodyThrows() { - $this->setExpectedException('InvalidArgumentException', 'Invalid request body given'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid request body given'); new Request( 'GET', 'http://localhost', diff --git a/tests/Message/ResponseTest.php b/tests/Message/ResponseTest.php index 61acf19e..6d4acb73 100644 --- a/tests/Message/ResponseTest.php +++ b/tests/Message/ResponseTest.php @@ -2,8 +2,10 @@ namespace React\Tests\Http\Message; +use Psr\Http\Message\StreamInterface; use React\Http\Io\HttpBodyStream; use React\Http\Message\Response; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; use React\Tests\Http\TestCase; @@ -15,7 +17,7 @@ public function testConstructWithStringBodyWillReturnStreamInstance() $body = $response->getBody(); /** @var \Psr\Http\Message\StreamInterface $body */ - $this->assertInstanceOf('Psr\Http\Message\StreamInterface', $body); + $this->assertInstanceOf(StreamInterface::class, $body); $this->assertEquals('hello', (string) $body); } @@ -25,9 +27,9 @@ public function testConstructWithStreamingBodyWillReturnReadableBodyStream() $body = $response->getBody(); /** @var \Psr\Http\Message\StreamInterface $body */ - $this->assertInstanceOf('Psr\Http\Message\StreamInterface', $body); - $this->assertInstanceof('React\Stream\ReadableStreamInterface', $body); - $this->assertInstanceOf('React\Http\Io\HttpBodyStream', $body); + $this->assertInstanceOf(StreamInterface::class, $body); + $this->assertInstanceof(ReadableStreamInterface::class, $body); + $this->assertInstanceOf(HttpBodyStream::class, $body); $this->assertNull($body->getSize()); } @@ -44,13 +46,13 @@ public function testConstructWithHttpBodyStreamReturnsBodyAsIs() public function testFloatBodyWillThrow() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new Response(200, [], 1.0); } public function testResourceBodyWillThrow() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new Response(200, [], tmpfile()); } @@ -126,7 +128,8 @@ public function testJsonMethodReturnsJsonTextForSimpleString() public function testJsonMethodThrowsForInvalidString() { - $this->setExpectedException('InvalidArgumentException', 'Unable to encode given data as JSON: Malformed UTF-8 characters, possibly incorrectly encoded'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unable to encode given data as JSON: Malformed UTF-8 characters, possibly incorrectly encoded'); Response::json("Hello w\xF6rld!"); } @@ -220,25 +223,25 @@ public function testParseMessageWithHttp10SimpleOkResponseWithLegacyNewlines() public function testParseMessageWithInvalidHttpProtocolVersion12Throws() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); Response::parseMessage("HTTP/1.2 200 OK\r\n"); } public function testParseMessageWithInvalidHttpProtocolVersion2Throws() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); Response::parseMessage("HTTP/2 200 OK\r\n"); } public function testParseMessageWithInvalidStatusCodeUnderflowThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); Response::parseMessage("HTTP/1.1 99 OK\r\n"); } public function testParseMessageWithInvalidResponseHeaderFieldThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); Response::parseMessage("HTTP/1.1 200 OK\r\nServer\r\n"); } } diff --git a/tests/Message/ServerRequestTest.php b/tests/Message/ServerRequestTest.php index 36d20bfa..596ebf47 100644 --- a/tests/Message/ServerRequestTest.php +++ b/tests/Message/ServerRequestTest.php @@ -2,8 +2,10 @@ namespace React\Tests\Http\Message; +use Psr\Http\Message\StreamInterface; use React\Http\Io\HttpBodyStream; use React\Http\Message\ServerRequest; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; use React\Tests\Http\TestCase; @@ -302,8 +304,8 @@ public function testConstructWithStreamingRequestBodyReturnsBodyWhichImplementsR ); $body = $request->getBody(); - $this->assertInstanceOf('Psr\Http\Message\StreamInterface', $body); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(StreamInterface::class, $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); $this->assertSame(0, $body->getSize()); } @@ -319,8 +321,8 @@ public function testConstructWithStreamingRequestBodyReturnsBodyWithSizeFromCont ); $body = $request->getBody(); - $this->assertInstanceOf('Psr\Http\Message\StreamInterface', $body); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(StreamInterface::class, $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); $this->assertSame(100, $body->getSize()); } @@ -336,14 +338,14 @@ public function testConstructWithStreamingRequestBodyReturnsBodyWithSizeUnknownF ); $body = $request->getBody(); - $this->assertInstanceOf('Psr\Http\Message\StreamInterface', $body); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); + $this->assertInstanceOf(StreamInterface::class, $body); + $this->assertInstanceOf(ReadableStreamInterface::class, $body); $this->assertNull($body->getSize()); } public function testConstructWithFloatRequestBodyThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new ServerRequest( 'GET', 'http://localhost', @@ -354,7 +356,7 @@ public function testConstructWithFloatRequestBodyThrows() public function testConstructWithResourceRequestBodyThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new ServerRequest( 'GET', 'http://localhost', @@ -403,85 +405,85 @@ public function testParseMessageWithConnectMethodWithAuthorityFormRequestTarget( public function testParseMessageWithInvalidHttp11RequestWithoutHostThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / HTTP/1.1\r\n", []); } public function testParseMessageWithInvalidHttpProtocolVersionThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / HTTP/1.2\r\n", []); } public function testParseMessageWithInvalidProtocolThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / CUSTOM/1.1\r\n", []); } public function testParseMessageWithInvalidHostHeaderWithoutValueThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / HTTP/1.1\r\nHost\r\n", []); } public function testParseMessageWithInvalidHostHeaderSyntaxThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / HTTP/1.1\r\nHost: ///\r\n", []); } public function testParseMessageWithInvalidHostHeaderWithSchemeThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / HTTP/1.1\r\nHost: http://localhost\r\n", []); } public function testParseMessageWithInvalidHostHeaderWithQueryThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / HTTP/1.1\r\nHost: localhost?foo\r\n", []); } public function testParseMessageWithInvalidHostHeaderWithFragmentThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / HTTP/1.1\r\nHost: localhost#foo\r\n", []); } public function testParseMessageWithInvalidContentLengthHeaderThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length:\r\n", []); } public function testParseMessageWithInvalidTransferEncodingHeaderThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / HTTP/1.1\r\nHost: localhost\r\nTransfer-Encoding:\r\n", []); } public function testParseMessageWithInvalidBothContentLengthHeaderAndTransferEncodingHeaderThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 0\r\nTransfer-Encoding: chunked\r\n", []); } public function testParseMessageWithInvalidEmptyHostHeaderWithAbsoluteFormRequestTargetThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET http://example.com/ HTTP/1.1\r\nHost: \r\n", []); } public function testParseMessageWithInvalidConnectMethodNotUsingAuthorityFormThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("CONNECT / HTTP/1.1\r\nHost: localhost\r\n", []); } public function testParseMessageWithInvalidRequestTargetAsteriskFormThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); ServerRequest::parseMessage("GET * HTTP/1.1\r\nHost: localhost\r\n", []); } } diff --git a/tests/Message/UriTest.php b/tests/Message/UriTest.php index cdbc5a87..adaee94b 100644 --- a/tests/Message/UriTest.php +++ b/tests/Message/UriTest.php @@ -9,118 +9,116 @@ class UriTest extends TestCase { public function testCtorWithInvalidSyntaxThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new Uri('///'); } public function testCtorWithInvalidSchemeThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new Uri('not+a+scheme://localhost'); } public function testCtorWithInvalidHostThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new Uri('http://not a host/'); } public function testCtorWithInvalidPortThrows() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new Uri('http://localhost:80000/'); } public static function provideValidUris() { - return [ - [ - 'http://localhost' - ], - [ - 'http://localhost/' - ], - [ - 'http://localhost:8080/' - ], - [ - 'http://127.0.0.1/' - ], - [ - 'http://[::1]:8080/' - ], - [ - 'http://localhost/path' - ], - [ - 'http://localhost/sub/path' - ], - [ - 'http://localhost/with%20space' - ], - [ - 'http://localhost/with%2fslash' - ], - [ - 'http://localhost/?name=Alice' - ], - [ - 'http://localhost/?name=John+Doe' - ], - [ - 'http://localhost/?name=John%20Doe' - ], - [ - 'http://localhost/?name=Alice&age=42' - ], - [ - 'http://localhost/?name=Alice&' - ], - [ - 'http://localhost/?choice=A%26B' - ], - [ - 'http://localhost/?safe=Yes!?' - ], - [ - 'http://localhost/?alias=@home' - ], - [ - 'http://localhost/?assign:=true' - ], - [ - 'http://localhost/?name=' - ], - [ - 'http://localhost/?name' - ], - [ - '' - ], - [ - '/' - ], - [ - '/path' - ], - [ - 'path' - ], - [ - 'http://user@localhost/' - ], - [ - 'http://user:@localhost/' - ], - [ - 'http://:pass@localhost/' - ], - [ - 'http://user:pass@localhost/path?query#fragment' - ], - [ - 'http://user%20name:pass%20word@localhost/path%20name?query%20name#frag%20ment' - ] + yield [ + 'http://localhost' + ]; + yield [ + 'http://localhost/' + ]; + yield [ + 'http://localhost:8080/' + ]; + yield [ + 'http://127.0.0.1/' + ]; + yield [ + 'http://[::1]:8080/' + ]; + yield [ + 'http://localhost/path' + ]; + yield [ + 'http://localhost/sub/path' + ]; + yield [ + 'http://localhost/with%20space' + ]; + yield [ + 'http://localhost/with%2fslash' + ]; + yield [ + 'http://localhost/?name=Alice' + ]; + yield [ + 'http://localhost/?name=John+Doe' + ]; + yield [ + 'http://localhost/?name=John%20Doe' + ]; + yield [ + 'http://localhost/?name=Alice&age=42' + ]; + yield [ + 'http://localhost/?name=Alice&' + ]; + yield [ + 'http://localhost/?choice=A%26B' + ]; + yield [ + 'http://localhost/?safe=Yes!?' + ]; + yield [ + 'http://localhost/?alias=@home' + ]; + yield [ + 'http://localhost/?assign:=true' + ]; + yield [ + 'http://localhost/?name=' + ]; + yield [ + 'http://localhost/?name' + ]; + yield [ + '' + ]; + yield [ + '/' + ]; + yield [ + '/path' + ]; + yield [ + 'path' + ]; + yield [ + 'http://user@localhost/' + ]; + yield [ + 'http://user:@localhost/' + ]; + yield [ + 'http://:pass@localhost/' + ]; + yield [ + 'http://user:pass@localhost/path?query#fragment' + ]; + yield [ + 'http://user%20name:pass%20word@localhost/path%20name?query%20name#frag%20ment' ]; } @@ -137,35 +135,33 @@ public function testToStringReturnsOriginalUriGivenToCtor($string) public static function provideValidUrisThatWillBeTransformed() { - return [ - [ - 'http://localhost:8080/?', - 'http://localhost:8080/' - ], - [ - 'http://localhost:8080/#', - 'http://localhost:8080/' - ], - [ - 'http://localhost:8080/?#', - 'http://localhost:8080/' - ], - [ - 'http://@localhost:8080/', - 'http://localhost:8080/' - ], - [ - 'http://localhost:8080/?percent=50%', - 'http://localhost:8080/?percent=50%25' - ], - [ - 'http://user name:pass word@localhost/path name?query name#frag ment', - 'http://user%20name:pass%20word@localhost/path%20name?query%20name#frag%20ment' - ], - [ - 'HTTP://USER:PASS@LOCALHOST:8080/PATH?QUERY#FRAGMENT', - 'http://USER:PASS@localhost:8080/PATH?QUERY#FRAGMENT' - ] + yield [ + 'http://localhost:8080/?', + 'http://localhost:8080/' + ]; + yield [ + 'http://localhost:8080/#', + 'http://localhost:8080/' + ]; + yield [ + 'http://localhost:8080/?#', + 'http://localhost:8080/' + ]; + yield [ + 'http://@localhost:8080/', + 'http://localhost:8080/' + ]; + yield [ + 'http://localhost:8080/?percent=50%', + 'http://localhost:8080/?percent=50%25' + ]; + yield [ + 'http://user name:pass word@localhost/path name?query name#frag ment', + 'http://user%20name:pass%20word@localhost/path%20name?query%20name#frag%20ment' + ]; + yield [ + 'HTTP://USER:PASS@LOCALHOST:8080/PATH?QUERY#FRAGMENT', + 'http://USER:PASS@localhost:8080/PATH?QUERY#FRAGMENT' ]; } @@ -251,7 +247,7 @@ public function testWithSchemeThrowsWhenSchemeIsInvalid() { $uri = new Uri('http://localhost'); - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $uri->withScheme('invalid+scheme'); } @@ -375,7 +371,7 @@ public function testWithHostThrowsWhenHostIsInvalidWithPlus() { $uri = new Uri('http://localhost'); - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $uri->withHost('invalid+host'); } @@ -383,7 +379,7 @@ public function testWithHostThrowsWhenHostIsInvalidWithSpace() { $uri = new Uri('http://localhost'); - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $uri->withHost('invalid host'); } @@ -448,7 +444,7 @@ public function testWithPortThrowsWhenPortIsInvalidUnderflow() { $uri = new Uri('http://localhost'); - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $uri->withPort(0); } @@ -456,7 +452,7 @@ public function testWithPortThrowsWhenPortIsInvalidOverflow() { $uri = new Uri('http://localhost'); - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $uri->withPort(65536); } @@ -576,112 +572,110 @@ public function testWithFragmentReturnsSameInstanceWhenFragmentIsUnchangedEncode public static function provideResolveUris() { - return [ - [ - 'http://localhost/', - '', - 'http://localhost/' - ], - [ - 'http://localhost/', - 'http://example.com/', - 'http://example.com/' - ], - [ - 'http://localhost/', - 'path', - 'http://localhost/path' - ], - [ - 'http://localhost/', - 'path/', - 'http://localhost/path/' - ], - [ - 'http://localhost/', - 'path//', - 'http://localhost/path/' - ], - [ - 'http://localhost', - 'path', - 'http://localhost/path' - ], - [ - 'http://localhost/a/b', - '/path', - 'http://localhost/path' - ], - [ - 'http://localhost/', - '/a/b/c', - 'http://localhost/a/b/c' - ], - [ - 'http://localhost/a/path', - 'b/c', - 'http://localhost/a/b/c' - ], - [ - 'http://localhost/a/path', - '/b/c', - 'http://localhost/b/c' - ], - [ - 'http://localhost/a/path/', - 'b/c', - 'http://localhost/a/path/b/c' - ], - [ - 'http://localhost/a/path/', - '../b/c', - 'http://localhost/a/b/c' - ], - [ - 'http://localhost', - '../../../a/b', - 'http://localhost/a/b' - ], - [ - 'http://localhost/path', - '?query', - 'http://localhost/path?query' - ], - [ - 'http://localhost/path', - '#fragment', - 'http://localhost/path#fragment' - ], - [ - 'http://localhost/path', - 'http://localhost', - 'http://localhost' - ], - [ - 'http://localhost/path', - 'http://localhost/?query#fragment', - 'http://localhost/?query#fragment' - ], - [ - 'http://localhost/path/?a#fragment', - '?b', - 'http://localhost/path/?b' - ], - [ - 'http://localhost/path', - '//localhost', - 'http://localhost' - ], - [ - 'http://localhost/path', - '//localhost/a?query', - 'http://localhost/a?query' - ], - [ - 'http://localhost/path', - '//LOCALHOST', - 'http://localhost' - ] + yield [ + 'http://localhost/', + '', + 'http://localhost/' + ]; + yield [ + 'http://localhost/', + 'http://example.com/', + 'http://example.com/' + ]; + yield [ + 'http://localhost/', + 'path', + 'http://localhost/path' + ]; + yield [ + 'http://localhost/', + 'path/', + 'http://localhost/path/' + ]; + yield [ + 'http://localhost/', + 'path//', + 'http://localhost/path/' + ]; + yield [ + 'http://localhost', + 'path', + 'http://localhost/path' + ]; + yield [ + 'http://localhost/a/b', + '/path', + 'http://localhost/path' + ]; + yield [ + 'http://localhost/', + '/a/b/c', + 'http://localhost/a/b/c' + ]; + yield [ + 'http://localhost/a/path', + 'b/c', + 'http://localhost/a/b/c' + ]; + yield [ + 'http://localhost/a/path', + '/b/c', + 'http://localhost/b/c' + ]; + yield [ + 'http://localhost/a/path/', + 'b/c', + 'http://localhost/a/path/b/c' + ]; + yield [ + 'http://localhost/a/path/', + '../b/c', + 'http://localhost/a/b/c' + ]; + yield [ + 'http://localhost', + '../../../a/b', + 'http://localhost/a/b' + ]; + yield [ + 'http://localhost/path', + '?query', + 'http://localhost/path?query' + ]; + yield [ + 'http://localhost/path', + '#fragment', + 'http://localhost/path#fragment' + ]; + yield [ + 'http://localhost/path', + 'http://localhost', + 'http://localhost' + ]; + yield [ + 'http://localhost/path', + 'http://localhost/?query#fragment', + 'http://localhost/?query#fragment' + ]; + yield [ + 'http://localhost/path/?a#fragment', + '?b', + 'http://localhost/path/?b' + ]; + yield [ + 'http://localhost/path', + '//localhost', + 'http://localhost' + ]; + yield [ + 'http://localhost/path', + '//localhost/a?query', + 'http://localhost/a?query' + ]; + yield [ + 'http://localhost/path', + '//LOCALHOST', + 'http://localhost' ]; } diff --git a/tests/Middleware/LimitConcurrentRequestsMiddlewareTest.php b/tests/Middleware/LimitConcurrentRequestsMiddlewareTest.php index b79826d6..67656d4c 100644 --- a/tests/Middleware/LimitConcurrentRequestsMiddlewareTest.php +++ b/tests/Middleware/LimitConcurrentRequestsMiddlewareTest.php @@ -10,6 +10,7 @@ use React\Promise\Deferred; use React\Promise\Promise; use React\Promise\PromiseInterface; +use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; use React\Tests\Http\TestCase; @@ -114,7 +115,8 @@ public function testThrowsExceptionDirectlyFromMiddlewareWhenBelowLimit() { $middleware = new LimitConcurrentRequestsMiddleware(1); - $this->setExpectedException('RuntimeException', 'demo'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('demo'); $middleware(new ServerRequest('GET', 'https://example.com/'), function () { throw new \RuntimeException('demo'); }); @@ -124,7 +126,8 @@ public function testThrowsErrorDirectlyFromMiddlewareWhenBelowLimit() { $middleware = new LimitConcurrentRequestsMiddleware(1); - $this->setExpectedException('Error', 'demo'); + $this->expectException(\Error::class); + $this->expectExceptionMessage('demo'); $middleware(new ServerRequest('GET', 'https://example.com/'), function () { throw new \Error('demo'); }); @@ -159,7 +162,7 @@ public function testReturnsPendingPromiseFromMiddlewareWhenAboveLimit() public function testStreamDoesNotPauseOrResumeWhenBelowLimit() { - $body = $this->getMockBuilder('React\Http\Io\HttpBodyStream')->disableOriginalConstructor()->getMock(); + $body = $this->createMock(HttpBodyStream::class); $body->expects($this->never())->method('pause'); $body->expects($this->never())->method('resume'); $limitHandlers = new LimitConcurrentRequestsMiddleware(1); @@ -168,7 +171,7 @@ public function testStreamDoesNotPauseOrResumeWhenBelowLimit() public function testStreamDoesPauseWhenAboveLimit() { - $body = $this->getMockBuilder('React\Http\Io\HttpBodyStream')->disableOriginalConstructor()->getMock(); + $body = $this->createMock(HttpBodyStream::class); $body->expects($this->once())->method('pause'); $body->expects($this->never())->method('resume'); $limitHandlers = new LimitConcurrentRequestsMiddleware(1); @@ -182,7 +185,7 @@ public function testStreamDoesPauseWhenAboveLimit() public function testStreamDoesPauseAndThenResumeWhenDequeued() { - $body = $this->getMockBuilder('React\Http\Io\HttpBodyStream')->disableOriginalConstructor()->getMock(); + $body = $this->createMock(HttpBodyStream::class); $body->expects($this->once())->method('pause'); $body->expects($this->once())->method('resume'); $limitHandlers = new LimitConcurrentRequestsMiddleware(1); @@ -467,11 +470,11 @@ public function testReceivesStreamingBodyChangesInstanceWithCustomBodyButSameDat $deferred->reject(new \RuntimeException()); $this->assertNotSame($request, $req); - $this->assertInstanceOf('Psr\Http\Message\ServerRequestInterface', $req); + $this->assertInstanceOf(ServerRequestInterface::class, $req); $body = $req->getBody(); - $this->assertInstanceOf('React\Stream\ReadableStreamInterface', $body); - /* @var $body \React\Stream\ReadableStreamInterface */ + $this->assertInstanceOf(ReadableStreamInterface::class, $body); + /* @var $body ReadableStreamInterface */ $this->assertEquals(5, $body->getSize()); diff --git a/tests/Middleware/RequestBodyBufferMiddlewareTest.php b/tests/Middleware/RequestBodyBufferMiddlewareTest.php index 262ad9ca..28866c96 100644 --- a/tests/Middleware/RequestBodyBufferMiddlewareTest.php +++ b/tests/Middleware/RequestBodyBufferMiddlewareTest.php @@ -272,7 +272,7 @@ function (ServerRequestInterface $request) { $this->assertFalse($stream->isWritable()); assert($exception instanceof \RuntimeException); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); $this->assertEquals('Buffered 3', $exception->getMessage()); $this->assertEquals(42, $exception->getCode()); $this->assertNull($exception->getPrevious()); @@ -307,7 +307,7 @@ function (ServerRequestInterface $request) { $this->assertFalse($stream->isWritable()); assert($exception instanceof \Error); - $this->assertInstanceOf('Error', $exception); + $this->assertInstanceOf(\Error::class, $exception); $this->assertEquals('Buffered 3', $exception->getMessage()); $this->assertEquals(42, $exception->getCode()); $this->assertNull($exception->getPrevious()); @@ -342,10 +342,10 @@ public function testBufferingRejectsWhenStreamEmitsError() $this->assertFalse($stream->isWritable()); assert($exception instanceof \RuntimeException); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); $this->assertEquals('Error while buffering request body: Unexpected Foo', $exception->getMessage()); $this->assertEquals(42, $exception->getCode()); - $this->assertInstanceOf('UnexpectedValueException', $exception->getPrevious()); + $this->assertInstanceOf(\UnexpectedValueException::class, $exception->getPrevious()); } public function testFullBodyStreamedBeforeCallingNextMiddleware() @@ -399,7 +399,7 @@ public function testCancelBufferingClosesStreamAndRejectsPromise() }); assert($exception instanceof \RuntimeException); - $this->assertInstanceOf('RuntimeException', $exception); + $this->assertInstanceOf(\RuntimeException::class, $exception); $this->assertEquals('Cancelled buffering request body', $exception->getMessage()); $this->assertEquals(0, $exception->getCode()); $this->assertNull($exception->getPrevious()); diff --git a/tests/TestCase.php b/tests/TestCase.php index fa6fcd1c..4df6087f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,7 @@ namespace React\Tests\Http; +use PHPUnit\Framework\MockObject\MockBuilder; use PHPUnit\Framework\TestCase as BaseTestCase; class TestCase extends BaseTestCase @@ -39,46 +40,12 @@ protected function expectCallableNever() protected function createCallableMock() { - if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) { + if (method_exists(MockBuilder::class, 'addMethods')) { // PHPUnit 9+ - return $this->getMockBuilder('stdClass')->addMethods(['__invoke'])->getMock(); + return $this->getMockBuilder(\stdClass::class)->addMethods(['__invoke'])->getMock(); } else { - // legacy PHPUnit 4 - PHPUnit 8 - return $this->getMockBuilder('stdClass')->setMethods(['__invoke'])->getMock(); + // legacy PHPUnit + return $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); } } - - public function assertContainsString($needle, $haystack) - { - if (method_exists($this, 'assertStringContainsString')) { - // PHPUnit 7.5+ - $this->assertStringContainsString($needle, $haystack); - } else { - // legacy PHPUnit 4 - PHPUnit 7.5 - $this->assertContains($needle, $haystack); - } - } - - public function assertNotContainsString($needle, $haystack) - { - if (method_exists($this, 'assertStringNotContainsString')) { - // PHPUnit 7.5+ - $this->assertStringNotContainsString($needle, $haystack); - } else { - // legacy PHPUnit 4 - PHPUnit 7.5 - $this->assertNotContains($needle, $haystack); - } - } - - public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null) - { - $this->expectException($exception); - if ($exceptionMessage !== '') { - $this->expectExceptionMessage($exceptionMessage); - } - if ($exceptionCode !== null) { - $this->expectExceptionCode($exceptionCode); - } - } - }