From 5e4a74283a8b3b513fc5a1db603360e887a86709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 11 Aug 2023 12:48:49 +0200 Subject: [PATCH 1/4] Update tests to support PHPUnit ^5.7 --- composer.json | 2 +- .../AbstractMessageComponentTestCase.php | 6 +-- .../unit/AbstractConnectionDecoratorTest.php | 6 +-- tests/unit/Http/HttpRequestParserTest.php | 6 +-- tests/unit/Http/HttpServerTest.php | 6 +-- tests/unit/Http/OriginCheckTest.php | 9 +++-- tests/unit/Http/RouterTest.php | 37 ++++++++++--------- tests/unit/Server/EchoServerTest.php | 2 +- .../unit/Server/FlashPolicyComponentTest.php | 8 ++-- tests/unit/Server/IoConnectionTest.php | 2 +- tests/unit/Server/IoServerTest.php | 20 +++++----- .../unit/Server/IpBlackListComponentTest.php | 6 +-- tests/unit/Session/SessionComponentTest.php | 26 ++++++------- tests/unit/Wamp/ServerProtocolTest.php | 18 ++++----- tests/unit/Wamp/TopicManagerTest.php | 6 +-- tests/unit/Wamp/TopicTest.php | 18 ++++----- tests/unit/Wamp/WampConnectionTest.php | 4 +- tests/unit/Wamp/WampServerTest.php | 6 +-- 18 files changed, 96 insertions(+), 92 deletions(-) diff --git a/composer.json b/composer.json index ba788169..06e78c32 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ , "symfony/routing": "^2.6|^3.0|^4.0|^5.0|^6.0" } , "require-dev": { - "phpunit/phpunit": "~4.8", + "phpunit/phpunit": "^5.7 || ^4.8.36", "psr/http-message": "~1.0.1" } } diff --git a/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php b/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php index 8c298e5b..a50cde53 100644 --- a/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php +++ b/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php @@ -11,10 +11,10 @@ abstract public function getDecoratorClassString(); abstract public function getComponentClassString(); public function setUp() { - $this->_app = $this->getMock($this->getComponentClassString()); + $this->_app = $this->getMockBuilder($this->getComponentClassString())->getMock(); $decorator = $this->getDecoratorClassString(); $this->_serv = new $decorator($this->_app); - $this->_conn = $this->getMock('\Ratchet\ConnectionInterface'); + $this->_conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock(); $this->doOpen($this->_conn); } @@ -29,7 +29,7 @@ public function isExpectedConnection() { public function testOpen() { $this->_app->expects($this->once())->method('onOpen')->with($this->isExpectedConnection()); - $this->doOpen($this->getMock('\Ratchet\ConnectionInterface')); + $this->doOpen($this->getMockBuilder('Ratchet\ConnectionInterface')->getMock()); } public function testOnClose() { diff --git a/tests/unit/AbstractConnectionDecoratorTest.php b/tests/unit/AbstractConnectionDecoratorTest.php index 87c46ff8..e699c9f8 100644 --- a/tests/unit/AbstractConnectionDecoratorTest.php +++ b/tests/unit/AbstractConnectionDecoratorTest.php @@ -12,7 +12,7 @@ class AbstractConnectionDecoratorTest extends \PHPUnit_Framework_TestCase { protected $l2; public function setUp() { - $this->mock = $this->getMock('\Ratchet\ConnectionInterface'); + $this->mock = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock(); $this->l1 = new ConnectionDecorator($this->mock); $this->l2 = new ConnectionDecorator($this->l1); } @@ -84,7 +84,7 @@ public function testUnsetLevel2() { } public function testGetConnection() { - $class = new \ReflectionClass('\\Ratchet\\AbstractConnectionDecorator'); + $class = new \ReflectionClass('Ratchet\\AbstractConnectionDecorator'); $method = $class->getMethod('getConnection'); $method->setAccessible(true); @@ -94,7 +94,7 @@ public function testGetConnection() { } public function testGetConnectionLevel2() { - $class = new \ReflectionClass('\\Ratchet\\AbstractConnectionDecorator'); + $class = new \ReflectionClass('Ratchet\\AbstractConnectionDecorator'); $method = $class->getMethod('getConnection'); $method->setAccessible(true); diff --git a/tests/unit/Http/HttpRequestParserTest.php b/tests/unit/Http/HttpRequestParserTest.php index 6af8402c..9008afe3 100644 --- a/tests/unit/Http/HttpRequestParserTest.php +++ b/tests/unit/Http/HttpRequestParserTest.php @@ -30,7 +30,7 @@ public function testIsEom($expected, $message) { } public function testBufferOverflowResponse() { - $conn = $this->getMock('\Ratchet\ConnectionInterface'); + $conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock(); $this->parser->maxSize = 20; @@ -42,9 +42,9 @@ public function testBufferOverflowResponse() { } public function testReturnTypeIsRequest() { - $conn = $this->getMock('\Ratchet\ConnectionInterface'); + $conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock(); $return = $this->parser->onMessage($conn, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n"); - $this->assertInstanceOf('\Psr\Http\Message\RequestInterface', $return); + $this->assertInstanceOf('Psr\Http\Message\RequestInterface', $return); } } diff --git a/tests/unit/Http/HttpServerTest.php b/tests/unit/Http/HttpServerTest.php index 7041d66b..ac48a139 100644 --- a/tests/unit/Http/HttpServerTest.php +++ b/tests/unit/Http/HttpServerTest.php @@ -12,15 +12,15 @@ public function setUp() { } public function getConnectionClassString() { - return '\Ratchet\ConnectionInterface'; + return 'Ratchet\ConnectionInterface'; } public function getDecoratorClassString() { - return '\Ratchet\Http\HttpServer'; + return 'Ratchet\Http\HttpServer'; } public function getComponentClassString() { - return '\Ratchet\Http\HttpServerInterface'; + return 'Ratchet\Http\HttpServerInterface'; } public function testOpen() { diff --git a/tests/unit/Http/OriginCheckTest.php b/tests/unit/Http/OriginCheckTest.php index c1c40120..222ea3df 100644 --- a/tests/unit/Http/OriginCheckTest.php +++ b/tests/unit/Http/OriginCheckTest.php @@ -9,11 +9,12 @@ class OriginCheckTest extends AbstractMessageComponentTestCase { protected $_reqStub; public function setUp() { - $this->_reqStub = $this->getMock('Psr\Http\Message\RequestInterface'); + $this->_reqStub = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); $this->_reqStub->expects($this->any())->method('getHeader')->will($this->returnValue(['localhost'])); parent::setUp(); + assert($this->_serv instanceof OriginCheck); $this->_serv->allowedOrigins[] = 'localhost'; } @@ -22,15 +23,15 @@ protected function doOpen($conn) { } public function getConnectionClassString() { - return '\Ratchet\ConnectionInterface'; + return 'Ratchet\ConnectionInterface'; } public function getDecoratorClassString() { - return '\Ratchet\Http\OriginCheck'; + return 'Ratchet\Http\OriginCheck'; } public function getComponentClassString() { - return '\Ratchet\Http\HttpServerInterface'; + return 'Ratchet\Http\HttpServerInterface'; } public function testCloseOnNonMatchingOrigin() { diff --git a/tests/unit/Http/RouterTest.php b/tests/unit/Http/RouterTest.php index 1ca4cbc8..93a17836 100644 --- a/tests/unit/Http/RouterTest.php +++ b/tests/unit/Http/RouterTest.php @@ -19,18 +19,18 @@ class RouterTest extends \PHPUnit_Framework_TestCase { protected $_req; public function setUp() { - $this->_conn = $this->getMock('\Ratchet\ConnectionInterface'); - $this->_uri = $this->getMock('Psr\Http\Message\UriInterface'); - $this->_req = $this->getMock('\Psr\Http\Message\RequestInterface'); + $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(); $this->_req ->expects($this->any()) ->method('getUri') ->will($this->returnValue($this->_uri)); - $this->_matcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface'); + $this->_matcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\UrlMatcherInterface')->getMock(); $this->_matcher ->expects($this->any()) ->method('getContext') - ->will($this->returnValue($this->getMock('Symfony\Component\Routing\RequestContext'))); + ->will($this->returnValue($this->getMockBuilder('Symfony\Component\Routing\RequestContext')->getMock())); $this->_router = new Router($this->_matcher); $this->_uri->expects($this->any())->method('getPath')->will($this->returnValue('ws://doesnt.matter/')); @@ -40,7 +40,9 @@ public function setUp() { return true; }))->will($this->returnSelf()); $this->_uri->expects($this->any())->method('getQuery')->will($this->returnCallback([$this, 'getResult'])); + $this->_uri->expects($this->any())->method('getHost')->willReturn('example.com'); $this->_req->expects($this->any())->method('withUri')->will($this->returnSelf()); + $this->_req->expects($this->any())->method('getMethod')->willReturn('GET'); } public function testFourOhFour() { @@ -53,22 +55,22 @@ public function testFourOhFour() { } public function testNullRequest() { - $this->setExpectedException('\UnexpectedValueException'); + $this->setExpectedException('UnexpectedValueException'); $this->_router->onOpen($this->_conn); } public function testControllerIsMessageComponentInterface() { - $this->setExpectedException('\UnexpectedValueException'); + $this->setExpectedException('UnexpectedValueException'); $this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => new \StdClass))); $this->_router->onOpen($this->_conn, $this->_req); } public function testControllerOnOpen() { - $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); + $controller = $this->getMockBuilder('Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); $this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => $controller))); $this->_router->onOpen($this->_conn, $this->_req); - $expectedConn = new \PHPUnit_Framework_Constraint_IsInstanceOf('\Ratchet\ConnectionInterface'); + $expectedConn = new \PHPUnit_Framework_Constraint_IsInstanceOf('Ratchet\ConnectionInterface'); $controller->expects($this->once())->method('onOpen')->with($expectedConn, $this->_req); $this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => $controller))); @@ -77,7 +79,7 @@ public function testControllerOnOpen() { public function testControllerOnMessageBubbles() { $message = "The greatest trick the Devil ever pulled was convincing the world he didn't exist"; - $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); + $controller = $this->getMockBuilder('Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); $controller->expects($this->once())->method('onMessage')->with($this->_conn, $message); $this->_conn->controller = $controller; @@ -86,7 +88,7 @@ public function testControllerOnMessageBubbles() { } public function testControllerOnCloseBubbles() { - $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); + $controller = $this->getMockBuilder('Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); $controller->expects($this->once())->method('onClose')->with($this->_conn); $this->_conn->controller = $controller; @@ -96,7 +98,7 @@ public function testControllerOnCloseBubbles() { public function testControllerOnErrorBubbles() { $e= new \Exception('One cannot be betrayed if one has no exceptions'); - $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); + $controller = $this->getMockBuilder('Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); $controller->expects($this->once())->method('onError')->with($this->_conn, $e); $this->_conn->controller = $controller; @@ -106,12 +108,12 @@ public function testControllerOnErrorBubbles() { public function testRouterGeneratesRouteParameters() { /** @var $controller WsServerInterface */ - $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); + $controller = $this->getMockBuilder('Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); /** @var $matcher UrlMatcherInterface */ $this->_matcher->expects($this->any())->method('match')->will( $this->returnValue(['_controller' => $controller, 'foo' => 'bar', 'baz' => 'qux']) ); - $conn = $this->getMock('Ratchet\Mock\Connection'); + $conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock(); $router = new Router($this->_matcher); @@ -121,13 +123,13 @@ public function testRouterGeneratesRouteParameters() { } public function testQueryParams() { - $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); + $controller = $this->getMockBuilder('Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); $this->_matcher->expects($this->any())->method('match')->will( $this->returnValue(['_controller' => $controller, 'foo' => 'bar', 'baz' => 'qux']) ); - $conn = $this->getMock('Ratchet\Mock\Connection'); - $request = $this->getMock('Psr\Http\Message\RequestInterface'); + $conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock(); + $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); $uri = new \GuzzleHttp\Psr7\Uri('ws://doesnt.matter/endpoint?hello=world&foo=nope'); $request->expects($this->any())->method('getUri')->will($this->returnCallback(function() use (&$uri) { @@ -138,6 +140,7 @@ public function testQueryParams() { return true; }))->will($this->returnSelf()); + $request->expects($this->once())->method('getMethod')->willReturn('GET'); $router = new Router($this->_matcher); $router->onOpen($conn, $request); diff --git a/tests/unit/Server/EchoServerTest.php b/tests/unit/Server/EchoServerTest.php index 47fb0e28..be944cc9 100644 --- a/tests/unit/Server/EchoServerTest.php +++ b/tests/unit/Server/EchoServerTest.php @@ -7,7 +7,7 @@ class EchoServerTest extends \PHPUnit_Framework_TestCase { protected $_comp; public function setUp() { - $this->_conn = $this->getMock('\Ratchet\ConnectionInterface'); + $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 38fc96a6..9da65533 100644 --- a/tests/unit/Server/FlashPolicyComponentTest.php +++ b/tests/unit/Server/FlashPolicyComponentTest.php @@ -123,7 +123,7 @@ public function testSetSiteControlThrowsException() { } public function testErrorClosesConnection() { - $conn = $this->getMock('\\Ratchet\\ConnectionInterface'); + $conn = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock(); $conn->expects($this->once())->method('close'); $this->_policy->onError($conn, new \Exception); @@ -132,7 +132,7 @@ public function testErrorClosesConnection() { public function testOnMessageSendsString() { $this->_policy->addAllowedAccess('*', '*'); - $conn = $this->getMock('\\Ratchet\\ConnectionInterface'); + $conn = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock(); $conn->expects($this->once())->method('send')->with($this->isType('string')); $this->_policy->onMessage($conn, ' '); @@ -140,13 +140,13 @@ public function testOnMessageSendsString() { public function testOnOpenExists() { $this->assertTrue(method_exists($this->_policy, 'onOpen')); - $conn = $this->getMock('\Ratchet\ConnectionInterface'); + $conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock(); $this->_policy->onOpen($conn); } public function testOnCloseExists() { $this->assertTrue(method_exists($this->_policy, 'onClose')); - $conn = $this->getMock('\Ratchet\ConnectionInterface'); + $conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock(); $this->_policy->onClose($conn); } } diff --git a/tests/unit/Server/IoConnectionTest.php b/tests/unit/Server/IoConnectionTest.php index 07130f6d..4bed85a6 100644 --- a/tests/unit/Server/IoConnectionTest.php +++ b/tests/unit/Server/IoConnectionTest.php @@ -10,7 +10,7 @@ class IoConnectionTest extends \PHPUnit_Framework_TestCase { protected $conn; public function setUp() { - $this->sock = $this->getMock('\\React\\Socket\\ConnectionInterface'); + $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 6d7936db..11a87ae2 100644 --- a/tests/unit/Server/IoServerTest.php +++ b/tests/unit/Server/IoServerTest.php @@ -26,7 +26,7 @@ protected function tickLoop(LoopInterface $loop) { } public function setUp() { - $this->app = $this->getMock('\\Ratchet\\MessageComponentInterface'); + $this->app = $this->getMockBuilder('Ratchet\\MessageComponentInterface')->getMock(); $loop = new StreamSelectLoop; $this->reactor = new Server(0, $loop); @@ -37,7 +37,7 @@ public function setUp() { } public function testOnOpen() { - $this->app->expects($this->once())->method('onOpen')->with($this->isInstanceOf('\\Ratchet\\ConnectionInterface')); + $this->app->expects($this->once())->method('onOpen')->with($this->isInstanceOf('Ratchet\\ConnectionInterface')); $client = stream_socket_client("tcp://localhost:{$this->port}"); @@ -54,7 +54,7 @@ public function testOnData() { $msg = 'Hello World!'; $this->app->expects($this->once())->method('onMessage')->with( - $this->isInstanceOf('\\Ratchet\\ConnectionInterface') + $this->isInstanceOf('Ratchet\\ConnectionInterface') , $msg ); @@ -80,7 +80,7 @@ public function testOnData() { * @requires extension sockets */ public function testOnClose() { - $this->app->expects($this->once())->method('onClose')->with($this->isInstanceOf('\\Ratchet\\ConnectionInterface')); + $this->app->expects($this->once())->method('onClose')->with($this->isInstanceOf('Ratchet\\ConnectionInterface')); $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_set_option($client, SOL_SOCKET, SO_REUSEADDR, 1); @@ -98,7 +98,7 @@ public function testOnClose() { } public function testFactory() { - $this->assertInstanceOf('\\Ratchet\\Server\\IoServer', IoServer::factory($this->app, 0)); + $this->assertInstanceOf('Ratchet\\Server\\IoServer', IoServer::factory($this->app, 0)); } public function testNoLoopProvidedError() { @@ -109,8 +109,8 @@ public function testNoLoopProvidedError() { } public function testOnErrorPassesException() { - $conn = $this->getMock('\\React\\Socket\\ConnectionInterface'); - $conn->decor = $this->getMock('\\Ratchet\\ConnectionInterface'); + $conn = $this->getMockBuilder('React\\Socket\\ConnectionInterface')->getMock(); + $conn->decor = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock(); $err = new \Exception("Nope"); $this->app->expects($this->once())->method('onError')->with($conn->decor, $err); @@ -121,12 +121,12 @@ public function testOnErrorPassesException() { public function onErrorCalledWhenExceptionThrown() { $this->markTestIncomplete("Need to learn how to throw an exception from a mock"); - $conn = $this->getMock('\\React\\Socket\\ConnectionInterface'); + $conn = $this->getMockBuilder('React\\Socket\\ConnectionInterface')->getMock(); $this->server->handleConnect($conn); $e = new \Exception; - $this->app->expects($this->once())->method('onMessage')->with($this->isInstanceOf('\\Ratchet\\ConnectionInterface'), 'f')->will($e); - $this->app->expects($this->once())->method('onError')->with($this->instanceOf('\\Ratchet\\ConnectionInterface', $e)); + $this->app->expects($this->once())->method('onMessage')->with($this->isInstanceOf('Ratchet\\ConnectionInterface'), 'f')->will($e); + $this->app->expects($this->once())->method('onError')->with($this->instanceOf('Ratchet\\ConnectionInterface', $e)); $this->server->handleData('f', $conn); } diff --git a/tests/unit/Server/IpBlackListComponentTest.php b/tests/unit/Server/IpBlackListComponentTest.php index 90f41859..6fc736dd 100644 --- a/tests/unit/Server/IpBlackListComponentTest.php +++ b/tests/unit/Server/IpBlackListComponentTest.php @@ -10,7 +10,7 @@ class IpBlackListTest extends \PHPUnit_Framework_TestCase { protected $mock; public function setUp() { - $this->mock = $this->getMock('\\Ratchet\\MessageComponentInterface'); + $this->mock = $this->getMockBuilder('Ratchet\\MessageComponentInterface')->getMock(); $this->blocker = new IpBlackList($this->mock); } @@ -113,11 +113,11 @@ public function testFilterAddress($expected, $input) { } public function testUnblockingSilentlyFails() { - $this->assertInstanceOf('\\Ratchet\\Server\\IpBlackList', $this->blocker->unblockAddress('localhost')); + $this->assertInstanceOf('Ratchet\\Server\\IpBlackList', $this->blocker->unblockAddress('localhost')); } protected function newConn() { - $conn = $this->getMock('\\Ratchet\\ConnectionInterface'); + $conn = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock(); $conn->remoteAddress = '127.0.0.1'; return $conn; diff --git a/tests/unit/Session/SessionComponentTest.php b/tests/unit/Session/SessionComponentTest.php index ea452db3..e9d09459 100644 --- a/tests/unit/Session/SessionComponentTest.php +++ b/tests/unit/Session/SessionComponentTest.php @@ -26,15 +26,15 @@ public function tearDown() { } public function getConnectionClassString() { - return '\Ratchet\ConnectionInterface'; + return 'Ratchet\ConnectionInterface'; } public function getDecoratorClassString() { - return '\Ratchet\NullComponent'; + return 'Ratchet\NullComponent'; } public function getComponentClassString() { - return '\Ratchet\Http\HttpServerInterface'; + return 'Ratchet\Http\HttpServerInterface'; } public function classCaseProvider() { @@ -48,11 +48,11 @@ public function classCaseProvider() { * @dataProvider classCaseProvider */ public function testToClassCase($in, $out) { - $ref = new \ReflectionClass('\\Ratchet\\Session\\SessionProvider'); + $ref = new \ReflectionClass('Ratchet\\Session\\SessionProvider'); $method = $ref->getMethod('toClassCase'); $method->setAccessible(true); - $component = new SessionProvider($this->getMock($this->getComponentClassString()), $this->getMock('\SessionHandlerInterface')); + $component = new SessionProvider($this->getMockBuilder($this->getComponentClassString())->getMock(), $this->getMockBuilder('SessionHandlerInterface')->getMock()); $this->assertEquals($out, $method->invokeArgs($component, array($in))); } @@ -81,10 +81,10 @@ public function testConnectionValueFromPdo() { $pdoHandler = new PdoSessionHandler($pdo, $dbOptions); $pdoHandler->write($sessionId, '_sf2_attributes|a:2:{s:5:"hello";s:5:"world";s:4:"last";i:1332872102;}_sf2_flashes|a:0:{}'); - $component = new SessionProvider($this->getMock($this->getComponentClassString()), $pdoHandler, array('auto_start' => 1)); - $connection = $this->getMock('Ratchet\\ConnectionInterface'); + $component = new SessionProvider($this->getMockBuilder($this->getComponentClassString())->getMock(), $pdoHandler, array('auto_start' => 1)); + $connection = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock(); - $headers = $this->getMock('Psr\Http\Message\RequestInterface'); + $headers = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); $headers->expects($this->once())->method('getHeader')->will($this->returnValue([ini_get('session.name') . "={$sessionId};"])); $component->onOpen($connection, $headers); @@ -93,9 +93,9 @@ public function testConnectionValueFromPdo() { } protected function newConn() { - $conn = $this->getMock('Ratchet\ConnectionInterface'); + $conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock(); - $headers = $this->getMock('Psr\Http\Message\Request', array('getCookie'), array('POST', '/', array())); + $headers = $this->getMockBuilder('Psr\Http\Message\Request', array('getCookie'), array('POST', '/', array()))->getMock(); $headers->expects($this->once())->method('getCookie', array(ini_get('session.name')))->will($this->returnValue(null)); return $conn; @@ -113,12 +113,12 @@ public function testRejectInvalidSeralizers() { } ini_set('session.serialize_handler', 'wddx'); - $this->setExpectedException('\RuntimeException'); - new SessionProvider($this->getMock($this->getComponentClassString()), $this->getMock('\SessionHandlerInterface')); + $this->setExpectedException('RuntimeException'); + new SessionProvider($this->getMockBuilder($this->getComponentClassString())->getMock(), $this->getMockBuilder('SessionHandlerInterface')->getMock()); } protected function doOpen($conn) { - $request = $this->getMock('Psr\Http\Message\RequestInterface'); + $request = $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock(); $request->expects($this->any())->method('getHeader')->will($this->returnValue([])); $this->_serv->onOpen($conn, $request); diff --git a/tests/unit/Wamp/ServerProtocolTest.php b/tests/unit/Wamp/ServerProtocolTest.php index 8ff68c25..4b90aeef 100644 --- a/tests/unit/Wamp/ServerProtocolTest.php +++ b/tests/unit/Wamp/ServerProtocolTest.php @@ -36,7 +36,7 @@ public function invalidMessageProvider() { * @dataProvider invalidMessageProvider */ public function testInvalidMessages($type) { - $this->setExpectedException('\Ratchet\Wamp\Exception'); + $this->setExpectedException('Ratchet\Wamp\Exception'); $conn = $this->newConn(); $this->_comp->onOpen($conn); @@ -180,7 +180,7 @@ public function testOnClosePropagation() { $this->_comp->onOpen($conn); $this->_comp->onClose($conn); - $class = new \ReflectionClass('\\Ratchet\\Wamp\\WampConnection'); + $class = new \ReflectionClass('Ratchet\\Wamp\\WampConnection'); $method = $class->getMethod('getConnection'); $method->setAccessible(true); @@ -197,7 +197,7 @@ public function testOnErrorPropagation() { $this->_comp->onOpen($conn); $this->_comp->onError($conn, $e); - $class = new \ReflectionClass('\\Ratchet\\Wamp\\WampConnection'); + $class = new \ReflectionClass('Ratchet\\Wamp\\WampConnection'); $method = $class->getMethod('getConnection'); $method->setAccessible(true); @@ -222,7 +222,7 @@ public function testPrefix() { } public function testMessageMustBeJson() { - $this->setExpectedException('\\Ratchet\\Wamp\\JsonException'); + $this->setExpectedException('Ratchet\\Wamp\\JsonException'); $conn = new Connection; @@ -241,7 +241,7 @@ public function testGetSubProtocolsGetFromApp() { } public function testWampOnMessageApp() { - $app = $this->getMock('\\Ratchet\\Wamp\\WampServerInterface'); + $app = $this->getMockBuilder('Ratchet\\Wamp\\WampServerInterface')->getMock(); $wamp = new ServerProtocol($app); $this->assertContains('wamp', $wamp->getSubProtocols()); @@ -259,7 +259,7 @@ public function badFormatProvider() { * @dataProvider badFormatProvider */ public function testValidJsonButInvalidProtocol($message) { - $this->setExpectedException('\Ratchet\Wamp\Exception'); + $this->setExpectedException('Ratchet\Wamp\Exception'); $conn = $this->newConn(); $this->_comp->onOpen($conn); @@ -267,7 +267,7 @@ public function testValidJsonButInvalidProtocol($message) { } public function testBadClientInputFromNonStringTopic() { - $this->setExpectedException('\Ratchet\Wamp\Exception'); + $this->setExpectedException('Ratchet\Wamp\Exception'); $conn = new WampConnection($this->newConn()); $this->_comp->onOpen($conn); @@ -276,7 +276,7 @@ public function testBadClientInputFromNonStringTopic() { } public function testBadPrefixWithNonStringTopic() { - $this->setExpectedException('\Ratchet\Wamp\Exception'); + $this->setExpectedException('Ratchet\Wamp\Exception'); $conn = new WampConnection($this->newConn()); $this->_comp->onOpen($conn); @@ -285,7 +285,7 @@ public function testBadPrefixWithNonStringTopic() { } public function testBadPublishWithNonStringTopic() { - $this->setExpectedException('\Ratchet\Wamp\Exception'); + $this->setExpectedException('Ratchet\Wamp\Exception'); $conn = new WampConnection($this->newConn()); $this->_comp->onOpen($conn); diff --git a/tests/unit/Wamp/TopicManagerTest.php b/tests/unit/Wamp/TopicManagerTest.php index b21b6bc0..fe3b5db2 100644 --- a/tests/unit/Wamp/TopicManagerTest.php +++ b/tests/unit/Wamp/TopicManagerTest.php @@ -18,8 +18,8 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { private $conn; public function setUp() { - $this->conn = $this->getMock('\Ratchet\ConnectionInterface'); - $this->mock = $this->getMock('\Ratchet\Wamp\WampServerInterface'); + $this->conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock(); + $this->mock = $this->getMockBuilder('Ratchet\Wamp\WampServerInterface')->getMock(); $this->mngr = new TopicManager($this->mock); $this->conn->WAMP = new \StdClass; @@ -217,7 +217,7 @@ public function testGetSubProtocolsReturnsArray() { public function testGetSubProtocolsBubbles() { $subs = array('hello', 'world'); - $app = $this->getMock('Ratchet\Wamp\Stub\WsWampServerInterface'); + $app = $this->getMockBuilder('Ratchet\Wamp\Stub\WsWampServerInterface')->getMock(); $app->expects($this->once())->method('getSubProtocols')->will($this->returnValue($subs)); $mngr = new TopicManager($app); diff --git a/tests/unit/Wamp/TopicTest.php b/tests/unit/Wamp/TopicTest.php index b8685b7e..29dc9a98 100644 --- a/tests/unit/Wamp/TopicTest.php +++ b/tests/unit/Wamp/TopicTest.php @@ -40,8 +40,8 @@ public function testBroadcast() { $name = 'Batman'; $protocol = json_encode(array(8, $name, $msg)); - $first = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface'))); - $second = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface'))); + $first = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock(); + $second = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock(); $first->expects($this->once()) ->method('send') @@ -63,9 +63,9 @@ public function testBroadcastWithExclude() { $name = 'Excluding'; $protocol = json_encode(array(8, $name, $msg)); - $first = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface'))); - $second = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface'))); - $third = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface'))); + $first = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock(); + $second = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock(); + $third = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock(); $first->expects($this->once()) ->method('send') @@ -90,9 +90,9 @@ public function testBroadcastWithEligible() { $name = 'Eligible'; $protocol = json_encode(array(8, $name, $msg)); - $first = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface'))); - $second = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface'))); - $third = $this->getMock('Ratchet\\Wamp\\WampConnection', array('send'), array($this->getMock('\\Ratchet\\ConnectionInterface'))); + $first = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock(); + $second = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock(); + $third = $this->getMockBuilder('Ratchet\\Wamp\\WampConnection')->setMethods(array('send'))->setConstructorArgs(array($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()))->getMock(); $first->expects($this->once()) ->method('send') @@ -159,6 +159,6 @@ public function testDoesNotHaveAfterRemove() { } protected function newConn() { - return new WampConnection($this->getMock('\\Ratchet\\ConnectionInterface')); + return new WampConnection($this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock()); } } diff --git a/tests/unit/Wamp/WampConnectionTest.php b/tests/unit/Wamp/WampConnectionTest.php index adf59d53..83869f0f 100644 --- a/tests/unit/Wamp/WampConnectionTest.php +++ b/tests/unit/Wamp/WampConnectionTest.php @@ -9,7 +9,7 @@ class WampConnectionTest extends \PHPUnit_Framework_TestCase { protected $mock; public function setUp() { - $this->mock = $this->getMock('\\Ratchet\\ConnectionInterface'); + $this->mock = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock(); $this->conn = new WampConnection($this->mock); } @@ -67,7 +67,7 @@ public function testGetUriWhenNoCurieGiven() { } public function testClose() { - $mock = $this->getMock('\\Ratchet\\ConnectionInterface'); + $mock = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock(); $conn = new WampConnection($mock); $mock->expects($this->once())->method('close'); diff --git a/tests/unit/Wamp/WampServerTest.php b/tests/unit/Wamp/WampServerTest.php index 626b1cef..fb1f2147 100644 --- a/tests/unit/Wamp/WampServerTest.php +++ b/tests/unit/Wamp/WampServerTest.php @@ -7,7 +7,7 @@ */ class WampServerTest extends AbstractMessageComponentTestCase { public function getConnectionClassString() { - return '\Ratchet\Wamp\WampConnection'; + return 'Ratchet\Wamp\WampConnection'; } public function getDecoratorClassString() { @@ -15,7 +15,7 @@ public function getDecoratorClassString() { } public function getComponentClassString() { - return '\Ratchet\Wamp\WampServerInterface'; + return 'Ratchet\Wamp\WampServerInterface'; } public function testOnMessageToEvent() { @@ -23,7 +23,7 @@ public function testOnMessageToEvent() { $this->_app->expects($this->once())->method('onPublish')->with( $this->isExpectedConnection() - , new \PHPUnit_Framework_Constraint_IsInstanceOf('\Ratchet\Wamp\Topic') + , new \PHPUnit_Framework_Constraint_IsInstanceOf('Ratchet\Wamp\Topic') , $published , array() , array() From 5c32ebcb1e8a5658569d506dc5561c4710d1ba07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 11 Aug 2023 13:10:39 +0200 Subject: [PATCH 2/4] Update tests to support PHPUnit ^6.5 --- composer.json | 2 +- .../AbstractMessageComponentTestCase.php | 6 ++- .../unit/AbstractConnectionDecoratorTest.php | 21 ++++++++-- tests/unit/Http/HttpRequestParserTest.php | 10 ++++- tests/unit/Http/RouterTest.php | 18 ++++++--- tests/unit/Server/EchoServerTest.php | 3 +- .../unit/Server/FlashPolicyComponentTest.php | 27 ++++++++++--- tests/unit/Server/IoConnectionTest.php | 3 +- tests/unit/Server/IoServerTest.php | 10 +++-- .../unit/Server/IpBlackListComponentTest.php | 3 +- .../unit/Session/Serialize/PhpHandlerTest.php | 3 +- .../Storage/VirtualSessionStoragePDOTest.php | 3 +- tests/unit/Wamp/ServerProtocolTest.php | 39 +++++++++++++++---- tests/unit/Wamp/TopicManagerTest.php | 4 +- tests/unit/Wamp/TopicTest.php | 4 +- tests/unit/Wamp/WampConnectionTest.php | 4 +- tests/unit/Wamp/WampServerTest.php | 2 +- 17 files changed, 124 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index 06e78c32..443190cb 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ , "symfony/routing": "^2.6|^3.0|^4.0|^5.0|^6.0" } , "require-dev": { - "phpunit/phpunit": "^5.7 || ^4.8.36", + "phpunit/phpunit": "^6.5 || ^5.7 || ^4.8.36", "psr/http-message": "~1.0.1" } } diff --git a/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php b/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php index a50cde53..e810e944 100644 --- a/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php +++ b/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php @@ -1,7 +1,9 @@ getConnectionClassString()); + return $this->isInstanceOf($this->getConnectionClassString()); } public function testOpen() { diff --git a/tests/unit/AbstractConnectionDecoratorTest.php b/tests/unit/AbstractConnectionDecoratorTest.php index e699c9f8..c029e0f1 100644 --- a/tests/unit/AbstractConnectionDecoratorTest.php +++ b/tests/unit/AbstractConnectionDecoratorTest.php @@ -1,12 +1,13 @@ markTestSkipped('Requires error_reporting to include E_NOTICE'); } - $this->setExpectedException('PHPUnit_Framework_Error'); + 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'); + } $var = $this->mock->nonExistant; } @@ -144,7 +149,11 @@ public function testWarningGettingNothingLevel1() { $this->markTestSkipped('Requires error_reporting to include E_NOTICE'); } - $this->setExpectedException('PHPUnit_Framework_Error'); + 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'); + } $var = $this->l1->nonExistant; } @@ -153,7 +162,11 @@ public function testWarningGettingNothingLevel2() { $this->markTestSkipped('Requires error_reporting to include E_NOTICE'); } - $this->setExpectedException('PHPUnit_Framework_Error'); + 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'); + } $var = $this->l2->nonExistant; } } diff --git a/tests/unit/Http/HttpRequestParserTest.php b/tests/unit/Http/HttpRequestParserTest.php index 9008afe3..d5e3540c 100644 --- a/tests/unit/Http/HttpRequestParserTest.php +++ b/tests/unit/Http/HttpRequestParserTest.php @@ -1,10 +1,12 @@ assertNull($this->parser->onMessage($conn, "GET / HTTP/1.1\r\n")); - $this->setExpectedException('OverflowException'); + if (method_exists($this, 'expectException')) { + $this->expectException('OverflowException'); + } else { + $this->setExpectedException('OverflowException'); + } $this->parser->onMessage($conn, "Header-Is: Too Big"); } diff --git a/tests/unit/Http/RouterTest.php b/tests/unit/Http/RouterTest.php index 93a17836..4a1dc58e 100644 --- a/tests/unit/Http/RouterTest.php +++ b/tests/unit/Http/RouterTest.php @@ -1,5 +1,6 @@ setExpectedException('UnexpectedValueException'); + if (method_exists($this, 'expectException')) { + $this->expectException('UnexpectedValueException'); + } else { + $this->setExpectedException('UnexpectedValueException'); + } $this->_router->onOpen($this->_conn); } public function testControllerIsMessageComponentInterface() { - $this->setExpectedException('UnexpectedValueException'); + if (method_exists($this, 'expectException')) { + $this->expectException('UnexpectedValueException'); + } else { + $this->setExpectedException('UnexpectedValueException'); + } $this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => new \StdClass))); $this->_router->onOpen($this->_conn, $this->_req); } @@ -70,7 +78,7 @@ public function testControllerOnOpen() { $this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => $controller))); $this->_router->onOpen($this->_conn, $this->_req); - $expectedConn = new \PHPUnit_Framework_Constraint_IsInstanceOf('Ratchet\ConnectionInterface'); + $expectedConn = $this->isInstanceOf('Ratchet\ConnectionInterface'); $controller->expects($this->once())->method('onOpen')->with($expectedConn, $this->_req); $this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => $controller))); diff --git a/tests/unit/Server/EchoServerTest.php b/tests/unit/Server/EchoServerTest.php index be944cc9..d2bc5efb 100644 --- a/tests/unit/Server/EchoServerTest.php +++ b/tests/unit/Server/EchoServerTest.php @@ -1,8 +1,9 @@ setExpectedException('UnexpectedValueException'); + if (method_exists($this, 'expectException')) { + $this->expectException('UnexpectedValueException'); + } else { + $this->setExpectedException('UnexpectedValueException'); + } $this->_policy->renderPolicy(); } public function testInvalidDomainPolicyReader() { - $this->setExpectedException('UnexpectedValueException'); + if (method_exists($this, 'expectException')) { + $this->expectException('UnexpectedValueException'); + } else { + $this->setExpectedException('UnexpectedValueException'); + } $this->_policy->setSiteControl('all'); $this->_policy->addAllowedAccess('dev.example.*', '*'); $this->_policy->renderPolicy(); @@ -111,13 +120,21 @@ public static function ports() { } public function testAddAllowedAccessOnlyAcceptsValidPorts() { - $this->setExpectedException('UnexpectedValueException'); + if (method_exists($this, 'expectException')) { + $this->expectException('UnexpectedValueException'); + } else { + $this->setExpectedException('UnexpectedValueException'); + } $this->_policy->addAllowedAccess('*', 'nope'); } public function testSetSiteControlThrowsException() { - $this->setExpectedException('UnexpectedValueException'); + if (method_exists($this, 'expectException')) { + $this->expectException('UnexpectedValueException'); + } else { + $this->setExpectedException('UnexpectedValueException'); + } $this->_policy->setSiteControl('nope'); } diff --git a/tests/unit/Server/IoConnectionTest.php b/tests/unit/Server/IoConnectionTest.php index 4bed85a6..01c71502 100644 --- a/tests/unit/Server/IoConnectionTest.php +++ b/tests/unit/Server/IoConnectionTest.php @@ -1,11 +1,12 @@ setExpectedException('RuntimeException'); + if (method_exists($this, 'expectException')) { + $this->expectException('RuntimeException'); + } else { + $this->setExpectedException('RuntimeException'); + } $io = new IoServer($this->app, $this->reactor); $io->run(); diff --git a/tests/unit/Server/IpBlackListComponentTest.php b/tests/unit/Server/IpBlackListComponentTest.php index 6fc736dd..3ca22fdd 100644 --- a/tests/unit/Server/IpBlackListComponentTest.php +++ b/tests/unit/Server/IpBlackListComponentTest.php @@ -1,11 +1,12 @@ setExpectedException('Ratchet\Wamp\Exception'); + if (method_exists($this, 'expectException')) { + $this->expectException('Ratchet\Wamp\Exception'); + } else { + $this->setExpectedException('Ratchet\Wamp\Exception'); + } $conn = $this->newConn(); $this->_comp->onOpen($conn); @@ -222,7 +227,11 @@ public function testPrefix() { } public function testMessageMustBeJson() { - $this->setExpectedException('Ratchet\\Wamp\\JsonException'); + if (method_exists($this, 'expectException')) { + $this->expectException('Ratchet\Wamp\Exception'); + } else { + $this->setExpectedException('Ratchet\Wamp\Exception'); + } $conn = new Connection; @@ -259,7 +268,11 @@ public function badFormatProvider() { * @dataProvider badFormatProvider */ public function testValidJsonButInvalidProtocol($message) { - $this->setExpectedException('Ratchet\Wamp\Exception'); + if (method_exists($this, 'expectException')) { + $this->expectException('Ratchet\Wamp\Exception'); + } else { + $this->setExpectedException('Ratchet\Wamp\Exception'); + } $conn = $this->newConn(); $this->_comp->onOpen($conn); @@ -267,7 +280,11 @@ public function testValidJsonButInvalidProtocol($message) { } public function testBadClientInputFromNonStringTopic() { - $this->setExpectedException('Ratchet\Wamp\Exception'); + if (method_exists($this, 'expectException')) { + $this->expectException('Ratchet\Wamp\Exception'); + } else { + $this->setExpectedException('Ratchet\Wamp\Exception'); + } $conn = new WampConnection($this->newConn()); $this->_comp->onOpen($conn); @@ -276,7 +293,11 @@ public function testBadClientInputFromNonStringTopic() { } public function testBadPrefixWithNonStringTopic() { - $this->setExpectedException('Ratchet\Wamp\Exception'); + if (method_exists($this, 'expectException')) { + $this->expectException('Ratchet\Wamp\Exception'); + } else { + $this->setExpectedException('Ratchet\Wamp\Exception'); + } $conn = new WampConnection($this->newConn()); $this->_comp->onOpen($conn); @@ -285,7 +306,11 @@ public function testBadPrefixWithNonStringTopic() { } public function testBadPublishWithNonStringTopic() { - $this->setExpectedException('Ratchet\Wamp\Exception'); + if (method_exists($this, 'expectException')) { + $this->expectException('Ratchet\Wamp\Exception'); + } else { + $this->setExpectedException('Ratchet\Wamp\Exception'); + } $conn = new WampConnection($this->newConn()); $this->_comp->onOpen($conn); diff --git a/tests/unit/Wamp/TopicManagerTest.php b/tests/unit/Wamp/TopicManagerTest.php index fe3b5db2..18d39a4c 100644 --- a/tests/unit/Wamp/TopicManagerTest.php +++ b/tests/unit/Wamp/TopicManagerTest.php @@ -1,10 +1,12 @@ _app->expects($this->once())->method('onPublish')->with( $this->isExpectedConnection() - , new \PHPUnit_Framework_Constraint_IsInstanceOf('Ratchet\Wamp\Topic') + , $this->isInstanceOf('Ratchet\Wamp\Topic') , $published , array() , array() From 9c447214f219c08de02802f4696cce44894d5cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 11 Aug 2023 13:18:02 +0200 Subject: [PATCH 3/4] Update tests to support PHPUnit ^7.5 --- composer.json | 2 +- phpunit.xml.dist | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 443190cb..c18eebbc 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ , "symfony/routing": "^2.6|^3.0|^4.0|^5.0|^6.0" } , "require-dev": { - "phpunit/phpunit": "^6.5 || ^5.7 || ^4.8.36", + "phpunit/phpunit": "^7.5 || ^5.7 || ^4.8.36", "psr/http-message": "~1.0.1" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0cc5451b..846edc4f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,12 +1,10 @@ @@ -16,12 +14,6 @@ - - - ./tests/integration/ - - - ./src/ From 7014fa46db6de5bf959d79c7f6ff008b6435b84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 19 Apr 2025 12:02:37 +0200 Subject: [PATCH 4/4] Update tests to support latest psr/http-message on PHP 7.2+ --- composer.json | 3 +-- tests/unit/Http/RouterTest.php | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index c18eebbc..db9f3c64 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +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", - "psr/http-message": "~1.0.1" + "phpunit/phpunit": "^7.5 || ^5.7 || ^4.8.36" } } diff --git a/tests/unit/Http/RouterTest.php b/tests/unit/Http/RouterTest.php index 4a1dc58e..828597cd 100644 --- a/tests/unit/Http/RouterTest.php +++ b/tests/unit/Http/RouterTest.php @@ -39,7 +39,6 @@ public function setUp() { return true; }))->will($this->returnSelf()); - $this->_uri->expects($this->any())->method('getQuery')->will($this->returnCallback([$this, 'getResult'])); $this->_uri->expects($this->any())->method('getHost')->willReturn('example.com'); $this->_req->expects($this->any())->method('withUri')->will($this->returnSelf()); $this->_req->expects($this->any())->method('getMethod')->willReturn('GET'); @@ -123,11 +122,12 @@ public function testRouterGeneratesRouteParameters() { ); $conn = $this->getMockBuilder('Ratchet\Mock\Connection')->getMock(); + $this->_uri->expects($this->once())->method('withQuery')->with('foo=bar&baz=qux')->willReturnSelf(); + $this->_req->expects($this->once())->method('withUri')->will($this->returnSelf()); + $router = new Router($this->_matcher); $router->onOpen($conn, $this->_req); - - $this->assertEquals('foo=bar&baz=qux', $this->_req->getUri()->getQuery()); } public function testQueryParams() {