Skip to content

Commit 6d1039a

Browse files
authored
Merge pull request #9 from clue-labs/tests
Improve test suite by adding test instructions and adding PHPUnit to require-dev
2 parents 72ef0d6 + 0fee83d commit 6d1039a

File tree

6 files changed

+55
-39
lines changed

6 files changed

+55
-39
lines changed

.travis.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
language: php
22

33
php:
4-
- 5.3
4+
# - 5.3 # requires old distro, see below
55
- 5.4
66
- 5.5
77
- 5.6
8-
- 7
9-
- hhvm
8+
- 7.0
9+
- 7.1
10+
- 7.2
11+
- hhvm # ignore errors, see below
12+
13+
# lock distro so future defaults will not break the build
14+
dist: trusty
15+
16+
matrix:
17+
include:
18+
- php: 5.3
19+
dist: precise
20+
allow_failures:
21+
- php: hhvm
22+
23+
sudo: false
1024

1125
install:
12-
- composer install --prefer-source --no-interaction
26+
- composer install --no-interaction
1327

1428
script:
15-
- phpunit --coverage-text
29+
- vendor/bin/phpunit --coverage-text

README.md

Lines changed: 21 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,26 @@ $ composer require clue/mdns-react:~0.2.0
140141

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

144+
This project aims to run on any platform and thus does not require any PHP
145+
extensions and supports running on legacy PHP 5.3 through current PHP 7+ and
146+
HHVM.
147+
It's *highly recommended to use PHP 7+* for this project.
148+
149+
## Tests
150+
151+
To run the test suite, you first need to clone this repo and then install all
152+
dependencies [through Composer](https://getcomposer.org):
153+
154+
```bash
155+
$ composer install
156+
```
157+
158+
To run the test suite, go to the project root and run:
159+
160+
```bash
161+
$ php vendor/bin/phpunit
162+
```
163+
143164
## License
144165

145166
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)