diff --git a/tests/Client/RequestTest.php b/tests/Client/RequestTest.php index 207aa15f..d7e43c3a 100644 --- a/tests/Client/RequestTest.php +++ b/tests/Client/RequestTest.php @@ -86,28 +86,30 @@ public function requestShouldBindToStreamEventsAndUseconnector() $request->handleData("\r\nbody"); } + /** + * @test + */ + public function requestShouldConnectViaTlsIfUrlUsesHttpsScheme() + { + $requestData = new RequestData('GET', 'https://www.example.com'); + $request = new Request($this->connector, $requestData); + + $this->connector->expects($this->once())->method('connect')->with('tls://www.example.com:443')->willReturn(new Promise(function () { })); + + $request->end(); + } + /** @test */ public function requestShouldEmitErrorIfConnectionFails() { $requestData = new RequestData('GET', 'http://www.example.com'); $request = new Request($this->connector, $requestData); - $this->rejectedConnectionMock(); - - $handler = $this->createCallableMock(); - $handler->expects($this->once()) - ->method('__invoke') - ->with( - $this->isInstanceOf('RuntimeException') - ); - - $request->on('error', $handler); + $this->connector->expects($this->once())->method('connect')->willReturn(\React\Promise\reject(new \RuntimeException())); - $handler = $this->createCallableMock(); - $handler->expects($this->once()) - ->method('__invoke'); + $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException'))); - $request->on('close', $handler); + $request->on('close', $this->expectCallableOnce()); $request->on('end', $this->expectCallableNever()); $request->end(); @@ -121,20 +123,9 @@ public function requestShouldEmitErrorIfConnectionClosesBeforeResponseIsParsed() $this->successfulConnectionMock(); - $handler = $this->createCallableMock(); - $handler->expects($this->once()) - ->method('__invoke') - ->with( - $this->isInstanceOf('RuntimeException') - ); - - $request->on('error', $handler); - - $handler = $this->createCallableMock(); - $handler->expects($this->once()) - ->method('__invoke'); + $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException'))); - $request->on('close', $handler); + $request->on('close', $this->expectCallableOnce()); $request->on('end', $this->expectCallableNever()); $request->end(); @@ -149,20 +140,9 @@ public function requestShouldEmitErrorIfConnectionEmitsError() $this->successfulConnectionMock(); - $handler = $this->createCallableMock(); - $handler->expects($this->once()) - ->method('__invoke') - ->with( - $this->isInstanceOf('Exception') - ); - - $request->on('error', $handler); + $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('Exception'))); - $handler = $this->createCallableMock(); - $handler->expects($this->once()) - ->method('__invoke'); - - $request->on('close', $handler); + $request->on('close', $this->expectCallableOnce()); $request->on('end', $this->expectCallableNever()); $request->end(); @@ -177,14 +157,7 @@ public function requestShouldEmitErrorIfRequestParserThrowsException() $this->successfulConnectionMock(); - $handler = $this->createCallableMock(); - $handler->expects($this->once()) - ->method('__invoke') - ->with( - $this->isInstanceOf('\InvalidArgumentException') - ); - - $request->on('error', $handler); + $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException'))); $request->end(); $request->handleData("\r\n\r\n"); @@ -198,14 +171,7 @@ public function requestShouldEmitErrorIfUrlIsInvalid() $requestData = new RequestData('GET', 'ftp://www.example.com'); $request = new Request($this->connector, $requestData); - $handler = $this->createCallableMock(); - $handler->expects($this->once()) - ->method('__invoke') - ->with( - $this->isInstanceOf('\InvalidArgumentException') - ); - - $request->on('error', $handler); + $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException'))); $this->connector->expects($this->never()) ->method('connect'); @@ -221,14 +187,7 @@ public function requestShouldEmitErrorIfUrlHasNoScheme() $requestData = new RequestData('GET', 'www.example.com'); $request = new Request($this->connector, $requestData); - $handler = $this->createCallableMock(); - $handler->expects($this->once()) - ->method('__invoke') - ->with( - $this->isInstanceOf('\InvalidArgumentException') - ); - - $request->on('error', $handler); + $request->on('error', $this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException'))); $this->connector->expects($this->never()) ->method('connect'); @@ -533,15 +492,6 @@ private function successfulAsyncConnectionMock() }; } - private function rejectedConnectionMock() - { - $this->connector - ->expects($this->once()) - ->method('connect') - ->with('www.example.com:80') - ->will($this->returnValue(new RejectedPromise(new \RuntimeException()))); - } - /** @test */ public function multivalueHeader() { diff --git a/tests/FunctionalServerTest.php b/tests/FunctionalServerTest.php index 3355b732..bd127ab7 100644 --- a/tests/FunctionalServerTest.php +++ b/tests/FunctionalServerTest.php @@ -300,8 +300,8 @@ public function testPlainHttpOnStandardPortWithoutHostHeaderReturnsUriWithNoPort public function testSecureHttpsOnStandardPortReturnsUriWithNoPort() { - if (!function_exists('stream_socket_enable_crypto')) { - $this->markTestSkipped('Not supported on your platform (outdated HHVM?)'); + if (defined('HHVM_VERSION')) { + $this->markTestSkipped('Not supported on HHVM'); } $loop = Factory::create(); @@ -339,8 +339,8 @@ public function testSecureHttpsOnStandardPortReturnsUriWithNoPort() public function testSecureHttpsOnStandardPortWithoutHostHeaderUsesSocketUri() { - if (!function_exists('stream_socket_enable_crypto')) { - $this->markTestSkipped('Not supported on your platform (outdated HHVM?)'); + if (defined('HHVM_VERSION')) { + $this->markTestSkipped('Not supported on HHVM'); } $loop = Factory::create(); @@ -408,8 +408,8 @@ public function testPlainHttpOnHttpsStandardPortReturnsUriWithPort() public function testSecureHttpsOnHttpStandardPortReturnsUriWithPort() { - if (!function_exists('stream_socket_enable_crypto')) { - $this->markTestSkipped('Not supported on your platform (outdated HHVM?)'); + if (defined('HHVM_VERSION')) { + $this->markTestSkipped('Not supported on HHVM'); } $loop = Factory::create();