Skip to content

Add test group to skip integration tests relying on internet connection #146

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

Merged
merged 2 commits into from
Jan 5, 2018
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,14 @@ To run the test suite, go to the project root and run:
$ php vendor/bin/phpunit
```

The test suite also contains a number of functional integration tests that rely
on a stable internet connection.
If you do not want to run these, they can simply be skipped like this:

```bash
$ php vendor/bin/phpunit --exclude-group internet
```

## License

MIT, see [LICENSE file](LICENSE).
17 changes: 1 addition & 16 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use React\Socket\SecureConnector;
use React\Socket\TcpConnector;

/** @group internet */
class IntegrationTest extends TestCase
{
const TIMEOUT = 5.0;
Expand Down Expand Up @@ -167,20 +168,4 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()
// if we reach this, then everything is good
$this->assertNull(null);
}

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

$connector = new TcpConnector($loop);
$pending = $connector->connect('8.8.8.8:80');

$loop->addTimer(0.001, function () use ($pending) {
$pending->cancel();
});

$pending->then($this->expectCallableNever(), $this->expectCallableOnce());

$loop->run();
}
}
42 changes: 42 additions & 0 deletions tests/TcpConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ public function connectionToEmptyPortShouldFail()
$loop->run();
}

/** @test */
public function connectionToTcpServerShouldAddResourceToLoop()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new TcpConnector($loop);

$server = new TcpServer(0, $loop);

$valid = false;
$loop->expects($this->once())->method('addWriteStream')->with($this->callback(function ($arg) use (&$valid) {
$valid = is_resource($arg);
return true;
}));
$connector->connect($server->getAddress());

$this->assertTrue($valid);
}

/** @test */
public function connectionToTcpServerShouldSucceed()
{
Expand Down Expand Up @@ -196,6 +214,30 @@ public function connectionToInvalidSchemeShouldFailImmediately()
);
}

/** @test */
public function cancellingConnectionShouldRemoveResourceFromLoopAndCloseResource()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new TcpConnector($loop);

$server = new TcpServer(0, $loop);

$loop->expects($this->once())->method('addWriteStream');
$promise = $connector->connect($server->getAddress());

$resource = null;
$valid = false;
$loop->expects($this->once())->method('removeWriteStream')->with($this->callback(function ($arg) use (&$resource, &$valid) {
$resource = $arg;
$valid = is_resource($arg);
return true;
}));
$promise->cancel();

$this->assertTrue($valid);
$this->assertFalse(is_resource($resource));
}

/** @test */
public function cancellingConnectionShouldRejectPromise()
{
Expand Down