Skip to content

Commit fc6cdf4

Browse files
authored
Merge pull request #1093 from clue-labs/phpunit9
Update tests to support PHPUnit ^9.6
2 parents 0caf171 + 12728b4 commit fc6cdf4

22 files changed

Lines changed: 155 additions & 68 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ jobs:
4545
dependency-versions: "${{ matrix.dependencies }}"
4646

4747
- name: "Run PHPUnit"
48-
run: "vendor/bin/phpunit"
48+
run: "vendor/bin/phpunit ${{ matrix.php-version < 7.3 && ' -c phpunit.xml.legacy' || '' }}"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
, "symfony/routing": "^2.6|^3.0|^4.0|^5.0|^6.0"
3636
}
3737
, "require-dev": {
38-
"phpunit/phpunit": "^7.5 || ^5.7 || ^4.8.36"
38+
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"
3939
}
4040
}

phpunit.xml.dist

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
forceCoversAnnotation="true"
4-
bootstrap="tests/bootstrap.php"
5-
colors="true"
6-
backupGlobals="false"
7-
backupStaticAttributes="false"
8-
stopOnError="false"
9-
>
102

3+
<!-- PHPUnit configuration file with new format for PHPUnit 9.6+ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
6+
bootstrap="tests/bootstrap.php"
7+
cacheResult="false"
8+
colors="true">
119
<testsuites>
12-
<testsuite name="unit">
10+
<testsuite name="Ratchet test suite">
1311
<directory>./tests/unit/</directory>
1412
</testsuite>
1513
</testsuites>
16-
17-
<filter>
18-
<whitelist>
14+
<coverage>
15+
<include>
1916
<directory>./src/</directory>
20-
</whitelist>
21-
</filter>
22-
</phpunit>
17+
</include>
18+
</coverage>
19+
</phpunit>

phpunit.xml.legacy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
6+
bootstrap="tests/bootstrap.php"
7+
colors="true">
8+
<testsuites>
9+
<testsuite name="Ratchet Test Suite">
10+
<directory>./tests/unit/</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist>
15+
<directory>./src/</directory>
16+
</whitelist>
17+
</filter>
18+
</phpunit>

tests/helpers/Ratchet/AbstractMessageComponentTestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ abstract public function getConnectionClassString();
1212
abstract public function getDecoratorClassString();
1313
abstract public function getComponentClassString();
1414

15-
public function setUp() {
15+
/**
16+
* @before
17+
*/
18+
public function setUpConnection() {
1619
$this->_app = $this->getMockBuilder($this->getComponentClassString())->getMock();
1720
$decorator = $this->getDecoratorClassString();
1821
$this->_serv = new $decorator($this->_app);

tests/unit/AbstractConnectionDecoratorTest.php

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class AbstractConnectionDecoratorTest extends TestCase {
1212
protected $l1;
1313
protected $l2;
1414

15-
public function setUp() {
15+
/**
16+
* @before
17+
*/
18+
public function setUpConnection() {
1619
$this->mock = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
1720
$this->l1 = new ConnectionDecorator($this->mock);
1821
$this->l2 = new ConnectionDecorator($this->l1);
@@ -132,41 +135,44 @@ public function testDecoratorRecursionLevel2() {
132135
}
133136

134137
public function testWarningGettingNothing() {
135-
if (!(error_reporting() & E_NOTICE)) {
136-
$this->markTestSkipped('Requires error_reporting to include E_NOTICE');
137-
}
138-
139-
if (method_exists($this, 'expectException')) {
140-
$this->expectException(class_exists('PHPUnit\Framework\Error\Error') ? 'PHPUnit\Framework\Error\Error' : 'PHPUnit_Framework_Error');
141-
} else {
142-
$this->setExpectedException('PHPUnit_Framework_Error');
143-
}
138+
$error = false;
139+
set_error_handler(function () use (&$error) {
140+
$error = true;
141+
}, E_NOTICE);
142+
144143
$var = $this->mock->nonExistant;
144+
145+
restore_error_handler();
146+
147+
$this->assertTrue($error);
148+
$this->assertNull($var);
145149
}
146150

147151
public function testWarningGettingNothingLevel1() {
148-
if (!(error_reporting() & E_NOTICE)) {
149-
$this->markTestSkipped('Requires error_reporting to include E_NOTICE');
150-
}
151-
152-
if (method_exists($this, 'expectException')) {
153-
$this->expectException(class_exists('PHPUnit\Framework\Error\Error') ? 'PHPUnit\Framework\Error\Error' : 'PHPUnit_Framework_Error');
154-
} else {
155-
$this->setExpectedException('PHPUnit_Framework_Error');
156-
}
152+
$error = false;
153+
set_error_handler(function () use (&$error) {
154+
$error = true;
155+
}, E_NOTICE);
156+
157157
$var = $this->l1->nonExistant;
158+
159+
restore_error_handler();
160+
161+
$this->assertTrue($error);
162+
$this->assertNull($var);
158163
}
159164

160165
public function testWarningGettingNothingLevel2() {
161-
if (!(error_reporting() & E_NOTICE)) {
162-
$this->markTestSkipped('Requires error_reporting to include E_NOTICE');
163-
}
164-
165-
if (method_exists($this, 'expectException')) {
166-
$this->expectException(class_exists('PHPUnit\Framework\Error\Error') ? 'PHPUnit\Framework\Error\Error' : 'PHPUnit_Framework_Error');
167-
} else {
168-
$this->setExpectedException('PHPUnit_Framework_Error');
169-
}
166+
$error = false;
167+
set_error_handler(function () use (&$error) {
168+
$error = true;
169+
}, E_NOTICE);
170+
170171
$var = $this->l2->nonExistant;
172+
173+
restore_error_handler();
174+
175+
$this->assertTrue($error);
176+
$this->assertNull($var);
171177
}
172178
}

tests/unit/Http/HttpRequestParserTest.php

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

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

tests/unit/Http/HttpServerTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
* @covers Ratchet\Http\HttpServer
77
*/
88
class HttpServerTest extends AbstractMessageComponentTestCase {
9-
public function setUp() {
10-
parent::setUp();
9+
/**
10+
* @before
11+
*/
12+
public function setUpConnection() {
13+
parent::setUpConnection();
1114
$this->_conn->httpHeadersReceived = true;
1215
}
1316

tests/unit/Http/OriginCheckTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
class OriginCheckTest extends AbstractMessageComponentTestCase {
99
protected $_reqStub;
1010

11-
public function setUp() {
11+
/**
12+
* @before
13+
*/
14+
public function setUpConnection() {
1215
$this->_reqStub = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock();
1316
$this->_reqStub->expects($this->any())->method('getHeader')->will($this->returnValue(['localhost']));
1417

15-
parent::setUp();
18+
parent::setUpConnection();
1619

1720
assert($this->_serv instanceof OriginCheck);
1821
$this->_serv->allowedOrigins[] = 'localhost';

tests/unit/Http/RouterTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ class RouterTest extends TestCase {
1818
protected $_uri;
1919
protected $_req;
2020

21-
public function setUp() {
21+
/**
22+
* @before
23+
*/
24+
public function setUpConnection() {
2225
$this->_conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
2326
$this->_uri = $this->getMockBuilder('Psr\Http\Message\UriInterface')->getMock();
2427
$this->_req = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock();

0 commit comments

Comments
 (0)