Skip to content

Commit 2ebb7cf

Browse files
committed
Add tests instructions and add PHPUnit to require-dev
1 parent 72ef0d6 commit 2ebb7cf

File tree

6 files changed

+33
-36
lines changed

6 files changed

+33
-36
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ php:
99
- hhvm
1010

1111
install:
12-
- composer install --prefer-source --no-interaction
12+
- composer install --no-interaction
1313

1414
script:
15-
- phpunit --coverage-text
15+
- vendor/bin/phpunit --coverage-text

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ as defined in [RFC 6763](http://tools.ietf.org/html/rfc6763).
2020
* [Promises](#promises)
2121
* [Blocking](#blocking)
2222
* [Install](#install)
23+
* [Tests](#tests)
2324
* [License](#license)
2425
* [More](#more)
2526

@@ -140,6 +141,21 @@ $ composer require clue/mdns-react:~0.2.0
140141

141142
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
142143

144+
## Tests
145+
146+
To run the test suite, you first need to clone this repo and then install all
147+
dependencies [through Composer](https://getcomposer.org):
148+
149+
```bash
150+
$ composer install
151+
```
152+
153+
To run the test suite, go to the project root and run:
154+
155+
```bash
156+
$ php vendor/bin/phpunit
157+
```
158+
143159
## License
144160

145161
MIT

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
"react/event-loop": "~0.4.0|~0.3.0",
2020
"react/dns": "~0.4.0|~0.3.0",
2121
"react/promise": "^2.1 || ^1.2.1"
22+
},
23+
"require-dev": {
24+
"phpunit/phpunit": "^6.0 || ^5.7 || ^4.8.35"
2225
}
2326
}

tests/FactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class FactoryTest extends TestCase
66
{
77
public function testCreateResolver()
88
{
9-
$loop = $this->getMock('React\EventLoop\LoopInterface');
9+
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
1010
$factory = new Factory($loop);
1111

1212
$resolver = $factory->createResolver();

tests/MulticastExecutorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ class MulticastExecutorTest extends TestCase
1515
public function setUp()
1616
{
1717
$this->nameserver = Factory::DNS;
18-
$this->loop = $this->getMock('React\EventLoop\LoopInterface');
19-
$this->parser = $this->getMock('React\Dns\Protocol\Parser');
20-
$this->dumper = $this->getMock('React\Dns\Protocol\BinaryDumper');
18+
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
19+
$this->parser = $this->getMockBuilder('React\Dns\Protocol\Parser')->getMock();
20+
$this->dumper = $this->getMockBuilder('React\Dns\Protocol\BinaryDumper')->getMock();
2121
$this->sockets = $this->getMockBuilder('Clue\React\Multicast\Factory')->disableOriginalConstructor()->getMock();
2222
}
2323

2424
public function testQueryWillReturnPromise()
2525
{
2626
$executor = new MulticastExecutor($this->loop, $this->parser, $this->dumper, 5, $this->sockets);
2727

28-
$socket = $this->getMock('React\Datagram\SocketInterface');
28+
$socket = $this->getMockBuilder('React\Datagram\SocketInterface')->getMock();
2929

3030
$this->dumper->expects($this->once())->method('toBinary')->will($this->returnValue('message'));
3131
$this->sockets->expects($this->once())->method('createSender')->will($this->returnValue($socket));
@@ -42,12 +42,12 @@ public function testCancellingPromiseWillCloseSocketAndReject()
4242
{
4343
$executor = new MulticastExecutor($this->loop, $this->parser, $this->dumper, 5, $this->sockets);
4444

45-
$socket = $this->getMock('React\Datagram\SocketInterface');
45+
$socket = $this->getMockBuilder('React\Datagram\SocketInterface')->getMock();
4646
$socket->expects($this->once())->method('close');
4747
$socket->expects($this->once())->method('send')->with($this->equalTo('message'), $this->equalTo($this->nameserver));
4848
$this->sockets->expects($this->once())->method('createSender')->will($this->returnValue($socket));
4949

50-
$timer = $this->getMock('React\EventLoop\Timer\TimerInterface');
50+
$timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock();
5151
$timer->expects($this->once())->method('cancel');
5252
$this->loop->expects($this->once())->method('addTimer')->willReturn($timer);
5353

@@ -60,6 +60,6 @@ public function testCancellingPromiseWillCloseSocketAndReject()
6060

6161
$ret->cancel();
6262

63-
$ret->then($this->expectCallableNever(), $this->expectCallableOnceParameter('RuntimeException'));
63+
$ret->then($this->expectCallableNever(), $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
6464
}
6565
}

tests/bootstrap.php

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
require_once __DIR__ . '/../vendor/autoload.php';
3+
require __DIR__ . '/../vendor/autoload.php';
44

55
error_reporting(-1);
66

7-
class TestCase extends PHPUnit_Framework_TestCase
7+
class TestCase extends PHPUnit\Framework\TestCase
88
{
99
protected function expectCallableOnce()
1010
{
@@ -24,7 +24,7 @@ protected function expectCallableOnceWith($value)
2424
$mock
2525
->expects($this->once())
2626
->method('__invoke')
27-
->with($this->equalTo($value));
27+
->with($value);
2828

2929
return $mock;
3030
}
@@ -39,30 +39,8 @@ protected function expectCallableNever()
3939
return $mock;
4040
}
4141

42-
protected function expectCallableOnceParameter($type)
43-
{
44-
$mock = $this->createCallableMock();
45-
$mock
46-
->expects($this->once())
47-
->method('__invoke')
48-
->with($this->isInstanceOf($type));
49-
50-
return $mock;
51-
}
52-
53-
/**
54-
* @link https://github.com/reactphp/react/blob/master/tests/React/Tests/Socket/TestCase.php (taken from reactphp/react)
55-
*/
5642
protected function createCallableMock()
5743
{
58-
return $this->getMock('CallableStub');
44+
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
5945
}
6046
}
61-
62-
class CallableStub
63-
{
64-
public function __invoke()
65-
{
66-
}
67-
}
68-

0 commit comments

Comments
 (0)