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

Run tests on PHPUnit 9 and clean up test suite #239

Merged
merged 2 commits into from
Jun 30, 2020
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"require-dev": {
"clue/block-react": "^1.2",
"phpunit/phpunit": "^7.5 || ^6.4 || ^5.7 || ^4.8.35",
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35",
"react/promise-stream": "^1.2"
},
"autoload": {
Expand Down
11 changes: 1 addition & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="React Test Suite">
<directory>./tests/</directory>
Expand Down
30 changes: 9 additions & 21 deletions tests/DnsConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class DnsConnectorTest extends TestCase
private $resolver;
private $connector;

public function setUp()
/**
* @before
*/
public function setUpMocks()
{
$this->tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$this->resolver = $this->getMockBuilder('React\Dns\Resolver\ResolverInterface')->getMock();
Expand Down Expand Up @@ -78,10 +81,6 @@ public function testRejectsImmediatelyIfUriIsInvalid()
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Connection failed
*/
public function testRejectsWithTcpConnectorRejectionIfGivenIp()
{
$promise = Promise\reject(new \RuntimeException('Connection failed'));
Expand All @@ -91,13 +90,10 @@ public function testRejectsWithTcpConnectorRejectionIfGivenIp()
$promise = $this->connector->connect('1.2.3.4:80');
$promise->cancel();

$this->setExpectedException('RuntimeException', 'Connection failed');
$this->throwRejection($promise);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Connection failed
*/
public function testRejectsWithTcpConnectorRejectionAfterDnsIsResolved()
{
$promise = Promise\reject(new \RuntimeException('Connection failed'));
Expand All @@ -107,13 +103,10 @@ public function testRejectsWithTcpConnectorRejectionAfterDnsIsResolved()
$promise = $this->connector->connect('example.com:80');
$promise->cancel();

$this->setExpectedException('RuntimeException', 'Connection failed');
$this->throwRejection($promise);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Connection to example.invalid:80 failed during DNS lookup: DNS error
*/
public function testSkipConnectionIfDnsFails()
{
$promise = Promise\reject(new \RuntimeException('DNS error'));
Expand All @@ -122,6 +115,7 @@ public function testSkipConnectionIfDnsFails()

$promise = $this->connector->connect('example.invalid:80');

$this->setExpectedException('RuntimeException', 'Connection to example.invalid:80 failed during DNS lookup: DNS error');
$this->throwRejection($promise);
}

Expand All @@ -138,10 +132,6 @@ public function testRejectionExceptionUsesPreviousExceptionIfDnsFails()
})->then(null, $this->expectCallableOnceWith($this->identicalTo($exception)));
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Connection to example.com:80 cancelled during DNS lookup
*/
public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
{
$pending = new Promise\Promise(function () { }, $this->expectCallableOnce());
Expand All @@ -151,6 +141,7 @@ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
$promise = $this->connector->connect('example.com:80');
$promise->cancel();

$this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled during DNS lookup');
$this->throwRejection($promise);
}

Expand All @@ -174,10 +165,6 @@ public function testCancelDuringTcpConnectionCancelsTcpConnectionAfterDnsIsResol
$promise->cancel();
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Connection cancelled
*/
public function testCancelDuringTcpConnectionCancelsTcpConnectionWithTcpRejectionAfterDnsIsResolved()
{
$first = new Deferred();
Expand All @@ -192,6 +179,7 @@ public function testCancelDuringTcpConnectionCancelsTcpConnectionWithTcpRejectio

$promise->cancel();

$this->setExpectedException('RuntimeException', 'Connection cancelled');
$this->throwRejection($promise);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/FunctionalSecureServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class FunctionalSecureServerTest extends TestCase
{
const TIMEOUT = 0.5;

public function setUp()
/**
* @before
*/
public function setUpSkipTest()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Not supported on legacy HHVM');
Expand Down
28 changes: 10 additions & 18 deletions tests/FunctionalTcpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testEmitsConnectionWithRemoteIp()

$peer = Block\await($peer, $loop, self::TIMEOUT);

$this->assertContains('127.0.0.1:', $peer);
$this->assertContainsString('127.0.0.1:', $peer);
}

public function testEmitsConnectionWithLocalIp()
Expand All @@ -110,7 +110,7 @@ public function testEmitsConnectionWithLocalIp()

$local = Block\await($peer, $loop, self::TIMEOUT);

$this->assertContains('127.0.0.1:', $local);
$this->assertContainsString('127.0.0.1:', $local);
$this->assertEquals($server->getAddress(), $local);
}

Expand All @@ -136,7 +136,7 @@ public function testEmitsConnectionWithLocalIpDespiteListeningOnAll()

$local = Block\await($peer, $loop, self::TIMEOUT);

$this->assertContains('127.0.0.1:', $local);
$this->assertContainsString('127.0.0.1:', $local);
}

public function testEmitsConnectionWithRemoteIpAfterConnectionIsClosedByPeer()
Expand All @@ -159,7 +159,7 @@ public function testEmitsConnectionWithRemoteIpAfterConnectionIsClosedByPeer()

$peer = Block\await($peer, $loop, self::TIMEOUT);

$this->assertContains('127.0.0.1:', $peer);
$this->assertContainsString('127.0.0.1:', $peer);
}

public function testEmitsConnectionWithRemoteNullAddressAfterConnectionIsClosedByServer()
Expand Down Expand Up @@ -255,7 +255,7 @@ public function testEmitsConnectionWithRemoteIpv6()

$peer = Block\await($peer, $loop, self::TIMEOUT);

$this->assertContains('[::1]:', $peer);
$this->assertContainsString('[::1]:', $peer);
}

public function testEmitsConnectionWithLocalIpv6()
Expand All @@ -281,7 +281,7 @@ public function testEmitsConnectionWithLocalIpv6()

$local = Block\await($peer, $loop, self::TIMEOUT);

$this->assertContains('[::1]:', $local);
$this->assertContainsString('[::1]:', $local);
$this->assertEquals($server->getAddress(), $local);
}

Expand Down Expand Up @@ -314,43 +314,35 @@ public function testEmitsConnectionWithInheritedContextOptions()
$this->assertEquals(array('socket' => array('backlog' => 4)), $all);
}

/**
* @expectedException InvalidArgumentException
*/
public function testFailsToListenOnInvalidUri()
{
$loop = Factory::create();

$this->setExpectedException('InvalidArgumentException');
new TcpServer('///', $loop);
}

/**
* @expectedException InvalidArgumentException
*/
public function testFailsToListenOnUriWithoutPort()
{
$loop = Factory::create();

$this->setExpectedException('InvalidArgumentException');
new TcpServer('127.0.0.1', $loop);
}

/**
* @expectedException InvalidArgumentException
*/
public function testFailsToListenOnUriWithWrongScheme()
{
$loop = Factory::create();

$this->setExpectedException('InvalidArgumentException');
new TcpServer('udp://127.0.0.1:0', $loop);
}

/**
* @expectedException InvalidArgumentException
*/
public function testFailsToListenOnUriWIthHostname()
{
$loop = Factory::create();

$this->setExpectedException('InvalidArgumentException');
new TcpServer('localhost:8080', $loop);
}
}
20 changes: 7 additions & 13 deletions tests/HappyEyeBallsConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class HappyEyeBallsConnectorTest extends TestCase
private $connector;
private $connection;

public function setUp()
/**
* @before
*/
public function setUpMocks()
{
$this->loop = new TimerSpeedUpEventLoop(new StreamSelectLoop());
$this->tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
Expand Down Expand Up @@ -222,10 +225,6 @@ public function testRejectsImmediatelyIfUriIsInvalid()
$this->loop->run();
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Connection failed
*/
public function testRejectsWithTcpConnectorRejectionIfGivenIp()
{
$that = $this;
Expand All @@ -240,13 +239,10 @@ public function testRejectsWithTcpConnectorRejectionIfGivenIp()
$that->throwRejection($promise);
});

$this->setExpectedException('RuntimeException', 'Connection failed');
$this->loop->run();
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Connection to example.invalid:80 failed during DNS lookup: DNS error
*/
public function testSkipConnectionIfDnsFails()
{
$that = $this;
Expand All @@ -259,13 +255,10 @@ public function testSkipConnectionIfDnsFails()
$that->throwRejection($promise);
});

$this->setExpectedException('RuntimeException', 'Connection to example.invalid:80 failed during DNS lookup: DNS error');
$this->loop->run();
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Connection to example.com:80 cancelled during DNS lookup
*/
public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
{
$that = $this;
Expand All @@ -281,6 +274,7 @@ public function testCancelDuringDnsCancelsDnsAndDoesNotStartTcpConnection()
$that->throwRejection($promise);
});

$this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled during DNS lookup');
$this->loop->run();
}

Expand Down
12 changes: 6 additions & 6 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public function gettingStuffFromGoogleShouldWork()

$conn = Block\await($connector->connect('google.com:80'), $loop);

$this->assertContains(':80', $conn->getRemoteAddress());
$this->assertContainsString(':80', $conn->getRemoteAddress());
$this->assertNotEquals('google.com:80', $conn->getRemoteAddress());

$conn->write("GET / HTTP/1.0\r\n\r\n");

$response = $this->buffer($conn, $loop, self::TIMEOUT);

$this->assertRegExp('#^HTTP/1\.0#', $response);
$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
}

/** @test */
Expand All @@ -49,7 +49,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork()

$response = $this->buffer($conn, $loop, self::TIMEOUT);

$this->assertRegExp('#^HTTP/1\.0#', $response);
$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
}

/** @test */
Expand Down Expand Up @@ -78,7 +78,7 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst()

$response = $this->buffer($conn, $loop, self::TIMEOUT);

$this->assertRegExp('#^HTTP/1\.0#', $response);
$this->assertMatchesRegExp('#^HTTP/1\.0#', $response);
}

/** @test */
Expand All @@ -89,14 +89,14 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork()

$conn = Block\await($connector->connect('google.com:443'), $loop);

$this->assertContains(':443', $conn->getRemoteAddress());
$this->assertContainsString(':443', $conn->getRemoteAddress());
$this->assertNotEquals('google.com:443', $conn->getRemoteAddress());

$conn->write("GET / HTTP/1.0\r\n\r\n");

$response = $this->buffer($conn, $loop, self::TIMEOUT);

$this->assertNotRegExp('#^HTTP/1\.0#', $response);
$this->assertDoesNotMatchRegExp('#^HTTP/1\.0#', $response);
}

public function testConnectingFailsIfConnectorUsesInvalidDnsResolverAddress()
Expand Down
Loading