Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
language: php

php:
- 5.3
# - 5.3 # requires old distro, see below
- 5.4
- 5.5
- 5.6
- 7
- hhvm
- 7.0
- 7.1
- 7.2
- hhvm # ignore errors, see below

# lock distro so future defaults will not break the build
dist: trusty

matrix:
include:
- php: 5.3
dist: precise
allow_failures:
- php: hhvm

sudo: false

install:
- composer install --prefer-source --no-interaction
- composer install --no-interaction

script:
- phpunit --coverage-text
- vendor/bin/phpunit --coverage-text
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ as defined in [RFC 6763](http://tools.ietf.org/html/rfc6763).
* [Promises](#promises)
* [Blocking](#blocking)
* [Install](#install)
* [Tests](#tests)
* [License](#license)
* [More](#more)

Expand Down Expand Up @@ -140,6 +141,26 @@ $ composer require clue/mdns-react:~0.2.0

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

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 7+ and
HHVM.
It's *highly recommended to use PHP 7+* for this project.

## Tests

To run the test suite, you first need to clone this repo and then install all
dependencies [through Composer](https://getcomposer.org):

```bash
$ composer install
```

To run the test suite, go to the project root and run:

```bash
$ php vendor/bin/phpunit
```

## License

MIT
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"react/event-loop": "~0.4.0|~0.3.0",
"react/dns": "~0.4.0|~0.3.0",
"react/promise": "^2.1 || ^1.2.1"
},
"require-dev": {
"phpunit/phpunit": "^6.0 || ^5.7 || ^4.8.35"
}
}
2 changes: 1 addition & 1 deletion tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class FactoryTest extends TestCase
{
public function testCreateResolver()
{
$loop = $this->getMock('React\EventLoop\LoopInterface');
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$factory = new Factory($loop);

$resolver = $factory->createResolver();
Expand Down
14 changes: 7 additions & 7 deletions tests/MulticastExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ class MulticastExecutorTest extends TestCase
public function setUp()
{
$this->nameserver = Factory::DNS;
$this->loop = $this->getMock('React\EventLoop\LoopInterface');
$this->parser = $this->getMock('React\Dns\Protocol\Parser');
$this->dumper = $this->getMock('React\Dns\Protocol\BinaryDumper');
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$this->parser = $this->getMockBuilder('React\Dns\Protocol\Parser')->getMock();
$this->dumper = $this->getMockBuilder('React\Dns\Protocol\BinaryDumper')->getMock();
$this->sockets = $this->getMockBuilder('Clue\React\Multicast\Factory')->disableOriginalConstructor()->getMock();
}

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

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

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

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

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

Expand All @@ -60,6 +60,6 @@ public function testCancellingPromiseWillCloseSocketAndReject()

$ret->cancel();

$ret->then($this->expectCallableNever(), $this->expectCallableOnceParameter('RuntimeException'));
$ret->then($this->expectCallableNever(), $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
}
}
30 changes: 4 additions & 26 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

error_reporting(-1);

class TestCase extends PHPUnit_Framework_TestCase
class TestCase extends PHPUnit\Framework\TestCase
{
protected function expectCallableOnce()
{
Expand All @@ -24,7 +24,7 @@ protected function expectCallableOnceWith($value)
$mock
->expects($this->once())
->method('__invoke')
->with($this->equalTo($value));
->with($value);

return $mock;
}
Expand All @@ -39,30 +39,8 @@ protected function expectCallableNever()
return $mock;
}

protected function expectCallableOnceParameter($type)
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->method('__invoke')
->with($this->isInstanceOf($type));

return $mock;
}

/**
* @link https://github.com/reactphp/react/blob/master/tests/React/Tests/Socket/TestCase.php (taken from reactphp/react)
*/
protected function createCallableMock()
{
return $this->getMock('CallableStub');
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}

class CallableStub
{
public function __invoke()
{
}
}