Skip to content

Commit 5d9f7fc

Browse files
authored
Merge pull request #54 from clue-labs/integration-tests
Add functional integration tests
2 parents d61930e + 8740211 commit 5d9f7fc

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ php:
1111
sudo: false
1212

1313
install:
14-
- composer install --prefer-source --no-interaction
14+
- COMPOSER_ROOT_VERSION=`git describe --abbrev=0` composer install --no-interaction
1515

1616
script:
1717
- phpunit --coverage-text

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and [`Stream`](https://github.com/reactphp/stream) components.
1616
* [ConnectionInterface](#connectioninterface)
1717
* [getRemoteAddress()](#getremoteaddress)
1818
* [Install](#install)
19+
* [Tests](#tests)
1920
* [License](#license)
2021

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

145146
More details about version upgrades can be found in the [CHANGELOG](CHANGELOG.md).
146147

148+
## Tests
149+
150+
To run the test suite, you first need to clone this repo and then install all
151+
dependencies [through Composer](http://getcomposer.org).
152+
Because the test suite contains some circular dependencies, you may have to
153+
manually specify the root package version like this:
154+
155+
```bash
156+
$ COMPOSER_ROOT_VERSION=`git describe --abbrev=0` composer install
157+
```
158+
159+
To run the test suite, you need PHPUnit. Go to the project root and run:
160+
161+
```bash
162+
$ phpunit
163+
```
164+
147165
## License
148166

149167
MIT, see [LICENSE file](LICENSE).

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"react/event-loop": "0.4.*|0.3.*",
1010
"react/stream": "^0.4.2"
1111
},
12+
"require-dev": {
13+
"react/socket-client": "^0.5.1",
14+
"clue/block-react": "^1.1"
15+
},
1216
"autoload": {
1317
"psr-4": {
1418
"React\\Socket\\": "src"

tests/FunctionalServerTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace React\Tests\Socket;
4+
5+
use React\EventLoop\Factory;
6+
use React\SocketClient\TcpConnector;
7+
use React\Socket\Server;
8+
use Clue\React\Block;
9+
10+
class FunctionalServerTest extends TestCase
11+
{
12+
public function testEmitsConnectionForNewConnection()
13+
{
14+
$loop = Factory::create();
15+
16+
$server = new Server($loop);
17+
$server->on('connection', $this->expectCallableOnce());
18+
$server->listen(0);
19+
$port = $server->getPort();
20+
21+
$connector = new TcpConnector($loop);
22+
$promise = $connector->create('127.0.0.1', $port);
23+
24+
$promise->then($this->expectCallableOnce());
25+
26+
Block\sleep(0.1, $loop);
27+
}
28+
29+
public function testEmitsConnectionEvenIfConnectionIsCancelled()
30+
{
31+
$loop = Factory::create();
32+
33+
$server = new Server($loop);
34+
$server->on('connection', $this->expectCallableOnce());
35+
$server->listen(0);
36+
$port = $server->getPort();
37+
38+
$connector = new TcpConnector($loop);
39+
$promise = $connector->create('127.0.0.1', $port);
40+
$promise->cancel();
41+
42+
$promise->then(null, $this->expectCallableOnce());
43+
44+
Block\sleep(0.1, $loop);
45+
}
46+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy