Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' || '' }}"
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
27 changes: 12 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
forceCoversAnnotation="true"
bootstrap="tests/bootstrap.php"
colors="true"
backupGlobals="false"
backupStaticAttributes="false"
stopOnError="false"
>

<!-- PHPUnit configuration file with new format for PHPUnit 9.6+ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheResult="false"
colors="true">
<testsuites>
<testsuite name="unit">
<testsuite name="Ratchet test suite">
<directory>./tests/unit/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
</include>
</coverage>
</phpunit>
18 changes: 18 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true">
<testsuites>
<testsuite name="Ratchet Test Suite">
<directory>./tests/unit/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
5 changes: 4 additions & 1 deletion tests/helpers/Ratchet/AbstractMessageComponentTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
62 changes: 34 additions & 28 deletions tests/unit/AbstractConnectionDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
5 changes: 4 additions & 1 deletion tests/unit/Http/HttpRequestParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
class HttpRequestParserTest extends TestCase {
protected $parser;

public function setUp() {
/**
* @before
*/
public function setUpParser() {
$this->parser = new HttpRequestParser;
}

Expand Down
7 changes: 5 additions & 2 deletions tests/unit/Http/HttpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 5 additions & 2 deletions tests/unit/Http/OriginCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Http/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Server/EchoServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Server/FlashPolicyComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class FlashPolicyTest extends TestCase {

protected $_policy;

public function setUp() {
/**
* @before
*/
public function setUpPolicy() {
$this->_policy = new FlashPolicy();
}

Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Server/IoConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Server/IoServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Server/IpBlackListComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Session/Serialize/PhpHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
class PhpHandlerTest extends TestCase {
protected $_handler;

public function setUp() {
/**
* @before
*/
public function setUpHandler() {
$this->_handler = new PhpHandler;
}

Expand Down
12 changes: 9 additions & 3 deletions tests/unit/Session/SessionComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
10 changes: 8 additions & 2 deletions tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -42,7 +45,10 @@ public function setUp() {
$this->_virtualSessionStorage->registerBag(new AttributeBag());
}

public function tearDown() {
/**
* @after
*/
public function tearDownHandler() {
unlink($this->_pathToDB);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Wamp/ServerProtocolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 11 additions & 2 deletions tests/unit/Wamp/TopicManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Wamp/WampConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading