diff --git a/composer.json b/composer.json index 676d3e77..58cf494d 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ }, "require-dev": { "clue/block-react": "^1.2", - "phpunit/phpunit": "^7.5 || ^6.4 || ^5.7 || ^4.8.35", + "phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35", "react/promise-stream": "^1.2" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 04d426b5..0e947b87 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,15 +1,6 @@ - + ./tests/ diff --git a/tests/DnsConnectorTest.php b/tests/DnsConnectorTest.php index 7954d7c9..f6401931 100644 --- a/tests/DnsConnectorTest.php +++ b/tests/DnsConnectorTest.php @@ -12,7 +12,10 @@ class DnsConnectorTest extends TestCase private $resolver; private $connector; - public function setUp() + /** + * @before + */ + public function setUpMocks() { $this->tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); $this->resolver = $this->getMockBuilder('React\Dns\Resolver\ResolverInterface')->getMock(); @@ -78,10 +81,6 @@ public function testRejectsImmediatelyIfUriIsInvalid() $promise->then($this->expectCallableNever(), $this->expectCallableOnce()); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection failed - */ public function testRejectsWithTcpConnectorRejectionIfGivenIp() { $promise = Promise\reject(new \RuntimeException('Connection failed')); @@ -91,13 +90,10 @@ public function testRejectsWithTcpConnectorRejectionIfGivenIp() $promise = $this->connector->connect('1.2.3.4:80'); $promise->cancel(); + $this->setExpectedException('RuntimeException', 'Connection failed'); $this->throwRejection($promise); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection failed - */ public function testRejectsWithTcpConnectorRejectionAfterDnsIsResolved() { $promise = Promise\reject(new \RuntimeException('Connection failed')); @@ -107,13 +103,10 @@ public function testRejectsWithTcpConnectorRejectionAfterDnsIsResolved() $promise = $this->connector->connect('example.com:80'); $promise->cancel(); + $this->setExpectedException('RuntimeException', 'Connection failed'); $this->throwRejection($promise); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection to example.invalid:80 failed during DNS lookup: DNS error - */ public function testSkipConnectionIfDnsFails() { $promise = Promise\reject(new \RuntimeException('DNS error')); @@ -122,6 +115,7 @@ public function testSkipConnectionIfDnsFails() $promise = $this->connector->connect('example.invalid:80'); + $this->setExpectedException('RuntimeException', 'Connection to example.invalid:80 failed during DNS lookup: DNS error'); $this->throwRejection($promise); } @@ -138,10 +132,6 @@ public function testRejectionExceptionUsesPreviousExceptionIfDnsFails() })->then(null, $this->expectCallableOnceWith($this->identicalTo($exception))); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection to example.com:80 cancelled during DNS lookup - */ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection() { $pending = new Promise\Promise(function () { }, $this->expectCallableOnce()); @@ -151,6 +141,7 @@ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection() $promise = $this->connector->connect('example.com:80'); $promise->cancel(); + $this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled during DNS lookup'); $this->throwRejection($promise); } @@ -174,10 +165,6 @@ public function testCancelDuringTcpConnectionCancelsTcpConnectionAfterDnsIsResol $promise->cancel(); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection cancelled - */ public function testCancelDuringTcpConnectionCancelsTcpConnectionWithTcpRejectionAfterDnsIsResolved() { $first = new Deferred(); @@ -192,6 +179,7 @@ public function testCancelDuringTcpConnectionCancelsTcpConnectionWithTcpRejectio $promise->cancel(); + $this->setExpectedException('RuntimeException', 'Connection cancelled'); $this->throwRejection($promise); } diff --git a/tests/FunctionalSecureServerTest.php b/tests/FunctionalSecureServerTest.php index 146fefd9..568732f5 100644 --- a/tests/FunctionalSecureServerTest.php +++ b/tests/FunctionalSecureServerTest.php @@ -17,7 +17,10 @@ class FunctionalSecureServerTest extends TestCase { const TIMEOUT = 0.5; - public function setUp() + /** + * @before + */ + public function setUpSkipTest() { if (defined('HHVM_VERSION')) { $this->markTestSkipped('Not supported on legacy HHVM'); diff --git a/tests/FunctionalTcpServerTest.php b/tests/FunctionalTcpServerTest.php index 77395154..dcceba95 100644 --- a/tests/FunctionalTcpServerTest.php +++ b/tests/FunctionalTcpServerTest.php @@ -87,7 +87,7 @@ public function testEmitsConnectionWithRemoteIp() $peer = Block\await($peer, $loop, self::TIMEOUT); - $this->assertContains('127.0.0.1:', $peer); + $this->assertContainsString('127.0.0.1:', $peer); } public function testEmitsConnectionWithLocalIp() @@ -110,7 +110,7 @@ public function testEmitsConnectionWithLocalIp() $local = Block\await($peer, $loop, self::TIMEOUT); - $this->assertContains('127.0.0.1:', $local); + $this->assertContainsString('127.0.0.1:', $local); $this->assertEquals($server->getAddress(), $local); } @@ -136,7 +136,7 @@ public function testEmitsConnectionWithLocalIpDespiteListeningOnAll() $local = Block\await($peer, $loop, self::TIMEOUT); - $this->assertContains('127.0.0.1:', $local); + $this->assertContainsString('127.0.0.1:', $local); } public function testEmitsConnectionWithRemoteIpAfterConnectionIsClosedByPeer() @@ -159,7 +159,7 @@ public function testEmitsConnectionWithRemoteIpAfterConnectionIsClosedByPeer() $peer = Block\await($peer, $loop, self::TIMEOUT); - $this->assertContains('127.0.0.1:', $peer); + $this->assertContainsString('127.0.0.1:', $peer); } public function testEmitsConnectionWithRemoteNullAddressAfterConnectionIsClosedByServer() @@ -255,7 +255,7 @@ public function testEmitsConnectionWithRemoteIpv6() $peer = Block\await($peer, $loop, self::TIMEOUT); - $this->assertContains('[::1]:', $peer); + $this->assertContainsString('[::1]:', $peer); } public function testEmitsConnectionWithLocalIpv6() @@ -281,7 +281,7 @@ public function testEmitsConnectionWithLocalIpv6() $local = Block\await($peer, $loop, self::TIMEOUT); - $this->assertContains('[::1]:', $local); + $this->assertContainsString('[::1]:', $local); $this->assertEquals($server->getAddress(), $local); } @@ -314,43 +314,35 @@ public function testEmitsConnectionWithInheritedContextOptions() $this->assertEquals(array('socket' => array('backlog' => 4)), $all); } - /** - * @expectedException InvalidArgumentException - */ public function testFailsToListenOnInvalidUri() { $loop = Factory::create(); + $this->setExpectedException('InvalidArgumentException'); new TcpServer('///', $loop); } - /** - * @expectedException InvalidArgumentException - */ public function testFailsToListenOnUriWithoutPort() { $loop = Factory::create(); + $this->setExpectedException('InvalidArgumentException'); new TcpServer('127.0.0.1', $loop); } - /** - * @expectedException InvalidArgumentException - */ public function testFailsToListenOnUriWithWrongScheme() { $loop = Factory::create(); + $this->setExpectedException('InvalidArgumentException'); new TcpServer('udp://127.0.0.1:0', $loop); } - /** - * @expectedException InvalidArgumentException - */ public function testFailsToListenOnUriWIthHostname() { $loop = Factory::create(); + $this->setExpectedException('InvalidArgumentException'); new TcpServer('localhost:8080', $loop); } } diff --git a/tests/HappyEyeBallsConnectorTest.php b/tests/HappyEyeBallsConnectorTest.php index 27c8df45..209c6aa1 100644 --- a/tests/HappyEyeBallsConnectorTest.php +++ b/tests/HappyEyeBallsConnectorTest.php @@ -17,7 +17,10 @@ class HappyEyeBallsConnectorTest extends TestCase private $connector; private $connection; - public function setUp() + /** + * @before + */ + public function setUpMocks() { $this->loop = new TimerSpeedUpEventLoop(new StreamSelectLoop()); $this->tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); @@ -222,10 +225,6 @@ public function testRejectsImmediatelyIfUriIsInvalid() $this->loop->run(); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection failed - */ public function testRejectsWithTcpConnectorRejectionIfGivenIp() { $that = $this; @@ -240,13 +239,10 @@ public function testRejectsWithTcpConnectorRejectionIfGivenIp() $that->throwRejection($promise); }); + $this->setExpectedException('RuntimeException', 'Connection failed'); $this->loop->run(); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection to example.invalid:80 failed during DNS lookup: DNS error - */ public function testSkipConnectionIfDnsFails() { $that = $this; @@ -259,13 +255,10 @@ public function testSkipConnectionIfDnsFails() $that->throwRejection($promise); }); + $this->setExpectedException('RuntimeException', 'Connection to example.invalid:80 failed during DNS lookup: DNS error'); $this->loop->run(); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection to example.com:80 cancelled during DNS lookup - */ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection() { $that = $this; @@ -281,6 +274,7 @@ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection() $that->throwRejection($promise); }); + $this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled during DNS lookup'); $this->loop->run(); } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index d9a7b378..7ec2047e 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -23,14 +23,14 @@ public function gettingStuffFromGoogleShouldWork() $conn = Block\await($connector->connect('google.com:80'), $loop); - $this->assertContains(':80', $conn->getRemoteAddress()); + $this->assertContainsString(':80', $conn->getRemoteAddress()); $this->assertNotEquals('google.com:80', $conn->getRemoteAddress()); $conn->write("GET / HTTP/1.0\r\n\r\n"); $response = $this->buffer($conn, $loop, self::TIMEOUT); - $this->assertRegExp('#^HTTP/1\.0#', $response); + $this->assertMatchesRegExp('#^HTTP/1\.0#', $response); } /** @test */ @@ -49,7 +49,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork() $response = $this->buffer($conn, $loop, self::TIMEOUT); - $this->assertRegExp('#^HTTP/1\.0#', $response); + $this->assertMatchesRegExp('#^HTTP/1\.0#', $response); } /** @test */ @@ -78,7 +78,7 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst() $response = $this->buffer($conn, $loop, self::TIMEOUT); - $this->assertRegExp('#^HTTP/1\.0#', $response); + $this->assertMatchesRegExp('#^HTTP/1\.0#', $response); } /** @test */ @@ -89,14 +89,14 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork() $conn = Block\await($connector->connect('google.com:443'), $loop); - $this->assertContains(':443', $conn->getRemoteAddress()); + $this->assertContainsString(':443', $conn->getRemoteAddress()); $this->assertNotEquals('google.com:443', $conn->getRemoteAddress()); $conn->write("GET / HTTP/1.0\r\n\r\n"); $response = $this->buffer($conn, $loop, self::TIMEOUT); - $this->assertNotRegExp('#^HTTP/1\.0#', $response); + $this->assertDoesNotMatchRegExp('#^HTTP/1\.0#', $response); } public function testConnectingFailsIfConnectorUsesInvalidDnsResolverAddress() diff --git a/tests/SecureConnectorTest.php b/tests/SecureConnectorTest.php index d272c79f..7f00028f 100644 --- a/tests/SecureConnectorTest.php +++ b/tests/SecureConnectorTest.php @@ -12,7 +12,10 @@ class SecureConnectorTest extends TestCase private $tcp; private $connector; - public function setUp() + /** + * @before + */ + public function setUpConnector() { if (defined('HHVM_VERSION')) { $this->markTestSkipped('Not supported on legacy HHVM'); @@ -59,10 +62,6 @@ public function testCancelDuringTcpConnectionCancelsTcpConnection() $promise->cancel(); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection cancelled - */ public function testCancelDuringTcpConnectionCancelsTcpConnectionAndRejectsWithTcpRejection() { $pending = new Promise\Promise(function () { }, function () { throw new \RuntimeException('Connection cancelled'); }); @@ -71,13 +70,10 @@ public function testCancelDuringTcpConnectionCancelsTcpConnectionAndRejectsWithT $promise = $this->connector->connect('example.com:80'); $promise->cancel(); + $this->setExpectedException('RuntimeException', 'Connection cancelled'); $this->throwRejection($promise); } - /** - * @expectedException UnexpectedValueException - * @expectedExceptionMessage Base connector does not use internal Connection class exposing stream resource - */ public function testConnectionWillBeClosedAndRejectedIfConnectionIsNoStream() { $connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); @@ -87,6 +83,7 @@ public function testConnectionWillBeClosedAndRejectedIfConnectionIsNoStream() $promise = $this->connector->connect('example.com:80'); + $this->setExpectedException('UnexpectedValueException', 'Base connector does not use internal Connection class exposing stream resource'); $this->throwRejection($promise); } @@ -133,10 +130,6 @@ public function testConnectionWillBeRejectedIfStreamEncryptionFailsAndClosesConn } } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection to example.com:80 cancelled during TLS handshake - */ public function testCancelDuringStreamEncryptionCancelsEncryptionAndClosesConnection() { $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->getMock(); @@ -157,6 +150,7 @@ public function testCancelDuringStreamEncryptionCancelsEncryptionAndClosesConnec $promise = $this->connector->connect('example.com:80'); $promise->cancel(); + $this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled during TLS handshake'); $this->throwRejection($promise); } diff --git a/tests/SecureIntegrationTest.php b/tests/SecureIntegrationTest.php index 1ef2f5de..c55880b6 100644 --- a/tests/SecureIntegrationTest.php +++ b/tests/SecureIntegrationTest.php @@ -22,7 +22,10 @@ class SecureIntegrationTest extends TestCase private $connector; private $address; - public function setUp() + /** + * @before + */ + public function setUpConnector() { if (defined('HHVM_VERSION')) { $this->markTestSkipped('Not supported on legacy HHVM'); @@ -37,7 +40,10 @@ public function setUp() $this->connector = new SecureConnector(new TcpConnector($this->loop), $this->loop, array('verify_peer' => false)); } - public function tearDown() + /** + * @after + */ + public function tearDownServer() { if ($this->server !== null) { $this->server->close(); diff --git a/tests/SecureServerTest.php b/tests/SecureServerTest.php index 96a2dcee..c5911c3c 100644 --- a/tests/SecureServerTest.php +++ b/tests/SecureServerTest.php @@ -8,7 +8,10 @@ class SecureServerTest extends TestCase { - public function setUp() + /** + * @before + */ + public function setUpSkipTest() { if (defined('HHVM_VERSION')) { $this->markTestSkipped('Not supported on legacy HHVM'); diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 25db8759..99e69883 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -23,13 +23,11 @@ public function testCreateServerWithZeroPortAssignsRandomPort() $server->close(); } - /** - * @expectedException InvalidArgumentException - */ public function testConstructorThrowsForInvalidUri() { $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $this->setExpectedException('InvalidArgumentException'); $server = new Server('invalid URI', $loop); } diff --git a/tests/TcpConnectorTest.php b/tests/TcpConnectorTest.php index b391b89b..d9798595 100644 --- a/tests/TcpConnectorTest.php +++ b/tests/TcpConnectorTest.php @@ -13,11 +13,7 @@ class TcpConnectorTest extends TestCase { const TIMEOUT = 5.0; - /** - * @test - * @expectedException RuntimeException - * @expectedExceptionMessage Connection to tcp://127.0.0.1:9999 failed: Connection refused - */ + /** @test */ public function connectionToEmptyPortShouldFail() { $loop = Factory::create(); @@ -25,6 +21,7 @@ public function connectionToEmptyPortShouldFail() $connector = new TcpConnector($loop); $promise = $connector->connect('127.0.0.1:9999'); + $this->setExpectedException('RuntimeException', 'Connection to tcp://127.0.0.1:9999 failed: Connection refused'); Block\await($promise, $loop, self::TIMEOUT); } @@ -63,10 +60,7 @@ public function connectionToTcpServerShouldSucceed() $server->close(); } - /** - * @test - * @expectedException RuntimeException - */ + /** @test */ public function connectionToTcpServerShouldFailIfFileDescriptorsAreExceeded() { $loop = Factory::create(); @@ -91,6 +85,7 @@ public function connectionToTcpServerShouldFailIfFileDescriptorsAreExceeded() $fds[] = $fd; } + $this->setExpectedException('RuntimeException'); Block\await($connector->connect('127.0.0.1:9999'), $loop, self::TIMEOUT); } @@ -124,7 +119,7 @@ public function connectionToTcpServerShouldSucceedWithLocalAdressOnLocalhost() $connection = Block\await($connector->connect('127.0.0.1:9999'), $loop, self::TIMEOUT); /* @var $connection ConnectionInterface */ - $this->assertContains('tcp://127.0.0.1:', $connection->getLocalAddress()); + $this->assertContainsString('tcp://127.0.0.1:', $connection->getLocalAddress()); $this->assertNotEquals('tcp://127.0.0.1:9999', $connection->getLocalAddress()); $connection->close(); @@ -203,7 +198,7 @@ public function connectionToIp6TcpServerShouldSucceed() $this->assertEquals('tcp://[::1]:9999', $connection->getRemoteAddress()); - $this->assertContains('tcp://[::1]:', $connection->getLocalAddress()); + $this->assertContainsString('tcp://[::1]:', $connection->getLocalAddress()); $this->assertNotEquals('tcp://[::1]:9999', $connection->getLocalAddress()); $connection->close(); @@ -271,7 +266,6 @@ public function cancellingConnectionShouldRemoveResourceFromLoopAndCloseResource $this->assertTrue($valid); // ensure that this resource should now be closed after the cancel() call - $this->assertInternalType('resource', $resource); $this->assertFalse(is_resource($resource)); } diff --git a/tests/TcpServerTest.php b/tests/TcpServerTest.php index d4243f7e..2e4b2c3b 100644 --- a/tests/TcpServerTest.php +++ b/tests/TcpServerTest.php @@ -22,10 +22,11 @@ private function createLoop() } /** + * @before * @covers React\Socket\TcpServer::__construct * @covers React\Socket\TcpServer::getAddress */ - public function setUp() + public function setUpServer() { $this->loop = $this->createLoop(); $this->server = new TcpServer(0, $this->loop); @@ -283,22 +284,21 @@ public function testEmitsErrorWhenAcceptListenerFails() $listener($socket); } - /** - * @expectedException RuntimeException - */ public function testListenOnBusyPortThrows() { if (DIRECTORY_SEPARATOR === '\\') { $this->markTestSkipped('Windows supports listening on same port multiple times'); } + $this->setExpectedException('RuntimeException'); $another = new TcpServer($this->port, $this->loop); } /** + * @after * @covers React\Socket\TcpServer::close */ - public function tearDown() + public function tearDownServer() { if ($this->server) { $this->server->close(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 4c4adbd9..cdb8b1bc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -115,4 +115,38 @@ protected function supportsTls13() } return false; } + + 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 assertMatchesRegExp($pattern, $string) + { + if (method_exists($this, 'assertMatchesRegularExpression')) { + // PHPUnit 10 + $this->assertMatchesRegularExpression($pattern, $string); + } else { + // legacy PHPUnit 4 - PHPUnit 9.2 + $this->assertRegExp($pattern, $string); + } + } + + public function assertDoesNotMatchRegExp($pattern, $string) + { + if (method_exists($this, 'assertDoesNotMatchRegularExpression')) { + // PHPUnit 10 + $this->assertDoesNotMatchRegularExpression($pattern, $string); + } else { + // legacy PHPUnit 4 - PHPUnit 9.2 + $this->assertNotRegExp($pattern, $string); + } + } + } diff --git a/tests/TimeoutConnectorTest.php b/tests/TimeoutConnectorTest.php index d4b21718..8595b981 100644 --- a/tests/TimeoutConnectorTest.php +++ b/tests/TimeoutConnectorTest.php @@ -10,10 +10,6 @@ class TimeoutConnectorTest extends TestCase { - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Connection to google.com:80 timed out after 0.01 seconds - */ public function testRejectsWithTimeoutReasonOnTimeout() { $promise = new Promise\Promise(function () { }); @@ -25,13 +21,10 @@ public function testRejectsWithTimeoutReasonOnTimeout() $timeout = new TimeoutConnector($connector, 0.01, $loop); + $this->setExpectedException('RuntimeException', 'Connection to google.com:80 timed out after 0.01 seconds'); Block\await($timeout->connect('google.com:80'), $loop); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Failed - */ public function testRejectsWithOriginalReasonWhenConnectorRejects() { $promise = Promise\reject(new \RuntimeException('Failed')); @@ -43,6 +36,7 @@ public function testRejectsWithOriginalReasonWhenConnectorRejects() $timeout = new TimeoutConnector($connector, 5.0, $loop); + $this->setExpectedException('RuntimeException', 'Failed'); Block\await($timeout->connect('google.com:80'), $loop); } diff --git a/tests/UnixConnectorTest.php b/tests/UnixConnectorTest.php index ab9c867b..d9fe79cd 100644 --- a/tests/UnixConnectorTest.php +++ b/tests/UnixConnectorTest.php @@ -10,7 +10,10 @@ class UnixConnectorTest extends TestCase private $loop; private $connector; - public function setUp() + /** + * @before + */ + public function setUpConnector() { $this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); $this->connector = new UnixConnector($this->loop); diff --git a/tests/UnixServerTest.php b/tests/UnixServerTest.php index 6a46c100..da9827a7 100644 --- a/tests/UnixServerTest.php +++ b/tests/UnixServerTest.php @@ -14,10 +14,11 @@ class UnixServerTest extends TestCase private $uds; /** + * @before * @covers React\Socket\UnixServer::__construct * @covers React\Socket\UnixServer::getAddress */ - public function setUp() + public function setUpServer() { if (!in_array('unix', stream_get_transports())) { $this->markTestSkipped('Unix domain sockets (UDS) not supported on your platform (Windows?)'); @@ -216,23 +217,19 @@ public function testCtorAddsResourceToLoop() $server = new UnixServer($this->getRandomSocketUri(), $loop); } - /** - * @expectedException InvalidArgumentException - */ public function testCtorThrowsForInvalidAddressScheme() { $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $this->setExpectedException('InvalidArgumentException'); $server = new UnixServer('tcp://localhost:0', $loop); } - /** - * @expectedException RuntimeException - */ public function testCtorThrowsWhenPathIsNotWritable() { $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $this->setExpectedException('RuntimeException'); $server = new UnixServer('/dev/null', $loop); } @@ -292,22 +289,21 @@ public function testEmitsErrorWhenAcceptListenerFails() $listener($socket); } - /** - * @expectedException RuntimeException - */ public function testListenOnBusyPortThrows() { if (DIRECTORY_SEPARATOR === '\\') { $this->markTestSkipped('Windows supports listening on same port multiple times'); } + $this->setExpectedException('RuntimeException'); $another = new UnixServer($this->uds, $this->loop); } /** + * @after * @covers React\Socket\UnixServer::close */ - public function tearDown() + public function tearDownServer() { if ($this->server) { $this->server->close();