Skip to content

Commit 2d2743d

Browse files
authored
Merge pull request #12 from SimonFrings/tests
TestsClean up test suite, add .gitattributes to exclude dev files from exports and run tests on PHP 7.4 and simplify test matrix
2 parents fc2b914 + 6e34d8e commit 2d2743d

File tree

7 files changed

+52
-50
lines changed

7 files changed

+52
-50
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/.travis.yml export-ignore
4+
/examples/ export-ignore
5+
/phpunit.xml.dist export-ignore
6+
/tests/ export-ignore

.travis.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
language: php
22

3-
php:
4-
# - 5.3 # requires old distro, see below
5-
- 5.4
6-
- 5.5
7-
- 5.6
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
3+
# lock distro so new future defaults will not break the build
144
dist: trusty
155

166
matrix:
177
include:
188
- php: 5.3
199
dist: precise
10+
- php: 5.4
11+
- php: 5.5
12+
- php: 5.6
13+
- php: 7.0
14+
- php: 7.1
15+
- php: 7.2
16+
- php: 7.3
17+
- php: 7.4
18+
- php: hhvm-3.18
2019
allow_failures:
21-
- php: hhvm
20+
- php: hhvm-3.18
2221

2322
sudo: false
2423

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"autoload": {
1414
"psr-4": { "Clue\\React\\Mdns\\": "src/" }
1515
},
16+
"autoload-dev": {
17+
"psr-4": { "Clue\\Tests\\React\\Mdns\\": "tests/" }
18+
},
1619
"require": {
1720
"php": ">=5.3",
1821
"clue/multicast-react": "^1.0 || ^0.2",
@@ -21,6 +24,6 @@
2124
"react/promise": "^2.1 || ^1.2.1"
2225
},
2326
"require-dev": {
24-
"phpunit/phpunit": "^6.0 || ^5.7 || ^4.8.35"
27+
"phpunit/phpunit": "^9.0 || ^6.0 || ^5.7 || ^4.8.35"
2528
}
2629
}

phpunit.xml.dist

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="tests/bootstrap.php"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
>
3+
<phpunit bootstrap="vendor/autoload.php" colors="true">
94
<testsuites>
105
<testsuite name="mDNS React Test Suite">
116
<directory>./tests/</directory>

tests/FactoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Clue\Tests\React\Mdns;
4+
35
use Clue\React\Mdns\Factory;
46

57
class FactoryTest extends TestCase

tests/MulticastExecutorTest.php

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

3+
namespace Clue\Tests\React\Mdns;
4+
35
use Clue\React\Mdns\MulticastExecutor;
46
use Clue\React\Mdns\Factory;
57
use React\Dns\Query\Query;
68

79
class MulticastExecutorTest extends TestCase
810
{
9-
private $nameserver;
10-
private $loop;
11-
private $parser;
12-
private $dumper;
13-
private $sockets;
14-
15-
public function setUp()
16-
{
17-
$this->nameserver = Factory::DNS;
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();
21-
$this->sockets = $this->getMockBuilder('Clue\React\Multicast\Factory')->disableOriginalConstructor()->getMock();
22-
}
23-
2411
public function testQueryWillReturnPromise()
2512
{
26-
$executor = new MulticastExecutor($this->loop, $this->parser, $this->dumper, 5, $this->sockets);
13+
$nameserver = Factory::DNS;
14+
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
15+
$parser = $this->getMockBuilder('React\Dns\Protocol\Parser')->getMock();
16+
$dumper = $this->getMockBuilder('React\Dns\Protocol\BinaryDumper')->getMock();
17+
$sockets = $this->getMockBuilder('Clue\React\Multicast\Factory')->disableOriginalConstructor()->getMock();
18+
19+
$executor = new MulticastExecutor($loop, $parser, $dumper, 5, $sockets);
2720

2821
$socket = $this->getMockBuilder('React\Datagram\SocketInterface')->getMock();
2922

30-
$this->dumper->expects($this->once())->method('toBinary')->will($this->returnValue('message'));
31-
$this->sockets->expects($this->once())->method('createSender')->will($this->returnValue($socket));
23+
$dumper->expects($this->once())->method('toBinary')->will($this->returnValue('message'));
24+
$sockets->expects($this->once())->method('createSender')->will($this->returnValue($socket));
3225

33-
$socket->expects($this->once())->method('send')->with($this->equalTo('message'), $this->equalTo($this->nameserver));
26+
$socket->expects($this->once())->method('send')->with($this->equalTo('message'), $this->equalTo($nameserver));
3427

3528
$query = new Query('name', 'type', 'class', time());
3629

37-
$ret = $executor->query($this->nameserver, $query);
30+
$ret = $executor->query($nameserver, $query);
3831
$this->assertInstanceOf('React\Promise\PromiseInterface', $ret);
3932
}
4033

4134
public function testCancellingPromiseWillCloseSocketAndReject()
4235
{
43-
$executor = new MulticastExecutor($this->loop, $this->parser, $this->dumper, 5, $this->sockets);
36+
$nameserver = Factory::DNS;
37+
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
38+
$parser = $this->getMockBuilder('React\Dns\Protocol\Parser')->getMock();
39+
$dumper = $this->getMockBuilder('React\Dns\Protocol\BinaryDumper')->getMock();
40+
$sockets = $this->getMockBuilder('Clue\React\Multicast\Factory')->disableOriginalConstructor()->getMock();
41+
42+
$executor = new MulticastExecutor($loop, $parser, $dumper, 5, $sockets);
4443

4544
$socket = $this->getMockBuilder('React\Datagram\SocketInterface')->getMock();
4645
$socket->expects($this->once())->method('close');
47-
$socket->expects($this->once())->method('send')->with($this->equalTo('message'), $this->equalTo($this->nameserver));
48-
$this->sockets->expects($this->once())->method('createSender')->will($this->returnValue($socket));
46+
$socket->expects($this->once())->method('send')->with($this->equalTo('message'), $this->equalTo($nameserver));
47+
$sockets->expects($this->once())->method('createSender')->will($this->returnValue($socket));
4948

5049
// prefer newer EventLoop 1.0/0.5+ TimerInterface or fall back to legacy namespace
5150
$timer = $this->getMockBuilder(
5251
interface_exists('React\EventLoop\TimerInterface') ? 'React\EventLoop\TimerInterface' : 'React\EventLoop\Timer\TimerInterface'
5352
)->getMock();
5453

55-
$this->loop->expects($this->once())->method('addTimer')->willReturn($timer);
56-
$this->loop->expects($this->once())->method('cancelTimer')->with($timer);
54+
$loop->expects($this->once())->method('addTimer')->willReturn($timer);
55+
$loop->expects($this->once())->method('cancelTimer')->with($timer);
5756

58-
$this->dumper->expects($this->once())->method('toBinary')->will($this->returnValue('message'));
57+
$dumper->expects($this->once())->method('toBinary')->will($this->returnValue('message'));
5958

6059
$query = new Query('name', 'type', 'class', time());
6160

62-
$ret = $executor->query($this->nameserver, $query);
61+
$ret = $executor->query($nameserver, $query);
6362
$this->assertInstanceOf('React\Promise\CancellablePromiseInterface', $ret);
6463

6564
$ret->cancel();

tests/bootstrap.php renamed to tests/TestCase.php

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

3-
require __DIR__ . '/../vendor/autoload.php';
3+
namespace Clue\Tests\React\Mdns;
44

5-
error_reporting(-1);
6-
7-
class TestCase extends PHPUnit\Framework\TestCase
5+
class TestCase extends \PHPUnit\Framework\TestCase
86
{
97
protected function expectCallableOnce()
108
{

0 commit comments

Comments
 (0)