Skip to content

Commit 9bdca13

Browse files
committed
Run tests on PHPUnit 9
1 parent 1b7acac commit 9bdca13

10 files changed

+119
-21
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
"react/promise-timer": "^1.1"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^5.0 || ^4.8"
24+
"phpunit/phpunit": "^9.0 || ^5.0 || ^4.8"
2525
}
2626
}

tests/ConnectionManagerDelayTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ class ConnectionManagerDelayTest extends TestCase
77
{
88
private $loop;
99

10-
public function setUp()
10+
/**
11+
* @before
12+
*/
13+
public function setUpLoop()
1114
{
1215
$this->loop = React\EventLoop\Factory::create();
1316
}

tests/ConnectionManagerRepeatTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ public function testTwoTriesWillStartTwoConnectionAttempts()
3131
$this->assertPromiseReject($promise);
3232
}
3333

34-
/**
35-
* @expectedException InvalidArgumentException
36-
*/
3734
public function testInvalidRepetitions()
3835
{
36+
$this->setExpectedException("InvalidArgumentException");
3937
$wont = new ConnectionManagerReject();
4038
$cm = new ConnectionManagerRepeat($wont, -3);
4139
}

tests/ConnectionManagerTimeoutTest.php

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

12-
public function setUp()
12+
/**
13+
* @before
14+
*/
15+
public function setUpLoop()
1316
{
1417
$this->loop = React\EventLoop\Factory::create();
1518
}

tests/Multiple/ConnectionManagerConcurrentTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66
class ConnectionManagerConcurrentTest extends TestCase
77
{
8-
/**
9-
* @expectedException InvalidArgumentException
10-
*/
118
public function testEmptyListsThrows()
129
{
10+
$this->setExpectedException("InvalidArgumentException");
1311
new ConnectionManagerConcurrent(array());
1412
}
1513

tests/Multiple/ConnectionManagerConsecutiveTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
class ConnectionManagerConsecutiveTest extends TestCase
88
{
9-
/**
10-
* @expectedException InvalidArgumentException
11-
*/
129
public function testEmptyListThrows()
1310
{
11+
$this->setExpectedException("InvalidArgumentException");
1412
new ConnectionManagerConsecutive(array());
1513
}
1614

tests/Multiple/ConnectionManagerRandomTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
class ConnectionManagerRandomTest extends TestCase
88
{
9-
/**
10-
* @expectedException InvalidArgumentException
11-
*/
129
public function testEmptyListThrows()
1310
{
11+
$this->setExpectedException("InvalidArgumentException");
1412
new ConnectionManagerRandom(array());
1513
}
1614

tests/Multiple/ConnectionManagerSelectiveTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ public function testInvalidUriWillAlwaysReject()
2121
$this->assertPromiseReject($promise);
2222
}
2323

24-
/**
25-
* @expectedException InvalidArgumentException
26-
*/
2724
public function testInvalidConnectorThrowsException()
2825
{
26+
27+
$this->setExpectedException("InvalidArgumentException");
2928
new ConnectionManagerSelective(array(
3029
'example.com' => false
3130
));
@@ -69,14 +68,13 @@ public function provideInvalidMatcher()
6968

7069
/**
7170
* @dataProvider provideInvalidMatcher
72-
* @expectedException InvalidArgumentException
7371
*
7472
* @param string $matcher
7573
*/
7674
public function testInvalidMatcherThrowsException($matcher)
7775
{
7876
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
79-
77+
$this->setExpectedException("InvalidArgumentException");
8078
new ConnectionManagerSelective(array(
8179
$matcher => $connector
8280
));

tests/TestCase.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
namespace ConnectionManager\Tests\Extra;
4+
5+
use React\Promise\Deferred;
6+
7+
class TestCase extends \PHPUnit\Framework\TestCase
8+
{
9+
protected function expectCallableOnce()
10+
{
11+
$mock = $this->createCallableMock();
12+
$mock
13+
->expects($this->once())
14+
->method('__invoke');
15+
16+
return $mock;
17+
}
18+
19+
protected function expectCallableNever()
20+
{
21+
$mock = $this->createCallableMock();
22+
$mock
23+
->expects($this->never())
24+
->method('__invoke');
25+
26+
return $mock;
27+
}
28+
29+
protected function expectCallableOnceParameter($type)
30+
{
31+
$mock = $this->createCallableMock();
32+
$mock
33+
->expects($this->once())
34+
->method('__invoke')
35+
->with($this->isInstanceOf($type));
36+
37+
return $mock;
38+
}
39+
40+
protected function expectCallableOnceValue($type)
41+
{
42+
$mock = $this->createCallableMock();
43+
$mock
44+
->expects($this->once())
45+
->method('__invoke')
46+
->with($this->isInstanceOf($type));
47+
48+
return $mock;
49+
}
50+
51+
/**
52+
* @link https://github.com/reactphp/react/blob/master/tests/React/Tests/Socket/TestCase.php (taken from reactphp/react)
53+
*/
54+
protected function createCallableMock()
55+
{
56+
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
57+
}
58+
59+
protected function createConnectionManagerMock($ret)
60+
{
61+
$mock = $this->getMockBuilder('React\Socket\ConnectorInterface')
62+
->getMock();
63+
64+
$deferred = new Deferred();
65+
$deferred->resolve($ret);
66+
67+
$mock
68+
->expects($this->any())
69+
->method('connect')
70+
->will($this->returnValue($deferred->promise()));
71+
72+
return $mock;
73+
}
74+
75+
protected function assertPromiseResolve($promise)
76+
{
77+
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
78+
79+
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());
80+
}
81+
82+
protected function assertPromiseReject($promise)
83+
{
84+
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
85+
86+
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
87+
}
88+
89+
public function setExpectedException($exception, $message = '', $code = 0)
90+
{
91+
if (method_exists($this, 'expectException')) {
92+
$this->expectException($exception);
93+
if ($message !== '') {
94+
$this->expectExceptionMessage($message);
95+
}
96+
$this->expectExceptionCode($code);
97+
} else {
98+
parent::setExpectedException($exception, $message, $code);
99+
}
100+
}
101+
102+
}

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
require __DIR__ . '/../vendor/autoload.php';
66

7-
class TestCase extends PHPUnit_Framework_TestCase
7+
class TestCase extends PHPUnit\Framework\TestCase
88
{
99
protected function expectCallableOnce()
1010
{

0 commit comments

Comments
 (0)