Skip to content

Commit 5405f4e

Browse files
authored
Merge pull request #65 from SimonFrings/tests
Run tests on PHPUnit 9
2 parents 580d3cc + 1ea8564 commit 5405f4e

File tree

9 files changed

+53
-16
lines changed

9 files changed

+53
-16
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: php
33
# lock distro so new future defaults will not break the build
44
dist: trusty
55

6-
matrix:
6+
jobs:
77
include:
88
- php: 5.3
99
dist: precise
@@ -17,7 +17,7 @@ matrix:
1717
- php: 7.4
1818

1919
install:
20-
- composer install --no-interaction
20+
- composer install
2121

2222
script:
2323
- vendor/bin/phpunit --coverage-text

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
"clue/block-react": "^1.0 || ^0.3",
3232
"clue/caret-notation": "^0.2",
3333
"clue/tar-react": "^0.2",
34-
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35"
34+
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35"
3535
}
3636
}

tests/ClientTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ class ClientTest extends TestCase
1717
private $streamingParser;
1818
private $client;
1919

20-
public function setUp()
20+
/**
21+
* @before
22+
*/
23+
public function setUpClient()
2124
{
2225
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
2326
$this->browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock();
@@ -48,11 +51,9 @@ public function testCtor()
4851
new Client($this->loop);
4952
}
5053

51-
/**
52-
* @expectedException InvalidArgumentException
53-
*/
5454
public function testCtorWithInvalidUrlThrows()
5555
{
56+
$this->setExpectedException('InvalidArgumentException');
5657
new Client($this->loop, 'ftp://invalid');
5758
}
5859

tests/FunctionalClientTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class FunctionalClientTest extends TestCase
1111
{
1212
private $client;
1313

14-
public function setUp()
14+
/**
15+
* @before
16+
*/
17+
public function setUpClient()
1518
{
1619
$this->loop = LoopFactory::create();
1720
$this->client = new Client($this->loop);
@@ -349,12 +352,10 @@ public function testRemoveRunning($container)
349352
$this->assertEquals('', $ret);
350353
}
351354

352-
/**
353-
* @expectedException RuntimeException
354-
*/
355355
public function testContainerRemoveInvalid()
356356
{
357357
$promise = $this->client->containerRemove('invalid123');
358+
$this->setExpectedException('RuntimeException');
358359
Block\await($promise, $this->loop);
359360
}
360361

tests/Io/ReadableDemultiplexStreamTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class ReadableDemultiplexStreamTest extends TestCase
1111
private $stream;
1212
private $parser;
1313

14-
public function setUp()
14+
/**
15+
* @before
16+
*/
17+
public function setUpParser()
1518
{
1619
$this->stream = new ThroughStream();
1720
$this->parser = new ReadableDemultiplexStream($this->stream);

tests/Io/ReadableJsonStreamTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class ReadableJsonStreamTest extends TestCase
1111
private $stream;
1212
private $parser;
1313

14-
public function setUp()
14+
/**
15+
* @before
16+
*/
17+
public function setUpParser()
1518
{
1619
$this->stream = new ThroughStream();
1720
$this->parser = new ReadableJsonStream($this->stream);

tests/Io/ResponseParserTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ class ResponseParserTest extends TestCase
1010
{
1111
private $parser;
1212

13-
public function setUp()
13+
/**
14+
* @before
15+
*/
16+
public function setUpParser()
1417
{
1518
$this->parser = new ResponseParser();
1619
}

tests/Io/StreamingParserTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class StreamingParserTest extends TestCase
1313
{
1414
private $parser;
1515

16-
public function setUp()
16+
/**
17+
* @before
18+
*/
19+
public function setUpParser()
1720
{
1821
$this->parser = new StreamingParser();
1922
}

tests/TestCase.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ protected function expectCallableOnceParameter($type)
4848

4949
protected function createCallableMock()
5050
{
51-
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
51+
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
52+
// PHPUnit 8.5+
53+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
54+
} else {
55+
// legacy PHPUnit 4 - PHPUnit 8.4
56+
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
57+
}
5258
}
5359

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

7480
return $promise;
7581
}
82+
83+
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
84+
{
85+
if (method_exists($this, 'expectException')) {
86+
// PHPUnit 5.2+
87+
$this->expectException($exception);
88+
if ($exceptionMessage !== '') {
89+
$this->expectExceptionMessage($exceptionMessage);
90+
}
91+
if ($exceptionCode !== null) {
92+
$this->expectExceptionCode($exceptionCode);
93+
}
94+
} else {
95+
// legacy PHPUnit 4 - PHPUnit 5.1
96+
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
97+
}
98+
}
7699
}

0 commit comments

Comments
 (0)