diff --git a/tests/DnsConnectorTest.php b/tests/DnsConnectorTest.php index 3701ae6..15ba1a7 100644 --- a/tests/DnsConnectorTest.php +++ b/tests/DnsConnectorTest.php @@ -28,7 +28,9 @@ public function testPassByResolverIfGivenIp() $this->resolver->expects($this->never())->method('resolve'); $this->tcp->expects($this->once())->method('connect')->with($this->equalTo('127.0.0.1:80'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('127.0.0.1:80'); + $promise = $this->connector->connect('127.0.0.1:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection } public function testPassThroughResolverIfGivenHost() @@ -36,7 +38,9 @@ public function testPassThroughResolverIfGivenHost() $this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('1.2.3.4'))); $this->tcp->expects($this->once())->method('connect')->with($this->equalTo('1.2.3.4:80?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('google.com:80'); + $promise = $this->connector->connect('google.com:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection } public function testPassThroughResolverIfGivenHostWhichResolvesToIpv6() @@ -44,7 +48,9 @@ public function testPassThroughResolverIfGivenHostWhichResolvesToIpv6() $this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('::1'))); $this->tcp->expects($this->once())->method('connect')->with($this->equalTo('[::1]:80?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('google.com:80'); + $promise = $this->connector->connect('google.com:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection } public function testPassByResolverIfGivenCompleteUri() @@ -52,7 +58,9 @@ public function testPassByResolverIfGivenCompleteUri() $this->resolver->expects($this->never())->method('resolve'); $this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://127.0.0.1:80/path?query#fragment'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('scheme://127.0.0.1:80/path?query#fragment'); + $promise = $this->connector->connect('scheme://127.0.0.1:80/path?query#fragment'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection } public function testPassThroughResolverIfGivenCompleteUri() @@ -60,7 +68,9 @@ public function testPassThroughResolverIfGivenCompleteUri() $this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('1.2.3.4'))); $this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/path?query&hostname=google.com#fragment'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('scheme://google.com:80/path?query#fragment'); + $promise = $this->connector->connect('scheme://google.com:80/path?query#fragment'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection } public function testPassThroughResolverIfGivenExplicitHost() @@ -68,7 +78,9 @@ public function testPassThroughResolverIfGivenExplicitHost() $this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('google.com'))->will($this->returnValue(Promise\resolve('1.2.3.4'))); $this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/?hostname=google.de'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('scheme://google.com:80/?hostname=google.de'); + $promise = $this->connector->connect('scheme://google.com:80/?hostname=google.de'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection } public function testRejectsImmediatelyIfUriIsInvalid() @@ -289,6 +301,9 @@ public function testRejectionDuringDnsLookupShouldNotCreateAnyGarbageReferences( $this->tcp->expects($this->never())->method('connect'); $promise = $this->connector->connect('example.com:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + $dns->reject(new \RuntimeException('DNS failed')); unset($promise, $dns); @@ -310,6 +325,9 @@ public function testRejectionAfterDnsLookupShouldNotCreateAnyGarbageReferences() $this->tcp->expects($this->once())->method('connect')->with($this->equalTo('1.2.3.4:80?hostname=example.com'))->willReturn($tcp->promise()); $promise = $this->connector->connect('example.com:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + $dns->resolve('1.2.3.4'); $tcp->reject(new \RuntimeException('Connection failed')); unset($promise, $dns, $tcp); @@ -335,6 +353,9 @@ public function testRejectionAfterDnsLookupShouldNotCreateAnyGarbageReferencesAg $this->tcp->expects($this->once())->method('connect')->with($this->equalTo('1.2.3.4:80?hostname=example.com'))->willReturn($tcp->promise()); $promise = $this->connector->connect('example.com:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + $dns->resolve('1.2.3.4'); unset($promise, $dns, $tcp); diff --git a/tests/FunctionalSecureServerTest.php b/tests/FunctionalSecureServerTest.php index e3a8fca..f749a59 100644 --- a/tests/FunctionalSecureServerTest.php +++ b/tests/FunctionalSecureServerTest.php @@ -582,7 +582,13 @@ public function testServerEmitsErrorForClientWithInvalidCertificate() $connector = new SecureConnector(new TcpConnector(), null, array( 'verify_peer' => false )); - $connector->connect($server->getAddress()); + $promise = $connector->connect($server->getAddress()); + + try { + \React\Async\await($promise); + } catch (\RuntimeException $e) { + // ignore client-side exception + } $this->setExpectedException('RuntimeException', 'handshake'); diff --git a/tests/HappyEyeBallsConnectorTest.php b/tests/HappyEyeBallsConnectorTest.php index d8a3e5b..5301b3b 100644 --- a/tests/HappyEyeBallsConnectorTest.php +++ b/tests/HappyEyeBallsConnectorTest.php @@ -115,7 +115,9 @@ public function testPassByResolverIfGivenIpv6() $this->resolver->expects($this->never())->method('resolveAll'); $this->tcp->expects($this->once())->method('connect')->with($this->equalTo('[::1]:80'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('[::1]:80'); + $promise = $this->connector->connect('[::1]:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection $this->loop->run(); } @@ -125,7 +127,9 @@ public function testPassThroughResolverIfGivenHost() $this->resolver->expects($this->exactly(2))->method('resolveAll')->with($this->equalTo('google.com'), $this->anything())->will($this->returnValue(Promise\resolve(array('1.2.3.4')))); $this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('1.2.3.4:80?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('google.com:80'); + $promise = $this->connector->connect('google.com:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection $this->loop->run(); } @@ -135,7 +139,9 @@ public function testPassThroughResolverIfGivenHostWhichResolvesToIpv6() $this->resolver->expects($this->exactly(2))->method('resolveAll')->with($this->equalTo('google.com'), $this->anything())->will($this->returnValue(Promise\resolve(array('::1')))); $this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('[::1]:80?hostname=google.com'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('google.com:80'); + $promise = $this->connector->connect('google.com:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection $this->loop->run(); } @@ -145,7 +151,9 @@ public function testPassByResolverIfGivenCompleteUri() $this->resolver->expects($this->never())->method('resolveAll'); $this->tcp->expects($this->once())->method('connect')->with($this->equalTo('scheme://127.0.0.1:80/path?query#fragment'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('scheme://127.0.0.1:80/path?query#fragment'); + $promise = $this->connector->connect('scheme://127.0.0.1:80/path?query#fragment'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection $this->loop->run(); } @@ -155,7 +163,9 @@ public function testPassThroughResolverIfGivenCompleteUri() $this->resolver->expects($this->exactly(2))->method('resolveAll')->with($this->equalTo('google.com'), $this->anything())->will($this->returnValue(Promise\resolve(array('1.2.3.4')))); $this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/path?query&hostname=google.com#fragment'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('scheme://google.com:80/path?query#fragment'); + $promise = $this->connector->connect('scheme://google.com:80/path?query#fragment'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection $this->loop->run(); } @@ -165,7 +175,9 @@ public function testPassThroughResolverIfGivenExplicitHost() $this->resolver->expects($this->exactly(2))->method('resolveAll')->with($this->equalTo('google.com'), $this->anything())->will($this->returnValue(Promise\resolve(array('1.2.3.4')))); $this->tcp->expects($this->exactly(2))->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/?hostname=google.de'))->will($this->returnValue(Promise\reject(new \Exception('reject')))); - $this->connector->connect('scheme://google.com:80/?hostname=google.de'); + $promise = $this->connector->connect('scheme://google.com:80/?hostname=google.de'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection $this->loop->run(); } @@ -321,7 +333,6 @@ public function throwRejection($promise) public function provideIpvAddresses() { $ipv6 = array( - array(), array('1:2:3:4'), array('1:2:3:4', '5:6:7:8'), array('1:2:3:4', '5:6:7:8', '9:10:11:12'), diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 32d230c..fec5810 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -174,7 +174,6 @@ public function testWaitingForRejectedConnectionShouldNotCreateAnyGarbageReferen null, function ($e) use (&$wait) { $wait = false; - throw $e; } ); @@ -209,7 +208,6 @@ public function testWaitingForConnectionTimeoutDuringDnsLookupShouldNotCreateAny null, function ($e) use (&$wait) { $wait = false; - throw $e; } ); @@ -241,7 +239,6 @@ public function testWaitingForConnectionTimeoutDuringTcpConnectionShouldNotCreat null, function ($e) use (&$wait) { $wait = false; - throw $e; } ); @@ -273,7 +270,6 @@ public function testWaitingForInvalidDnsConnectionShouldNotCreateAnyGarbageRefer null, function ($e) use (&$wait) { $wait = false; - throw $e; } ); @@ -315,7 +311,6 @@ public function testWaitingForInvalidTlsConnectionShouldNotCreateAnyGarbageRefer null, function ($e) use (&$wait) { $wait = false; - throw $e; } ); diff --git a/tests/SecureConnectorTest.php b/tests/SecureConnectorTest.php index e7ed2f2..cfd0977 100644 --- a/tests/SecureConnectorTest.php +++ b/tests/SecureConnectorTest.php @@ -265,6 +265,9 @@ public function testRejectionDuringConnectionShouldNotCreateAnyGarbageReferences $this->tcp->expects($this->once())->method('connect')->willReturn($tcp->promise()); $promise = $this->connector->connect('example.com:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + $tcp->reject(new \RuntimeException()); unset($promise, $tcp); @@ -293,6 +296,9 @@ public function testRejectionDuringTlsHandshakeShouldNotCreateAnyGarbageReferenc $ref->setValue($this->connector, $encryption); $promise = $this->connector->connect('example.com:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + $tcp->resolve($connection); $tls->reject(new \RuntimeException()); unset($promise, $tcp, $tls); diff --git a/tests/TcpConnectorTest.php b/tests/TcpConnectorTest.php index 58b8d37..ede2070 100644 --- a/tests/TcpConnectorTest.php +++ b/tests/TcpConnectorTest.php @@ -116,7 +116,9 @@ public function connectionToTcpServerShouldFailIfFileDescriptorsAreExceeded() // dummy rejected promise to make sure autoloader has initialized all classes class_exists('React\Socket\SocketServer', true); class_exists('PHPUnit\Framework\Error\Warning', true); - new Promise(function () { throw new \RuntimeException('dummy'); }); + $promise = new Promise(function () { throw new \RuntimeException('dummy'); }); + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + unset($promise); // keep creating dummy file handles until all file descriptors are exhausted $fds = array(); diff --git a/tests/TimeoutConnectorTest.php b/tests/TimeoutConnectorTest.php index 71ca583..fa97de4 100644 --- a/tests/TimeoutConnectorTest.php +++ b/tests/TimeoutConnectorTest.php @@ -208,6 +208,9 @@ public function testRejectionDuringConnectionShouldNotCreateAnyGarbageReferences $timeout = new TimeoutConnector($connector, 0.01); $promise = $timeout->connect('example.com:80'); + + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + $connection->reject(new \RuntimeException('Connection failed')); unset($promise, $connection); @@ -232,6 +235,8 @@ public function testRejectionDueToTimeoutShouldNotCreateAnyGarbageReferences() $promise = $timeout->connect('example.com:80'); + $promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection + Loop::run(); unset($promise, $connection);