diff --git a/composer.json b/composer.json index 09670a2..f29ea00 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,14 @@ } ], "autoload": { - "psr-4": {"React\\Datagram\\": "src"} + "psr-4": { + "React\\Datagram\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "React\\Tests\\Datagram\\": "tests" + } }, "require": { "php": ">=5.3", @@ -22,6 +29,6 @@ }, "require-dev": { "clue/block-react": "~1.0", - "phpunit/phpunit": "^5.0 || ^4.8" + "phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c763a40..f2c3ea9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,15 @@ - + ./tests/ diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 6e20766..508c212 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -1,5 +1,7 @@ loop = React\EventLoop\Factory::create(); + $this->loop = \React\EventLoop\Factory::create(); $this->resolver = $this->createResolverMock(); $this->factory = new Factory($this->loop, $this->resolver); } @@ -62,6 +64,8 @@ public function testCreateClientLocalhostWithDefaultResolver() $promise = $this->factory->createClient('localhost:12345'); $capturedClient = Block\await($promise, $this->loop); + $this->assertInstanceOf('React\Datagram\SocketInterface', $capturedClient); + $capturedClient->close(); } @@ -129,11 +133,13 @@ public function testCreateClientWithHostnameWillUseResolver() $client->close(); } + /** + * @expectedException RuntimeException + */ public function testCreateClientWithHostnameWillRejectIfResolverRejects() { $this->resolver->expects($this->once())->method('resolve')->with('example.com')->willReturn(Promise\reject(new \RuntimeException('test'))); - $this->setExpectedException('RuntimeException'); Block\await($this->factory->createClient('example.com:0'), $this->loop); } @@ -155,6 +161,9 @@ public function testCreateServerWithInvalidHostnameWillReject() Block\await($this->factory->createServer('/////'), $this->loop); } + /** + * @expectedException RuntimeException + */ public function testCancelCreateClientWithCancellableHostnameResolver() { $promise = new Promise\Promise(function () { }, $this->expectCallableOnce()); @@ -163,10 +172,12 @@ public function testCancelCreateClientWithCancellableHostnameResolver() $promise = $this->factory->createClient('example.com:0'); $promise->cancel(); - $this->setExpectedException('RuntimeException'); Block\await($promise, $this->loop); } + /** + * @expectedException RuntimeException + */ public function testCancelCreateClientWithUncancellableHostnameResolver() { $promise = $this->getMockBuilder('React\Promise\PromiseInterface')->getMock(); @@ -175,7 +186,6 @@ public function testCancelCreateClientWithUncancellableHostnameResolver() $promise = $this->factory->createClient('example.com:0'); $promise->cancel(); - $this->setExpectedException('RuntimeException'); Block\await($promise, $this->loop); } } diff --git a/tests/SocketTest.php b/tests/SocketTest.php index 50fd7e7..f938188 100644 --- a/tests/SocketTest.php +++ b/tests/SocketTest.php @@ -1,5 +1,7 @@ loop = React\EventLoop\Factory::create(); - $this->factory = new React\Datagram\Factory($this->loop, $this->createResolverMock()); + $this->loop = \React\EventLoop\Factory::create(); + $this->factory = new \React\Datagram\Factory($this->loop, $this->createResolverMock()); } + /** + * @doesNotPerformAssertions + */ public function testCreateClientCloseWillNotBlock() { $promise = $this->factory->createClient('127.0.0.1:12345'); @@ -28,7 +33,7 @@ public function testCreateClientCloseWillNotBlock() } /** - * + * @doesNotPerformAssertions * @param Socket $client * @depends testCreateClientCloseWillNotBlock */ @@ -38,6 +43,9 @@ public function testClientCloseAgainWillNotBlock(Socket $client) $this->loop->run(); } + /** + * @doesNotPerformAssertions + */ public function testCreateClientEndWillNotBlock() { $promise = $this->factory->createClient('127.0.0.1:12345'); @@ -52,7 +60,7 @@ public function testCreateClientEndWillNotBlock() } /** - * + * @doesNotPerformAssertions * @param Socket $client * @depends testCreateClientEndWillNotBlock */ @@ -65,7 +73,7 @@ public function testClientEndAgainWillNotBlock(Socket $client) } /** - * + * @doesNotPerformAssertions * @param Socket $client * @depends testClientEndAgainWillNotBlock */ diff --git a/tests/bootstrap.php b/tests/TestCase.php similarity index 73% rename from tests/bootstrap.php rename to tests/TestCase.php index 6fec244..15820e2 100644 --- a/tests/bootstrap.php +++ b/tests/TestCase.php @@ -1,8 +1,10 @@ getMockBuilder('CallableStub')->getMock(); + return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); } protected function createResolverMock() @@ -34,10 +36,3 @@ protected function createResolverMock() return $this->getMockBuilder('React\Dns\Resolver\ResolverInterface')->getMock(); } } - -class CallableStub -{ - public function __invoke() - { - } -}