Skip to content

Commit

Permalink
Merge pull request #65 from SimonFrings/tests
Browse files Browse the repository at this point in the history
Run tests on PHPUnit 9
  • Loading branch information
clue authored Jul 30, 2020
2 parents 580d3cc + 1ea8564 commit 5405f4e
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: php
# lock distro so new future defaults will not break the build
dist: trusty

matrix:
jobs:
include:
- php: 5.3
dist: precise
Expand All @@ -17,7 +17,7 @@ matrix:
- php: 7.4

install:
- composer install --no-interaction
- composer install

script:
- vendor/bin/phpunit --coverage-text
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"clue/block-react": "^1.0 || ^0.3",
"clue/caret-notation": "^0.2",
"clue/tar-react": "^0.2",
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35"
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35"
}
}
9 changes: 5 additions & 4 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class ClientTest extends TestCase
private $streamingParser;
private $client;

public function setUp()
/**
* @before
*/
public function setUpClient()
{
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$this->browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
Expand Down Expand Up @@ -48,11 +51,9 @@ public function testCtor()
new Client($this->loop);
}

/**
* @expectedException InvalidArgumentException
*/
public function testCtorWithInvalidUrlThrows()
{
$this->setExpectedException('InvalidArgumentException');
new Client($this->loop, 'ftp://invalid');
}

Expand Down
9 changes: 5 additions & 4 deletions tests/FunctionalClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class FunctionalClientTest extends TestCase
{
private $client;

public function setUp()
/**
* @before
*/
public function setUpClient()
{
$this->loop = LoopFactory::create();
$this->client = new Client($this->loop);
Expand Down Expand Up @@ -349,12 +352,10 @@ public function testRemoveRunning($container)
$this->assertEquals('', $ret);
}

/**
* @expectedException RuntimeException
*/
public function testContainerRemoveInvalid()
{
$promise = $this->client->containerRemove('invalid123');
$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Io/ReadableDemultiplexStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class ReadableDemultiplexStreamTest extends TestCase
private $stream;
private $parser;

public function setUp()
/**
* @before
*/
public function setUpParser()
{
$this->stream = new ThroughStream();
$this->parser = new ReadableDemultiplexStream($this->stream);
Expand Down
5 changes: 4 additions & 1 deletion tests/Io/ReadableJsonStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class ReadableJsonStreamTest extends TestCase
private $stream;
private $parser;

public function setUp()
/**
* @before
*/
public function setUpParser()
{
$this->stream = new ThroughStream();
$this->parser = new ReadableJsonStream($this->stream);
Expand Down
5 changes: 4 additions & 1 deletion tests/Io/ResponseParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class ResponseParserTest extends TestCase
{
private $parser;

public function setUp()
/**
* @before
*/
public function setUpParser()
{
$this->parser = new ResponseParser();
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Io/StreamingParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class StreamingParserTest extends TestCase
{
private $parser;

public function setUp()
/**
* @before
*/
public function setUpParser()
{
$this->parser = new StreamingParser();
}
Expand Down
25 changes: 24 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ protected function expectCallableOnceParameter($type)

protected function createCallableMock()
{
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
// PHPUnit 8.5+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
} else {
// legacy PHPUnit 4 - PHPUnit 8.4
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}

protected function expectPromiseResolve($promise)
Expand All @@ -73,4 +79,21 @@ protected function expectPromiseReject($promise)

return $promise;
}

public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5.2+
$this->expectException($exception);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
} else {
// legacy PHPUnit 4 - PHPUnit 5.1
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}
}

0 comments on commit 5405f4e

Please sign in to comment.