diff --git a/composer.json b/composer.json index ba788169..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": "~4.8", - "psr/http-message": "~1.0.1" + "phpunit/phpunit": "^7.5 || ^5.7 || ^4.8.36" } } 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/ diff --git a/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php b/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php index 8c298e5b..e810e944 100644 --- a/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php +++ b/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php @@ -1,7 +1,9 @@ _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); } @@ -24,12 +26,12 @@ protected function doOpen($conn) { } public function isExpectedConnection() { - return new \PHPUnit_Framework_Constraint_IsInstanceOf($this->getConnectionClassString()); + return $this->isInstanceOf($this->getConnectionClassString()); } 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..c029e0f1 100644 --- a/tests/unit/AbstractConnectionDecoratorTest.php +++ b/tests/unit/AbstractConnectionDecoratorTest.php @@ -1,18 +1,19 @@ 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 +85,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 +95,7 @@ public function testGetConnection() { } public function testGetConnectionLevel2() { - $class = new \ReflectionClass('\\Ratchet\\AbstractConnectionDecorator'); + $class = new \ReflectionClass('Ratchet\\AbstractConnectionDecorator'); $method = $class->getMethod('getConnection'); $method->setAccessible(true); @@ -135,7 +136,11 @@ public function testWarningGettingNothing() { $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->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 6af8402c..d5e3540c 100644 --- a/tests/unit/Http/HttpRequestParserTest.php +++ b/tests/unit/Http/HttpRequestParserTest.php @@ -1,10 +1,12 @@ getMock('\Ratchet\ConnectionInterface'); + $conn = $this->getMockBuilder('Ratchet\ConnectionInterface')->getMock(); $this->parser->maxSize = 20; $this->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"); } 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..828597cd 100644 --- a/tests/unit/Http/RouterTest.php +++ b/tests/unit/Http/RouterTest.php @@ -1,5 +1,6 @@ _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/')); @@ -39,8 +39,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 +54,30 @@ public function testFourOhFour() { } public function testNullRequest() { - $this->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); } 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 = $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))); @@ -77,7 +86,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 +95,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 +105,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,28 +115,29 @@ 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(); + + $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() { - $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 +148,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..d2bc5efb 100644 --- a/tests/unit/Server/EchoServerTest.php +++ b/tests/unit/Server/EchoServerTest.php @@ -1,13 +1,14 @@ _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..c1961104 100644 --- a/tests/unit/Server/FlashPolicyComponentTest.php +++ b/tests/unit/Server/FlashPolicyComponentTest.php @@ -1,11 +1,12 @@ 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,19 +120,27 @@ 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'); } 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 +149,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 +157,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..01c71502 100644 --- a/tests/unit/Server/IoConnectionTest.php +++ b/tests/unit/Server/IoConnectionTest.php @@ -1,16 +1,17 @@ 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..d58a8733 100644 --- a/tests/unit/Server/IoServerTest.php +++ b/tests/unit/Server/IoServerTest.php @@ -1,6 +1,6 @@ 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,19 +98,23 @@ 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() { - $this->setExpectedException('RuntimeException'); + if (method_exists($this, 'expectException')) { + $this->expectException('RuntimeException'); + } else { + $this->setExpectedException('RuntimeException'); + } $io = new IoServer($this->app, $this->reactor); $io->run(); } 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 +125,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..3ca22fdd 100644 --- a/tests/unit/Server/IpBlackListComponentTest.php +++ b/tests/unit/Server/IpBlackListComponentTest.php @@ -1,16 +1,17 @@ mock = $this->getMock('\\Ratchet\\MessageComponentInterface'); + $this->mock = $this->getMockBuilder('Ratchet\\MessageComponentInterface')->getMock(); $this->blocker = new IpBlackList($this->mock); } @@ -113,11 +114,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/Serialize/PhpHandlerTest.php b/tests/unit/Session/Serialize/PhpHandlerTest.php index 4acf5bc6..2a7586c4 100644 --- a/tests/unit/Session/Serialize/PhpHandlerTest.php +++ b/tests/unit/Session/Serialize/PhpHandlerTest.php @@ -1,11 +1,12 @@ 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/Session/Storage/VirtualSessionStoragePDOTest.php b/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php index 2727484d..1f6466e6 100644 --- a/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php +++ b/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.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); @@ -180,7 +185,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 +202,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 +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; @@ -241,7 +250,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 +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 b21b6bc0..18d39a4c 100644 --- a/tests/unit/Wamp/TopicManagerTest.php +++ b/tests/unit/Wamp/TopicManagerTest.php @@ -1,10 +1,12 @@ 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 +219,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..3714ece9 100644 --- a/tests/unit/Wamp/TopicTest.php +++ b/tests/unit/Wamp/TopicTest.php @@ -1,10 +1,12 @@ 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 +65,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 +92,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 +161,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..d885974e 100644 --- a/tests/unit/Wamp/WampConnectionTest.php +++ b/tests/unit/Wamp/WampConnectionTest.php @@ -1,15 +1,17 @@ mock = $this->getMock('\\Ratchet\\ConnectionInterface'); + $this->mock = $this->getMockBuilder('Ratchet\\ConnectionInterface')->getMock(); $this->conn = new WampConnection($this->mock); } @@ -67,7 +69,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..9988f5ba 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') + , $this->isInstanceOf('Ratchet\Wamp\Topic') , $published , array() , array()