Skip to content

Commit

Permalink
Forward compatibility with PHPUnit 7 and PHPUnit 6
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Jul 18, 2019
1 parent 563cf67 commit 6b97970
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
},
"require-dev": {
"clue/block-react": "~1.0",
"phpunit/phpunit": "^5.0 || ^4.8"
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35"
}
}
14 changes: 11 additions & 3 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function testCreateClientLocalhostWithDefaultResolver()
$promise = $this->factory->createClient('localhost:12345');

$capturedClient = Block\await($promise, $this->loop);
$this->assertInstanceOf('React\Datagram\SocketInterface', $capturedClient);

$capturedClient->close();
}

Expand Down Expand Up @@ -131,11 +133,13 @@ public function testCreateClientWithHostnameWillUseResolver()
$client->close();
}

/**
* @expectedException RuntimeException
*/
public function testCreateClientWithHostnameWillRejectIfResolverRejects()
{
$this->resolver->expects($this->once())->method('resolve')->with('example.com')->willReturn(Promise\reject(new \RuntimeException('test')));

$this->setExpectedException('RuntimeException');
Block\await($this->factory->createClient('example.com:0'), $this->loop);
}

Expand All @@ -157,6 +161,9 @@ public function testCreateServerWithInvalidHostnameWillReject()
Block\await($this->factory->createServer('/////'), $this->loop);
}

/**
* @expectedException RuntimeException
*/
public function testCancelCreateClientWithCancellableHostnameResolver()
{
$promise = new Promise\Promise(function () { }, $this->expectCallableOnce());
Expand All @@ -165,10 +172,12 @@ public function testCancelCreateClientWithCancellableHostnameResolver()
$promise = $this->factory->createClient('example.com:0');
$promise->cancel();

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
}

/**
* @expectedException RuntimeException
*/
public function testCancelCreateClientWithUncancellableHostnameResolver()
{
$promise = $this->getMockBuilder('React\Promise\PromiseInterface')->getMock();
Expand All @@ -177,7 +186,6 @@ public function testCancelCreateClientWithUncancellableHostnameResolver()
$promise = $this->factory->createClient('example.com:0');
$promise->cancel();

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
}
}
12 changes: 9 additions & 3 deletions tests/SocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public function setUp()
$this->factory = new \React\Datagram\Factory($this->loop, $this->createResolverMock());
}

/**
* @doesNotPerformAssertions
*/
public function testCreateClientCloseWillNotBlock()
{
$promise = $this->factory->createClient('127.0.0.1:12345');
Expand All @@ -30,7 +33,7 @@ public function testCreateClientCloseWillNotBlock()
}

/**
*
* @doesNotPerformAssertions
* @param Socket $client
* @depends testCreateClientCloseWillNotBlock
*/
Expand All @@ -40,6 +43,9 @@ public function testClientCloseAgainWillNotBlock(Socket $client)
$this->loop->run();
}

/**
* @doesNotPerformAssertions
*/
public function testCreateClientEndWillNotBlock()
{
$promise = $this->factory->createClient('127.0.0.1:12345');
Expand All @@ -54,7 +60,7 @@ public function testCreateClientEndWillNotBlock()
}

/**
*
* @doesNotPerformAssertions
* @param Socket $client
* @depends testCreateClientEndWillNotBlock
*/
Expand All @@ -67,7 +73,7 @@ public function testClientEndAgainWillNotBlock(Socket $client)
}

/**
*
* @doesNotPerformAssertions
* @param Socket $client
* @depends testClientEndAgainWillNotBlock
*/
Expand Down
4 changes: 3 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace React\Tests\Datagram;

abstract class TestCase extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
protected function expectCallableOnce()
{
Expand Down

0 comments on commit 6b97970

Please sign in to comment.