diff --git a/.travis.yml b/.travis.yml index 57ab0985..56e51db4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index de6e8701..023b1bcf 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ and [`Stream`](https://github.com/reactphp/stream) components. * [ConnectionInterface](#connectioninterface) * [getRemoteAddress()](#getremoteaddress) * [Install](#install) +* [Tests](#tests) * [License](#license) ## Quickstart example @@ -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). diff --git a/composer.json b/composer.json index 98462141..a32e94e8 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/tests/FunctionalServerTest.php b/tests/FunctionalServerTest.php new file mode 100644 index 00000000..ab3bc807 --- /dev/null +++ b/tests/FunctionalServerTest.php @@ -0,0 +1,46 @@ +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); + } +}