Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to PHPUnit 7 #700

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 2 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm
- 7.2
- 7.3

dist: trusty

matrix:
allow_failures:
- php: hhvm

before_script:
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "session.serialize_handler = php" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
- php -m
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
, "symfony/routing": "^2.6|^3.0|^4.0"
}
, "require-dev": {
"phpunit/phpunit": "~4.8"
"phpunit/phpunit": "~7.0"
}
}
5 changes: 0 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
forceCoversAnnotation="true"
mapTestClassNameToCoveredClassName="true"
bootstrap="tests/bootstrap.php"
colors="true"
backupGlobals="false"
backupStaticAttributes="false"
syntaxCheck="false"
stopOnError="false"
>

<testsuites>
<testsuite name="unit">
<directory>./tests/unit/</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="integration">
<directory>./tests/integration/</directory>
</testsuite>
Expand Down
13 changes: 8 additions & 5 deletions tests/helpers/Ratchet/AbstractMessageComponentTestCase.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
namespace Ratchet;

abstract class AbstractMessageComponentTestCase extends \PHPUnit_Framework_TestCase {
use PHPUnit\Framework\Constraint\IsInstanceOf;
use PHPUnit\Framework\TestCase;

abstract class AbstractMessageComponentTestCase extends TestCase {
protected $_app;
protected $_serv;
protected $_conn;
Expand All @@ -11,10 +14,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);
}
Expand All @@ -24,12 +27,12 @@ protected function doOpen($conn) {
}

public function isExpectedConnection() {
return new \PHPUnit_Framework_Constraint_IsInstanceOf($this->getConnectionClassString());
return new 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() {
Expand Down
19 changes: 13 additions & 6 deletions tests/unit/AbstractConnectionDecoratorTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php
namespace Ratchet;
use Ratchet\Mock\ConnectionDecorator;

use Ratchet\Mock\ConnectionDecorator;
use PHPUnit\Framework\TestCase;
/**
* @covers Ratchet\AbstractConnectionDecorator
* @covers Ratchet\ConnectionInterface
*/
class AbstractConnectionDecoratorTest extends \PHPUnit_Framework_TestCase {
class AbstractConnectionDecoratorTest extends TestCase {
protected $mock;
protected $l1;
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);
}
Expand Down Expand Up @@ -130,18 +131,24 @@ public function testDecoratorRecursionLevel2() {
$this->assertSame($this->l2, $this->l2->decorator->conn->decorator->conn->decorator->conn);
}

/**
* @expectedException \PHPUnit\Framework\Error\Notice
*/
public function testWarningGettingNothing() {
$this->setExpectedException('PHPUnit_Framework_Error');
$var = $this->mock->nonExistant;
}

/**
* @expectedException \PHPUnit\Framework\Error\Notice
*/
public function testWarningGettingNothingLevel1() {
$this->setExpectedException('PHPUnit_Framework_Error');
$var = $this->l1->nonExistant;
}

/**
* @expectedException \PHPUnit\Framework\Error\Notice
*/
public function testWarningGettingNothingLevel2() {
$this->setExpectedException('PHPUnit_Framework_Error');
$var = $this->l2->nonExistant;
}
}
12 changes: 7 additions & 5 deletions tests/unit/Http/HttpRequestParserTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
namespace Ratchet\Http;

use PHPUnit\Framework\TestCase;
/**
* @covers Ratchet\Http\HttpRequestParser
*/
class HttpRequestParserTest extends \PHPUnit_Framework_TestCase {
class HttpRequestParserTest extends TestCase {
protected $parser;

public function setUp() {
Expand All @@ -29,20 +30,21 @@ public function testIsEom($expected, $message) {
$this->assertEquals($expected, $this->parser->isEom($message));
}

/**
* @expectedException \OverflowException
*/
public function testBufferOverflowResponse() {
$conn = $this->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');

$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);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Http/OriginCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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();
Expand Down
40 changes: 23 additions & 17 deletions tests/unit/Http/RouterTest.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
<?php
namespace Ratchet\Http;

use PHPUnit\Framework\Constraint\IsInstanceOf;
use Ratchet\WebSocket\WsServerInterface;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Matcher\UrlMatcher;

use PHPUnit\Framework\TestCase;

/**
* @covers Ratchet\Http\Router
*/
class RouterTest extends \PHPUnit_Framework_TestCase {
class RouterTest extends TestCase {
protected $_router;
protected $_matcher;
protected $_conn;
protected $_uri;
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/'));
Expand All @@ -52,13 +54,17 @@ public function testFourOhFour() {
$this->_router->onOpen($this->_conn, $this->_req);
}

/**
* @expectedException \UnexpectedValueException
*/
public function testNullRequest() {
$this->setExpectedException('\UnexpectedValueException');
$this->_router->onOpen($this->_conn);
}

/**
* @expectedException \UnexpectedValueException
*/
public function testControllerIsMessageComponentInterface() {
$this->setExpectedException('\UnexpectedValueException');
$this->_matcher->expects($this->any())->method('match')->will($this->returnValue(array('_controller' => new \StdClass)));
$this->_router->onOpen($this->_conn, $this->_req);
}
Expand All @@ -68,7 +74,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 = new 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)));
Expand Down Expand Up @@ -111,7 +117,7 @@ public function testRouterGeneratesRouteParameters() {
$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);

Expand All @@ -126,8 +132,8 @@ public function testQueryParams() {
$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) {
Expand All @@ -151,10 +157,10 @@ public function testImpatientClientOverflow() {
$this->_conn->expects($this->once())->method('close');

$header = "GET /nope HTTP/1.1
Upgrade: websocket
Connection: upgrade
Host: localhost
Origin: http://localhost
Upgrade: websocket
Connection: upgrade
Host: localhost
Origin: http://localhost
Sec-WebSocket-Version: 13\r\n\r\n";

$app = new HttpServer(new Router(new UrlMatcher(new RouteCollection, new RequestContext)));
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/Server/EchoServerTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php
namespace Ratchet\Server;

use Ratchet\Server\EchoServer;
use PHPUnit\Framework\TestCase;

class EchoServerTest extends \PHPUnit_Framework_TestCase {
class EchoServerTest extends TestCase {
protected $_conn;
protected $_comp;

public function setUp() {
$this->_conn = $this->getMock('\Ratchet\ConnectionInterface');
$this->_conn = $this->getMockBuilder('\Ratchet\ConnectionInterface')->getMock();
$this->_comp = new EchoServer;
}

Expand Down
Loading