Skip to content

Commit

Permalink
Merge pull request #54 from clue-labs/integration-tests
Browse files Browse the repository at this point in the history
Add functional integration tests
  • Loading branch information
clue authored Dec 30, 2016
2 parents d61930e + 8740211 commit 5d9f7fc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ php:
sudo: false

install:
- composer install --prefer-source --no-interaction
- COMPOSER_ROOT_VERSION=`git describe --abbrev=0` composer install --no-interaction

script:
- phpunit --coverage-text
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and [`Stream`](https://github.com/reactphp/stream) components.
* [ConnectionInterface](#connectioninterface)
* [getRemoteAddress()](#getremoteaddress)
* [Install](#install)
* [Tests](#tests)
* [License](#license)

## Quickstart example
Expand Down Expand Up @@ -144,6 +145,23 @@ $ composer require react/socket:^0.4.4

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).
Because the test suite contains some circular dependencies, you may have to
manually specify the root package version like this:

```bash
$ COMPOSER_ROOT_VERSION=`git describe --abbrev=0` composer install
```

To run the test suite, you need PHPUnit. Go to the project root and run:

```bash
$ phpunit
```

## License

MIT, see [LICENSE file](LICENSE).
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"react/event-loop": "0.4.*|0.3.*",
"react/stream": "^0.4.2"
},
"require-dev": {
"react/socket-client": "^0.5.1",
"clue/block-react": "^1.1"
},
"autoload": {
"psr-4": {
"React\\Socket\\": "src"
Expand Down
46 changes: 46 additions & 0 deletions tests/FunctionalServerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace React\Tests\Socket;

use React\EventLoop\Factory;
use React\SocketClient\TcpConnector;
use React\Socket\Server;
use Clue\React\Block;

class FunctionalServerTest extends TestCase
{
public function testEmitsConnectionForNewConnection()
{
$loop = Factory::create();

$server = new Server($loop);
$server->on('connection', $this->expectCallableOnce());
$server->listen(0);
$port = $server->getPort();

$connector = new TcpConnector($loop);
$promise = $connector->create('127.0.0.1', $port);

$promise->then($this->expectCallableOnce());

Block\sleep(0.1, $loop);
}

public function testEmitsConnectionEvenIfConnectionIsCancelled()
{
$loop = Factory::create();

$server = new Server($loop);
$server->on('connection', $this->expectCallableOnce());
$server->listen(0);
$port = $server->getPort();

$connector = new TcpConnector($loop);
$promise = $connector->create('127.0.0.1', $port);
$promise->cancel();

$promise->then(null, $this->expectCallableOnce());

Block\sleep(0.1, $loop);
}
}

0 comments on commit 5d9f7fc

Please sign in to comment.