Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functional integration tests #54

Merged
merged 2 commits into from
Dec 30, 2016
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
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);
}
}