diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a0c9bf06..6b99b47e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -45,4 +45,4 @@ jobs:
dependency-versions: "${{ matrix.dependencies }}"
- name: "Run PHPUnit"
- run: "vendor/bin/phpunit"
+ run: "vendor/bin/phpunit ${{ matrix.php-version < 7.3 && ' -c phpunit.xml.legacy' || '' }}"
diff --git a/composer.json b/composer.json
index db9f3c64..d9ce25fe 100644
--- a/composer.json
+++ b/composer.json
@@ -35,6 +35,6 @@
, "symfony/routing": "^2.6|^3.0|^4.0|^5.0|^6.0"
}
, "require-dev": {
- "phpunit/phpunit": "^7.5 || ^5.7 || ^4.8.36"
+ "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"
}
}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 846edc4f..e8ab6917 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,22 +1,19 @@
-
+
+
-
+
./tests/unit/
-
-
-
+
+
./src/
-
-
-
\ No newline at end of file
+
+
+
diff --git a/phpunit.xml.legacy b/phpunit.xml.legacy
new file mode 100644
index 00000000..f88bf5b7
--- /dev/null
+++ b/phpunit.xml.legacy
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+ ./tests/unit/
+
+
+
+
+ ./src/
+
+
+
diff --git a/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php b/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php
index e810e944..c8d724a6 100644
--- a/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php
+++ b/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php
@@ -12,7 +12,10 @@ abstract public function getConnectionClassString();
abstract public function getDecoratorClassString();
abstract public function getComponentClassString();
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpConnection() {
$this->_app = $this->getMockBuilder($this->getComponentClassString())->getMock();
$decorator = $this->getDecoratorClassString();
$this->_serv = new $decorator($this->_app);
diff --git a/tests/unit/AbstractConnectionDecoratorTest.php b/tests/unit/AbstractConnectionDecoratorTest.php
index c029e0f1..b3131d2e 100644
--- a/tests/unit/AbstractConnectionDecoratorTest.php
+++ b/tests/unit/AbstractConnectionDecoratorTest.php
@@ -12,7 +12,10 @@ class AbstractConnectionDecoratorTest extends TestCase {
protected $l1;
protected $l2;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpConnection() {
$this->mock = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
$this->l1 = new ConnectionDecorator($this->mock);
$this->l2 = new ConnectionDecorator($this->l1);
@@ -132,41 +135,44 @@ public function testDecoratorRecursionLevel2() {
}
public function testWarningGettingNothing() {
- if (!(error_reporting() & E_NOTICE)) {
- $this->markTestSkipped('Requires error_reporting to include E_NOTICE');
- }
-
- if (method_exists($this, 'expectException')) {
- $this->expectException(class_exists('PHPUnit\Framework\Error\Error') ? 'PHPUnit\Framework\Error\Error' : 'PHPUnit_Framework_Error');
- } else {
- $this->setExpectedException('PHPUnit_Framework_Error');
- }
+ $error = false;
+ set_error_handler(function () use (&$error) {
+ $error = true;
+ }, E_NOTICE);
+
$var = $this->mock->nonExistant;
+
+ restore_error_handler();
+
+ $this->assertTrue($error);
+ $this->assertNull($var);
}
public function testWarningGettingNothingLevel1() {
- if (!(error_reporting() & E_NOTICE)) {
- $this->markTestSkipped('Requires error_reporting to include E_NOTICE');
- }
-
- if (method_exists($this, 'expectException')) {
- $this->expectException(class_exists('PHPUnit\Framework\Error\Error') ? 'PHPUnit\Framework\Error\Error' : 'PHPUnit_Framework_Error');
- } else {
- $this->setExpectedException('PHPUnit_Framework_Error');
- }
+ $error = false;
+ set_error_handler(function () use (&$error) {
+ $error = true;
+ }, E_NOTICE);
+
$var = $this->l1->nonExistant;
+
+ restore_error_handler();
+
+ $this->assertTrue($error);
+ $this->assertNull($var);
}
public function testWarningGettingNothingLevel2() {
- if (!(error_reporting() & E_NOTICE)) {
- $this->markTestSkipped('Requires error_reporting to include E_NOTICE');
- }
-
- if (method_exists($this, 'expectException')) {
- $this->expectException(class_exists('PHPUnit\Framework\Error\Error') ? 'PHPUnit\Framework\Error\Error' : 'PHPUnit_Framework_Error');
- } else {
- $this->setExpectedException('PHPUnit_Framework_Error');
- }
+ $error = false;
+ set_error_handler(function () use (&$error) {
+ $error = true;
+ }, E_NOTICE);
+
$var = $this->l2->nonExistant;
+
+ restore_error_handler();
+
+ $this->assertTrue($error);
+ $this->assertNull($var);
}
}
diff --git a/tests/unit/Http/HttpRequestParserTest.php b/tests/unit/Http/HttpRequestParserTest.php
index d5e3540c..bf7ee1a9 100644
--- a/tests/unit/Http/HttpRequestParserTest.php
+++ b/tests/unit/Http/HttpRequestParserTest.php
@@ -9,7 +9,10 @@
class HttpRequestParserTest extends TestCase {
protected $parser;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpParser() {
$this->parser = new HttpRequestParser;
}
diff --git a/tests/unit/Http/HttpServerTest.php b/tests/unit/Http/HttpServerTest.php
index ac48a139..e322e990 100644
--- a/tests/unit/Http/HttpServerTest.php
+++ b/tests/unit/Http/HttpServerTest.php
@@ -6,8 +6,11 @@
* @covers Ratchet\Http\HttpServer
*/
class HttpServerTest extends AbstractMessageComponentTestCase {
- public function setUp() {
- parent::setUp();
+ /**
+ * @before
+ */
+ public function setUpConnection() {
+ parent::setUpConnection();
$this->_conn->httpHeadersReceived = true;
}
diff --git a/tests/unit/Http/OriginCheckTest.php b/tests/unit/Http/OriginCheckTest.php
index 222ea3df..3f804a04 100644
--- a/tests/unit/Http/OriginCheckTest.php
+++ b/tests/unit/Http/OriginCheckTest.php
@@ -8,11 +8,14 @@
class OriginCheckTest extends AbstractMessageComponentTestCase {
protected $_reqStub;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpConnection() {
$this->_reqStub = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock();
$this->_reqStub->expects($this->any())->method('getHeader')->will($this->returnValue(['localhost']));
- parent::setUp();
+ parent::setUpConnection();
assert($this->_serv instanceof OriginCheck);
$this->_serv->allowedOrigins[] = 'localhost';
diff --git a/tests/unit/Http/RouterTest.php b/tests/unit/Http/RouterTest.php
index 828597cd..3a73341c 100644
--- a/tests/unit/Http/RouterTest.php
+++ b/tests/unit/Http/RouterTest.php
@@ -18,7 +18,10 @@ class RouterTest extends TestCase {
protected $_uri;
protected $_req;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpConnection() {
$this->_conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
$this->_uri = $this->getMockBuilder('Psr\Http\Message\UriInterface')->getMock();
$this->_req = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock();
diff --git a/tests/unit/Server/EchoServerTest.php b/tests/unit/Server/EchoServerTest.php
index d2bc5efb..cfe72598 100644
--- a/tests/unit/Server/EchoServerTest.php
+++ b/tests/unit/Server/EchoServerTest.php
@@ -7,7 +7,10 @@ class EchoServerTest extends TestCase {
protected $_conn;
protected $_comp;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpServer() {
$this->_conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
$this->_comp = new EchoServer;
}
diff --git a/tests/unit/Server/FlashPolicyComponentTest.php b/tests/unit/Server/FlashPolicyComponentTest.php
index c1961104..3af90f8d 100644
--- a/tests/unit/Server/FlashPolicyComponentTest.php
+++ b/tests/unit/Server/FlashPolicyComponentTest.php
@@ -10,7 +10,10 @@ class FlashPolicyTest extends TestCase {
protected $_policy;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpPolicy() {
$this->_policy = new FlashPolicy();
}
diff --git a/tests/unit/Server/IoConnectionTest.php b/tests/unit/Server/IoConnectionTest.php
index 01c71502..84186a65 100644
--- a/tests/unit/Server/IoConnectionTest.php
+++ b/tests/unit/Server/IoConnectionTest.php
@@ -10,7 +10,10 @@ class IoConnectionTest extends TestCase {
protected $sock;
protected $conn;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpConnection() {
$this->sock = $this->getMockBuilder('React\\Socket\\ConnectionInterface')->getMock();
$this->conn = new IoConnection($this->sock);
}
diff --git a/tests/unit/Server/IoServerTest.php b/tests/unit/Server/IoServerTest.php
index d58a8733..6547fcc1 100644
--- a/tests/unit/Server/IoServerTest.php
+++ b/tests/unit/Server/IoServerTest.php
@@ -25,7 +25,10 @@ protected function tickLoop(LoopInterface $loop) {
$loop->run();
}
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpServer() {
$this->app = $this->getMockBuilder('Ratchet\\MessageComponentInterface')->getMock();
$loop = new StreamSelectLoop;
diff --git a/tests/unit/Server/IpBlackListComponentTest.php b/tests/unit/Server/IpBlackListComponentTest.php
index 3ca22fdd..7037a347 100644
--- a/tests/unit/Server/IpBlackListComponentTest.php
+++ b/tests/unit/Server/IpBlackListComponentTest.php
@@ -10,7 +10,10 @@ class IpBlackListTest extends TestCase {
protected $blocker;
protected $mock;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpBlocker() {
$this->mock = $this->getMockBuilder('Ratchet\\MessageComponentInterface')->getMock();
$this->blocker = new IpBlackList($this->mock);
}
diff --git a/tests/unit/Session/Serialize/PhpHandlerTest.php b/tests/unit/Session/Serialize/PhpHandlerTest.php
index 2a7586c4..71e14980 100644
--- a/tests/unit/Session/Serialize/PhpHandlerTest.php
+++ b/tests/unit/Session/Serialize/PhpHandlerTest.php
@@ -9,7 +9,10 @@
class PhpHandlerTest extends TestCase {
protected $_handler;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpHandler() {
$this->_handler = new PhpHandler;
}
diff --git a/tests/unit/Session/SessionComponentTest.php b/tests/unit/Session/SessionComponentTest.php
index e9d09459..98077dad 100644
--- a/tests/unit/Session/SessionComponentTest.php
+++ b/tests/unit/Session/SessionComponentTest.php
@@ -10,18 +10,24 @@
* @covers Ratchet\Session\Storage\Proxy\VirtualProxy
*/
class SessionProviderTest extends AbstractMessageComponentTestCase {
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpProvider() {
return $this->markTestIncomplete('Test needs to be updated for ini_set issue in PHP 7.2');
if (!class_exists('Symfony\Component\HttpFoundation\Session\Session')) {
return $this->markTestSkipped('Dependency of Symfony HttpFoundation failed');
}
- parent::setUp();
+ parent::setUpConnection();
$this->_serv = new SessionProvider($this->_app, new NullSessionHandler);
}
- public function tearDown() {
+ /**
+ * @after
+ */
+ public function tearDownHandler() {
ini_set('session.serialize_handler', 'php');
}
diff --git a/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php b/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php
index 1f6466e6..517f9c70 100644
--- a/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php
+++ b/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php
@@ -14,7 +14,10 @@ class VirtualSessionStoragePDOTest extends TestCase {
protected $_pathToDB;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpHandler() {
if (!extension_loaded('PDO') || !extension_loaded('pdo_sqlite')) {
return $this->markTestSkipped('Session test requires PDO and pdo_sqlite');
}
@@ -42,7 +45,10 @@ public function setUp() {
$this->_virtualSessionStorage->registerBag(new AttributeBag());
}
- public function tearDown() {
+ /**
+ * @after
+ */
+ public function tearDownHandler() {
unlink($this->_pathToDB);
}
diff --git a/tests/unit/Wamp/ServerProtocolTest.php b/tests/unit/Wamp/ServerProtocolTest.php
index 029538b3..4e4983fa 100644
--- a/tests/unit/Wamp/ServerProtocolTest.php
+++ b/tests/unit/Wamp/ServerProtocolTest.php
@@ -14,7 +14,10 @@ class ServerProtocolTest extends TestCase {
protected $_app;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpProtocol() {
$this->_app = new TestComponent;
$this->_comp = new ServerProtocol($this->_app);
}
diff --git a/tests/unit/Wamp/TopicManagerTest.php b/tests/unit/Wamp/TopicManagerTest.php
index 18d39a4c..b0509872 100644
--- a/tests/unit/Wamp/TopicManagerTest.php
+++ b/tests/unit/Wamp/TopicManagerTest.php
@@ -19,7 +19,10 @@ class TopicManagerTest extends TestCase {
*/
private $conn;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpManager() {
$this->conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock();
$this->mock = $this->getMockBuilder('Ratchet\Wamp\WampServerInterface')->getMock();
$this->mngr = new TopicManager($this->mock);
@@ -214,7 +217,13 @@ public function testOnErrorBubbles() {
}
public function testGetSubProtocolsReturnsArray() {
- $this->assertInternalType('array', $this->mngr->getSubProtocols());
+ if (method_exists($this, 'assertIsArray')) {
+ // PHPUnit 7+
+ $this->assertIsArray($this->mngr->getSubProtocols());
+ } else {
+ // legacy PHPUnit
+ $this->assertInternalType('array', $this->mngr->getSubProtocols());
+ }
}
public function testGetSubProtocolsBubbles() {
diff --git a/tests/unit/Wamp/WampConnectionTest.php b/tests/unit/Wamp/WampConnectionTest.php
index d885974e..a51051bc 100644
--- a/tests/unit/Wamp/WampConnectionTest.php
+++ b/tests/unit/Wamp/WampConnectionTest.php
@@ -10,7 +10,10 @@ class WampConnectionTest extends TestCase {
protected $conn;
protected $mock;
- public function setUp() {
+ /**
+ * @before
+ */
+ public function setUpConnection() {
$this->mock = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock();
$this->conn = new WampConnection($this->mock);
}
diff --git a/tests/unit/Wamp/WampServerTest.php b/tests/unit/Wamp/WampServerTest.php
index 9988f5ba..62d29c30 100644
--- a/tests/unit/Wamp/WampServerTest.php
+++ b/tests/unit/Wamp/WampServerTest.php
@@ -34,7 +34,13 @@ public function testOnMessageToEvent() {
public function testGetSubProtocols() {
// todo: could expand on this
- $this->assertInternalType('array', $this->_serv->getSubProtocols());
+ if (method_exists($this, 'assertIsArray')) {
+ // PHPUnit 7+
+ $this->assertIsArray($this->_serv->getSubProtocols());
+ } else {
+ // legacy PHPUnit
+ $this->assertInternalType('array', $this->_serv->getSubProtocols());
+ }
}
public function testConnectionClosesOnInvalidJson() {