diff --git a/.travis.yml b/.travis.yml index aca49750..5e266897 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ php: sudo: false install: - - composer install --prefer-source --no-interaction + - composer install --no-interaction script: - - phpunit --coverage-text + - vendor/bin/phpunit --coverage-text diff --git a/README.md b/README.md index 1ba69e46..9052985e 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ easily be used to create a DNS server. * [Caching](#caching) * [Custom cache adapter](#custom-cache-adapter) * [Install](#install) +* [Tests](#tests) * [License](#license) * [References](#references) @@ -104,6 +105,21 @@ $ composer require react/dns:^0.4.5 More details about version upgrades can be found in the [CHANGELOG](CHANGELOG.md). +## Tests + +To run the test suite, you first need to clone this repo and then install all +dependencies [through Composer](http://getcomposer.org): + +```bash +$ composer install +``` + +To run the test suite, go to the project root and run: + +```bash +$ php vendor/bin/phpunit +``` + ## License MIT, see [LICENSE file](LICENSE). diff --git a/composer.json b/composer.json index f3e41744..85dbd16f 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,9 @@ "react/promise": "~2.1|~1.2", "react/promise-timer": "~1.1" }, + "require-dev": { + "phpunit/phpunit": "^5.0 || ^4.8.10" + }, "autoload": { "psr-4": { "React\\Dns\\": "src" } }, diff --git a/tests/Config/FilesystemFactoryTest.php b/tests/Config/FilesystemFactoryTest.php index 4f40cc7d..718c11fc 100644 --- a/tests/Config/FilesystemFactoryTest.php +++ b/tests/Config/FilesystemFactoryTest.php @@ -26,7 +26,7 @@ public function parseEtcResolvConfShouldParseCorrectly() $capturedConfig = null; - $loop = $this->getMock('React\EventLoop\LoopInterface'); + $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); $factory = new FilesystemFactory($loop); $factory->parseEtcResolvConf($contents)->then(function ($config) use (&$capturedConfig) { $capturedConfig = $config; @@ -39,12 +39,14 @@ public function parseEtcResolvConfShouldParseCorrectly() /** @test */ public function createShouldLoadStuffFromFilesystem() { + $this->markTestIncomplete('Filesystem API is incomplete'); + $expected = array('8.8.8.8'); $triggerListener = null; $capturedConfig = null; - $loop = $this->getMock('React\EventLoop\LoopInterface'); + $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); $loop ->expects($this->once()) ->method('addReadStream') diff --git a/tests/Query/CachedExecutorTest.php b/tests/Query/CachedExecutorTest.php index 6e80f50d..d08ed053 100644 --- a/tests/Query/CachedExecutorTest.php +++ b/tests/Query/CachedExecutorTest.php @@ -90,11 +90,11 @@ private function callQueryCallbackWithAddress($address) private function createExecutorMock() { - return $this->getMock('React\Dns\Query\ExecutorInterface'); + return $this->getMockBuilder('React\Dns\Query\ExecutorInterface')->getMock(); } private function createPromiseMock() { - return $this->getMock('React\Promise\PromiseInterface'); + return $this->getMockBuilder('React\Promise\PromiseInterface')->getMock(); } } diff --git a/tests/Query/ExecutorTest.php b/tests/Query/ExecutorTest.php index 998f1df9..599e1d71 100644 --- a/tests/Query/ExecutorTest.php +++ b/tests/Query/ExecutorTest.php @@ -7,8 +7,9 @@ use React\Dns\Model\Message; use React\Dns\Model\Record; use React\Dns\Protocol\BinaryDumper; +use React\Tests\Dns\TestCase; -class ExecutorTest extends \PHPUnit_Framework_TestCase +class ExecutorTest extends TestCase { private $loop; private $parser; @@ -17,8 +18,8 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->loop = $this->getMock('React\EventLoop\LoopInterface'); - $this->parser = $this->getMock('React\Dns\Protocol\Parser'); + $this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $this->parser = $this->getMockBuilder('React\Dns\Protocol\Parser')->getMock(); $this->dumper = new BinaryDumper(); $this->executor = new Executor($this->loop, $this->parser, $this->dumper); @@ -27,7 +28,7 @@ public function setUp() /** @test */ public function queryShouldCreateUdpRequest() { - $timer = $this->getMock('React\EventLoop\Timer\TimerInterface'); + $timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock(); $this->loop ->expects($this->any()) ->method('addTimer') @@ -47,7 +48,7 @@ public function queryShouldCreateUdpRequest() /** @test */ public function resolveShouldCreateTcpRequestIfRequestIsLargerThan512Bytes() { - $timer = $this->getMock('React\EventLoop\Timer\TimerInterface'); + $timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock(); $this->loop ->expects($this->any()) ->method('addTimer') @@ -70,7 +71,7 @@ public function resolveShouldCloseConnectionWhenCancelled() $conn = $this->createConnectionMock(false); $conn->expects($this->once())->method('close'); - $timer = $this->getMock('React\EventLoop\Timer\TimerInterface'); + $timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock(); $this->loop ->expects($this->any()) ->method('addTimer') @@ -130,7 +131,7 @@ public function resolveShouldNotStartOrCancelTimerWhenCancelledWithTimeoutIsNull /** @test */ public function resolveShouldRetryWithTcpIfResponseIsTruncated() { - $timer = $this->getMock('React\EventLoop\Timer\TimerInterface'); + $timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock(); $this->loop ->expects($this->any()) @@ -165,7 +166,7 @@ public function resolveShouldRetryWithTcpIfResponseIsTruncated() /** @test */ public function resolveShouldRetryWithTcpIfUdpThrows() { - $timer = $this->getMock('React\EventLoop\Timer\TimerInterface'); + $timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock(); $this->loop ->expects($this->once()) @@ -196,7 +197,7 @@ public function resolveShouldRetryWithTcpIfUdpThrows() /** @test */ public function resolveShouldFailIfBothUdpAndTcpThrow() { - $timer = $this->getMock('React\EventLoop\Timer\TimerInterface'); + $timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock(); $this->loop ->expects($this->once()) @@ -237,7 +238,7 @@ public function resolveShouldFailIfBothUdpAndTcpThrow() /** @test */ public function resolveShouldFailIfResponseIsTruncatedAfterTcpRequest() { - $timer = $this->getMock('React\EventLoop\Timer\TimerInterface'); + $timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock(); $this->loop ->expects($this->any()) @@ -288,7 +289,7 @@ public function resolveShouldCancelTimerWhenFullResponseIsReceived() ->will($this->returnNewConnectionMock()); - $timer = $this->getMock('React\EventLoop\Timer\TimerInterface'); + $timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock(); $timer ->expects($this->once()) ->method('cancel'); @@ -313,7 +314,7 @@ public function resolveShouldCloseConnectionOnTimeout() ->with('8.8.8.8:53', 'udp') ->will($this->returnNewConnectionMock(false)); - $timer = $this->getMock('React\EventLoop\Timer\TimerInterface'); + $timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock(); $timer ->expects($this->never()) ->method('cancel'); @@ -400,7 +401,7 @@ private function returnNewConnectionMock($emitData = true) private function createConnectionMock($emitData = true) { - $conn = $this->getMock('React\Socket\ConnectionInterface'); + $conn = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock(); $conn ->expects($this->any()) ->method('on') @@ -419,19 +420,4 @@ private function createExecutorMock() ->setMethods(array('createConnection')) ->getMock(); } - - protected function expectCallableNever() - { - $mock = $this->createCallableMock(); - $mock - ->expects($this->never()) - ->method('__invoke'); - - return $mock; - } - - protected function createCallableMock() - { - return $this->getMock('React\Tests\Dns\CallableStub'); - } } diff --git a/tests/Query/RetryExecutorTest.php b/tests/Query/RetryExecutorTest.php index c8ffe307..8950f84f 100644 --- a/tests/Query/RetryExecutorTest.php +++ b/tests/Query/RetryExecutorTest.php @@ -162,26 +162,6 @@ public function queryShouldCancelQueryOnCancel() $this->assertEquals(1, $cancelled); } - protected function expectCallableOnce() - { - $mock = $this->createCallableMock(); - $mock - ->expects($this->once()) - ->method('__invoke'); - - return $mock; - } - - protected function expectCallableNever() - { - $mock = $this->createCallableMock(); - $mock - ->expects($this->never()) - ->method('__invoke'); - - return $mock; - } - protected function expectPromiseOnce($return = null) { $mock = $this->createPromiseMock(); @@ -193,19 +173,14 @@ protected function expectPromiseOnce($return = null) return $mock; } - protected function createCallableMock() - { - return $this->getMock('React\Tests\Dns\CallableStub'); - } - protected function createExecutorMock() { - return $this->getMock('React\Dns\Query\ExecutorInterface'); + return $this->getMockBuilder('React\Dns\Query\ExecutorInterface')->getMock(); } protected function createPromiseMock() { - return $this->getMock('React\Promise\PromiseInterface'); + return $this->getMockBuilder('React\Promise\PromiseInterface')->getMock(); } protected function createStandardResponse() diff --git a/tests/Query/TimeoutExecutorTest.php b/tests/Query/TimeoutExecutorTest.php index 6ba1e37c..7f5ad0d3 100644 --- a/tests/Query/TimeoutExecutorTest.php +++ b/tests/Query/TimeoutExecutorTest.php @@ -17,7 +17,7 @@ public function setUp() { $this->loop = Factory::create(); - $this->wrapped = $this->getMock('React\Dns\Query\ExecutorInterface'); + $this->wrapped = $this->getMockBuilder('React\Dns\Query\ExecutorInterface')->getMock(); $this->executor = new TimeoutExecutor($this->wrapped, 5.0, $this->loop); } diff --git a/tests/Resolver/FactoryTest.php b/tests/Resolver/FactoryTest.php index 6b3b9ac8..85a4977f 100644 --- a/tests/Resolver/FactoryTest.php +++ b/tests/Resolver/FactoryTest.php @@ -10,7 +10,7 @@ class FactoryTest extends TestCase /** @test */ public function createShouldCreateResolver() { - $loop = $this->getMock('React\EventLoop\LoopInterface'); + $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); $factory = new Factory(); $resolver = $factory->create('8.8.8.8:53', $loop); @@ -21,7 +21,7 @@ public function createShouldCreateResolver() /** @test */ public function createWithoutPortShouldCreateResolverWithDefaultPort() { - $loop = $this->getMock('React\EventLoop\LoopInterface'); + $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); $factory = new Factory(); $resolver = $factory->create('8.8.8.8', $loop); @@ -33,7 +33,7 @@ public function createWithoutPortShouldCreateResolverWithDefaultPort() /** @test */ public function createCachedShouldCreateResolverWithCachedExecutor() { - $loop = $this->getMock('React\EventLoop\LoopInterface'); + $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); $factory = new Factory(); $resolver = $factory->createCached('8.8.8.8:53', $loop); @@ -50,8 +50,8 @@ public function createCachedShouldCreateResolverWithCachedExecutor() /** @test */ public function createCachedShouldCreateResolverWithCachedExecutorWithCustomCache() { - $cache = $this->getMock('React\Cache\CacheInterface'); - $loop = $this->getMock('React\EventLoop\LoopInterface'); + $cache = $this->getMockBuilder('React\Cache\CacheInterface')->getMock(); + $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); $factory = new Factory(); $resolver = $factory->createCached('8.8.8.8:53', $loop, $cache); @@ -71,7 +71,7 @@ public function createCachedShouldCreateResolverWithCachedExecutorWithCustomCach */ public function factoryShouldAddDefaultPort($input, $expected) { - $loop = $this->getMock('React\EventLoop\LoopInterface'); + $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); $factory = new Factory(); $resolver = $factory->create($input, $loop); diff --git a/tests/Resolver/ResolveAliasesTest.php b/tests/Resolver/ResolveAliasesTest.php index 3eadb107..7ffa082e 100644 --- a/tests/Resolver/ResolveAliasesTest.php +++ b/tests/Resolver/ResolveAliasesTest.php @@ -94,6 +94,6 @@ public function provideAliasedAnswers() private function createExecutorMock() { - return $this->getMock('React\Dns\Query\ExecutorInterface'); + return $this->getMockBuilder('React\Dns\Query\ExecutorInterface')->getMock(); } } diff --git a/tests/Resolver/ResolverTest.php b/tests/Resolver/ResolverTest.php index 666b2549..e11509bd 100644 --- a/tests/Resolver/ResolverTest.php +++ b/tests/Resolver/ResolverTest.php @@ -7,8 +7,9 @@ use React\Dns\Model\Message; use React\Dns\Model\Record; use React\Promise; +use React\Tests\Dns\TestCase; -class ResolverTest extends \PHPUnit_Framework_TestCase +class ResolverTest extends TestCase { /** @test */ public function resolveShouldQueryARecords() @@ -121,44 +122,8 @@ public function resolveWithNoAnswersShouldCallErrbackIfGiven() $resolver->resolve('igor.io')->then($this->expectCallableNever(), $errback); } - protected function expectCallableOnceWith($with) - { - $mock = $this->createCallableMock(); - $mock - ->expects($this->once()) - ->method('__invoke') - ->with($with); - - return $mock; - } - - protected function expectCallableOnce() - { - $mock = $this->createCallableMock(); - $mock - ->expects($this->once()) - ->method('__invoke'); - - return $mock; - } - - protected function expectCallableNever() - { - $mock = $this->createCallableMock(); - $mock - ->expects($this->never()) - ->method('__invoke'); - - return $mock; - } - - protected function createCallableMock() - { - return $this->getMock('React\Tests\Dns\CallableStub'); - } - private function createExecutorMock() { - return $this->getMock('React\Dns\Query\ExecutorInterface'); + return $this->getMockBuilder('React\Dns\Query\ExecutorInterface')->getMock(); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 19650d41..620bfaa1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,7 +20,7 @@ protected function expectCallableOnceWith($value) $mock ->expects($this->once()) ->method('__invoke') - ->with($this->equalTo($value)); + ->with($value); return $mock; } @@ -37,6 +37,6 @@ protected function expectCallableNever() protected function createCallableMock() { - return $this->getMock('React\Tests\Dns\CallableStub'); + return $this->getMockBuilder('React\Tests\Dns\CallableStub')->getMock(); } }