diff --git a/Makefile b/Makefile index 3a1ac95..aa143cc 100644 --- a/Makefile +++ b/Makefile @@ -8,21 +8,21 @@ cover: phpunit --coverage-text --coverage-html=reports/coverage abtests: - ulimit -n 2048 && php tests/AutobahnTestSuite/bin/fuzzingserver-libevent.php 8001 & - ulimit -n 2048 && php tests/AutobahnTestSuite/bin/fuzzingserver-stream.php 8002 & - ulimit -n 2048 && php tests/AutobahnTestSuite/bin/fuzzingserver-noutf8.php 8003 & + ulimit -n 2048 && php tests/autobahn/bin/fuzzingserver-libevent.php 8001 & + ulimit -n 2048 && php tests/autobahn/bin/fuzzingserver-stream.php 8002 & + ulimit -n 2048 && php tests/autobahn/bin/fuzzingserver-noutf8.php 8003 & wstest -m testeeserver -w ws://localhost:8000 & - wstest -m fuzzingclient -s tests/AutobahnTestSuite/fuzzingclient-all.json + wstest -m fuzzingclient -s tests/autobahn/fuzzingclient-all.json killall php wstest abtest: - ulimit -n 2048 && php tests/AutobahnTestSuite/bin/fuzzingserver-stream.php & - wstest -m fuzzingclient -s tests/AutobahnTestSuite/fuzzingclient-quick.json + ulimit -n 2048 && php tests/autobahn/bin/fuzzingserver-stream.php & + wstest -m fuzzingclient -s tests/autobahn/fuzzingclient-quick.json killall php profile: - php -d 'xdebug.profiler_enable=1' tests/AutobahnTestSuite/bin/fuzzingserver-libevent.php & - wstest -m fuzzingclient -s tests/AutobahnTestSuite/fuzzingclient-profile.json + php -d 'xdebug.profiler_enable=1' tests/autobahn/bin/fuzzingserver-libevent.php & + wstest -m fuzzingclient -s tests/autobahn/fuzzingclient-profile.json killall php apidocs: diff --git a/composer.json b/composer.json index a790d55..12c95f0 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,13 @@ } , "autoload": { "psr-0": { - "Ratchet\\Tests": "tests" - , "Ratchet": "src" + "Ratchet": "src" } } , "require": { "php": ">=5.3.9" , "react/socket": "0.3.*" - , "guzzle/http": "3.6.*" + , "guzzle/http": ">=3.6.0,<3.8.0-dev" , "symfony/http-foundation": "~2.2" , "symfony/routing": "~2.2" } diff --git a/composer.lock b/composer.lock index a803718..4800ed7 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "d5a238bcdccc33fab13dd3c65b663beb", + "hash": "a45c5bcb9c18e390adc2a60ffd059a52", "packages": [ { "name": "evenement/evenement", @@ -47,17 +47,17 @@ }, { "name": "guzzle/common", - "version": "v3.6.0", + "version": "v3.7.1", "target-dir": "Guzzle/Common", "source": { "type": "git", "url": "https://github.com/guzzle/common.git", - "reference": "v3.6.0" + "reference": "v3.7.1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/common/zipball/v3.6.0", - "reference": "v3.6.0", + "url": "https://api.github.com/repos/guzzle/common/zipball/v3.7.1", + "reference": "v3.7.1", "shasum": "" }, "require": { @@ -67,7 +67,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.6-dev" + "dev-master": "3.7-dev" } }, "autoload": { @@ -87,21 +87,21 @@ "event", "exception" ], - "time": "2013-05-30 07:01:25" + "time": "2013-07-05 20:17:54" }, { "name": "guzzle/http", - "version": "v3.6.0", + "version": "v3.7.1", "target-dir": "Guzzle/Http", "source": { "type": "git", "url": "https://github.com/guzzle/http.git", - "reference": "v3.6.0" + "reference": "v3.7.1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/http/zipball/v3.6.0", - "reference": "v3.6.0", + "url": "https://api.github.com/repos/guzzle/http/zipball/v3.7.1", + "reference": "v3.7.1", "shasum": "" }, "require": { @@ -116,7 +116,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.6-dev" + "dev-master": "3.7-dev" } }, "autoload": { @@ -144,21 +144,21 @@ "http", "http client" ], - "time": "2013-05-30 07:01:25" + "time": "2013-07-02 19:53:26" }, { "name": "guzzle/parser", - "version": "v3.6.0", + "version": "v3.7.1", "target-dir": "Guzzle/Parser", "source": { "type": "git", "url": "https://github.com/guzzle/parser.git", - "reference": "v3.6.0" + "reference": "v3.7.1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/parser/zipball/v3.6.0", - "reference": "v3.6.0", + "url": "https://api.github.com/repos/guzzle/parser/zipball/v3.7.1", + "reference": "v3.7.1", "shasum": "" }, "require": { @@ -167,7 +167,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.6-dev" + "dev-master": "3.7-dev" } }, "autoload": { @@ -188,21 +188,21 @@ "message", "url" ], - "time": "2013-05-30 07:01:25" + "time": "2013-06-11 00:24:07" }, { "name": "guzzle/stream", - "version": "v3.6.0", + "version": "v3.7.1", "target-dir": "Guzzle/Stream", "source": { "type": "git", "url": "https://github.com/guzzle/stream.git", - "reference": "v3.6.0" + "reference": "v3.7.1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/stream/zipball/v3.6.0", - "reference": "v3.6.0", + "url": "https://api.github.com/repos/guzzle/stream/zipball/v3.7.1", + "reference": "v3.7.1", "shasum": "" }, "require": { @@ -215,7 +215,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.6-dev" + "dev-master": "3.7-dev" } }, "autoload": { @@ -241,21 +241,21 @@ "component", "stream" ], - "time": "2013-05-30 07:01:25" + "time": "2013-06-27 00:50:43" }, { "name": "react/event-loop", - "version": "v0.3.2", + "version": "v0.3.3", "target-dir": "React/EventLoop", "source": { "type": "git", "url": "https://github.com/reactphp/event-loop.git", - "reference": "v0.3.2" + "reference": "v0.3.3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/event-loop/zipball/v0.3.2", - "reference": "v0.3.2", + "url": "https://api.github.com/repos/reactphp/event-loop/zipball/v0.3.3", + "reference": "v0.3.3", "shasum": "" }, "require": { @@ -284,7 +284,7 @@ "keywords": [ "event-loop" ], - "time": "2013-01-14 23:11:47" + "time": "2013-07-08 22:38:22" }, { "name": "react/socket", @@ -330,17 +330,17 @@ }, { "name": "react/stream", - "version": "v0.3.2", + "version": "v0.3.3", "target-dir": "React/Stream", "source": { "type": "git", "url": "https://github.com/reactphp/stream.git", - "reference": "v0.3.2" + "reference": "v0.3.3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/stream/zipball/v0.3.2", - "reference": "v0.3.2", + "url": "https://api.github.com/repos/reactphp/stream/zipball/v0.3.3", + "reference": "v0.3.3", "shasum": "" }, "require": { @@ -371,28 +371,28 @@ "pipe", "stream" ], - "time": "2013-05-10 15:12:22" + "time": "2013-07-09 00:44:12" }, { "name": "symfony/event-dispatcher", - "version": "v2.3.0", + "version": "v2.3.2", "target-dir": "Symfony/Component/EventDispatcher", "source": { "type": "git", "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "v2.3.0-RC1" + "reference": "v2.3.2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/v2.3.0-RC1", - "reference": "v2.3.0-RC1", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/v2.3.2", + "reference": "v2.3.2", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { - "symfony/dependency-injection": ">=2.0,<3.0" + "symfony/dependency-injection": "~2.0" }, "suggest": { "symfony/dependency-injection": "", @@ -429,17 +429,17 @@ }, { "name": "symfony/http-foundation", - "version": "v2.3.0", + "version": "v2.3.2", "target-dir": "Symfony/Component/HttpFoundation", "source": { "type": "git", "url": "https://github.com/symfony/HttpFoundation.git", - "reference": "v2.3.0-RC1" + "reference": "v2.3.2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/v2.3.0-RC1", - "reference": "v2.3.0-RC1", + "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/v2.3.2", + "reference": "v2.3.2", "shasum": "" }, "require": { @@ -475,31 +475,31 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "http://symfony.com", - "time": "2013-05-10 06:00:03" + "time": "2013-07-17 05:57:53" }, { "name": "symfony/routing", - "version": "v2.3.0", + "version": "v2.3.2", "target-dir": "Symfony/Component/Routing", "source": { "type": "git", "url": "https://github.com/symfony/Routing.git", - "reference": "v2.3.0" + "reference": "v2.3.2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Routing/zipball/v2.3.0", - "reference": "v2.3.0", + "url": "https://api.github.com/repos/symfony/Routing/zipball/v2.3.2", + "reference": "v2.3.2", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { - "doctrine/common": ">=2.2,<3.0", - "psr/log": ">=1.0,<2.0", - "symfony/config": ">=2.2,<3.0", - "symfony/yaml": ">=2.0,<3.0" + "doctrine/common": "~2.2", + "psr/log": "~1.0", + "symfony/config": "~2.2", + "symfony/yaml": "~2.0" }, "suggest": { "doctrine/common": "", @@ -533,7 +533,7 @@ ], "description": "Symfony Routing Component", "homepage": "http://symfony.com", - "time": "2013-05-20 08:57:26" + "time": "2013-06-23 08:16:02" } ], "packages-dev": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 78b3128..0cc5451 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,7 @@ - - ./tests/Ratchet/ + + ./tests/unit/ + + + + + + ./tests/integration/ - - ./tests/ - ./vendor/ - + + ./src/ + \ No newline at end of file diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index 6728c30..a3db257 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -79,7 +79,7 @@ class App { /** * @param string $path * @param ComponentInterface $controller - * @return Symfony\Component\Routing\Route + * @return \Symfony\Component\Routing\Route */ public function route($path, ComponentInterface $controller) { if ($controller instanceof HttpServerInterface || $controller instanceof WsServer) { diff --git a/tests/AutobahnTestSuite/bin/fuzzingserver-libuv.php b/tests/AutobahnTestSuite/bin/fuzzingserver-libuv.php deleted file mode 100644 index b3dec26..0000000 --- a/tests/AutobahnTestSuite/bin/fuzzingserver-libuv.php +++ /dev/null @@ -1,13 +0,0 @@ - 1 ? $argv[1] : 8000; - $sock->listen($port, '0.0.0.0'); - - $server = new Ratchet\Server\IoServer($app, $sock, $loop); - $server->run(); diff --git a/tests/AutobahnTestSuite/bin/fuzzingserver-libev.php b/tests/autobahn/bin/fuzzingserver-libev.php similarity index 100% rename from tests/AutobahnTestSuite/bin/fuzzingserver-libev.php rename to tests/autobahn/bin/fuzzingserver-libev.php diff --git a/tests/AutobahnTestSuite/bin/fuzzingserver-libevent.php b/tests/autobahn/bin/fuzzingserver-libevent.php similarity index 100% rename from tests/AutobahnTestSuite/bin/fuzzingserver-libevent.php rename to tests/autobahn/bin/fuzzingserver-libevent.php diff --git a/tests/AutobahnTestSuite/bin/fuzzingserver-noutf8.php b/tests/autobahn/bin/fuzzingserver-noutf8.php similarity index 100% rename from tests/AutobahnTestSuite/bin/fuzzingserver-noutf8.php rename to tests/autobahn/bin/fuzzingserver-noutf8.php diff --git a/tests/AutobahnTestSuite/bin/fuzzingserver-stream.php b/tests/autobahn/bin/fuzzingserver-stream.php similarity index 100% rename from tests/AutobahnTestSuite/bin/fuzzingserver-stream.php rename to tests/autobahn/bin/fuzzingserver-stream.php diff --git a/tests/AutobahnTestSuite/fuzzingclient-all.json b/tests/autobahn/fuzzingclient-all.json similarity index 100% rename from tests/AutobahnTestSuite/fuzzingclient-all.json rename to tests/autobahn/fuzzingclient-all.json diff --git a/tests/AutobahnTestSuite/fuzzingclient-profile.json b/tests/autobahn/fuzzingclient-profile.json similarity index 100% rename from tests/AutobahnTestSuite/fuzzingclient-profile.json rename to tests/autobahn/fuzzingclient-profile.json diff --git a/tests/AutobahnTestSuite/fuzzingclient-quick.json b/tests/autobahn/fuzzingclient-quick.json similarity index 100% rename from tests/AutobahnTestSuite/fuzzingclient-quick.json rename to tests/autobahn/fuzzingclient-quick.json diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..9d21c77 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,5 @@ +add('Ratchet', __DIR__ . '/helpers'); + $loader->register(); diff --git a/tests/Ratchet/Tests/AbstractMessageComponentTestCase.php b/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php similarity index 98% rename from tests/Ratchet/Tests/AbstractMessageComponentTestCase.php rename to tests/helpers/Ratchet/AbstractMessageComponentTestCase.php index a9223af..990e98c 100644 --- a/tests/Ratchet/Tests/AbstractMessageComponentTestCase.php +++ b/tests/helpers/Ratchet/AbstractMessageComponentTestCase.php @@ -1,5 +1,5 @@ 'websocket' + , 'Connection' => 'Upgrade' + , 'Host' => 'localhost:8080' + , 'Origin' => 'chrome://newtab' + , 'Sec-WebSocket-Protocol' => 'one, two, three' + , 'Sec-WebSocket-Key' => '9bnXNp3ae6FbFFRtPdiPXA==' + , 'Sec-WebSocket-Version' => '13' + ); + + public function setUp() { + $this->_request = new Request('GET', 'http://localhost', $this->_headers); + } + + public function testGetHeaderString() { + $this->assertEquals('Upgrade', (string)$this->_request->getHeader('connection')); + $this->assertEquals('9bnXNp3ae6FbFFRtPdiPXA==', (string)$this->_request->getHeader('Sec-Websocket-Key')); + } + + public function testGetHeaderInteger() { + $this->assertSame('13', (string)$this->_request->getHeader('Sec-Websocket-Version')); + $this->assertSame(13, (int)(string)$this->_request->getHeader('Sec-WebSocket-Version')); + } + + public function testGetHeaderObject() { + $this->assertInstanceOf('Guzzle\Http\Message\Header', $this->_request->getHeader('Origin')); + $this->assertNull($this->_request->getHeader('Non-existant-header')); + } + + public function testHeaderObjectNormalizeValues() { + $expected = 1 + substr_count($this->_headers['Sec-WebSocket-Protocol'], ','); + $protocols = $this->_request->getHeader('Sec-WebSocket-Protocol')->normalize(); + $count = 0; + + foreach ($protocols as $protocol) { + $count++; + } + + $this->assertEquals($expected, $count); + $this->assertEquals($expected, count($protocols)); + } + + public function testRequestFactoryCreateSignature() { + $ref = new \ReflectionMethod('Guzzle\Http\Message\RequestFactory', 'create'); + $this->assertEquals(2, $ref->getNumberOfRequiredParameters()); + } +} \ No newline at end of file diff --git a/tests/Ratchet/Tests/AbstractConnectionDecoratorTest.php b/tests/unit/AbstractConnectionDecoratorTest.php similarity index 98% rename from tests/Ratchet/Tests/AbstractConnectionDecoratorTest.php rename to tests/unit/AbstractConnectionDecoratorTest.php index f196c79..905cce1 100644 --- a/tests/Ratchet/Tests/AbstractConnectionDecoratorTest.php +++ b/tests/unit/AbstractConnectionDecoratorTest.php @@ -1,6 +1,6 @@ getMock('Ratchet\\Tests\\WebSocket\\Stub\\WsMessageComponentInterface'); + $mock = $this->getMock('Ratchet\WebSocket\Stub\WsMessageComponentInterface'); $mock->expects($this->once())->method('getSubProtocols')->will($this->returnValue(array('hello', 'world'))); $comp = new SessionProvider($mock, new NullSessionHandler); diff --git a/tests/Ratchet/Tests/Wamp/ServerProtocolTest.php b/tests/unit/Wamp/ServerProtocolTest.php similarity index 98% rename from tests/Ratchet/Tests/Wamp/ServerProtocolTest.php rename to tests/unit/Wamp/ServerProtocolTest.php index 4217ea3..9ecd89d 100644 --- a/tests/Ratchet/Tests/Wamp/ServerProtocolTest.php +++ b/tests/unit/Wamp/ServerProtocolTest.php @@ -1,9 +1,9 @@ conn = $this->getMock('\Ratchet\ConnectionInterface'); - $this->mock = $this->getMock('\Ratchet\Wamp\\WampServerInterface'); + $this->mock = $this->getMock('\Ratchet\Wamp\WampServerInterface'); $this->mngr = new TopicManager($this->mock); $this->conn->WAMP = new \StdClass; @@ -28,19 +28,19 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { } public function testGetTopicReturnsTopicObject() { - $class = new \ReflectionClass('Ratchet\\Wamp\\TopicManager'); + $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); $method->setAccessible(true); $topic = $method->invokeArgs($this->mngr, array('The Topic')); - $this->assertInstanceOf('Ratchet\\Wamp\\Topic', $topic); + $this->assertInstanceOf('Ratchet\Wamp\Topic', $topic); } public function testGetTopicCreatesTopicWithSameName() { $name = 'The Topic'; - $class = new \ReflectionClass('Ratchet\\Wamp\\TopicManager'); + $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); $method->setAccessible(true); @@ -50,7 +50,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { } public function testGetTopicReturnsSameObject() { - $class = new \ReflectionClass('Ratchet\\Wamp\\TopicManager'); + $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); $method->setAccessible(true); @@ -71,7 +71,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { $this->mock->expects($this->once())->method('onCall')->with( $this->conn , $id - , $this->isInstanceOf('Ratchet\\Wamp\\Topic') + , $this->isInstanceOf('Ratchet\Wamp\Topic') , array() ); @@ -80,7 +80,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { public function testOnSubscribeCreatesTopicObject() { $this->mock->expects($this->once())->method('onSubscribe')->with( - $this->conn, $this->isInstanceOf('Ratchet\\Wamp\\Topic') + $this->conn, $this->isInstanceOf('Ratchet\Wamp\Topic') ); $this->mngr->onSubscribe($this->conn, 'new topic'); @@ -89,7 +89,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { public function testTopicIsInConnectionOnSubscribe() { $name = 'New Topic'; - $class = new \ReflectionClass('Ratchet\\Wamp\\TopicManager'); + $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); $method->setAccessible(true); @@ -110,7 +110,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { public function testUnsubscribeEvent() { $name = 'in and out'; $this->mock->expects($this->once())->method('onUnsubscribe')->with( - $this->conn, $this->isInstanceOf('Ratchet\\Wamp\\Topic') + $this->conn, $this->isInstanceOf('Ratchet\Wamp\Topic') ); $this->mngr->onSubscribe($this->conn, $name); @@ -129,7 +129,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { public function testUnsubscribeRemovesTopicFromConnection() { $name = 'Bye Bye Topic'; - $class = new \ReflectionClass('Ratchet\\Wamp\\TopicManager'); + $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); $method->setAccessible(true); @@ -146,7 +146,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { $this->mock->expects($this->once())->method('onPublish')->with( $this->conn - , $this->isInstanceOf('Ratchet\\Wamp\\Topic') + , $this->isInstanceOf('Ratchet\Wamp\Topic') , $msg , $this->isType('array') , $this->isType('array') @@ -163,7 +163,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { public function testConnIsRemovedFromTopicOnClose() { $name = 'State testing'; - $class = new \ReflectionClass('Ratchet\\Wamp\\TopicManager'); + $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); $method->setAccessible(true); @@ -188,7 +188,7 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { public function testGetSubProtocolsBubbles() { $subs = array('hello', 'world'); - $app = $this->getMock('Ratchet\\Tests\\Wamp\\Stub\\WsWampServerInterface'); + $app = $this->getMock('Ratchet\Wamp\Stub\WsWampServerInterface'); $app->expects($this->once())->method('getSubProtocols')->will($this->returnValue($subs)); $mngr = new TopicManager($app); diff --git a/tests/Ratchet/Tests/Wamp/TopicTest.php b/tests/unit/Wamp/TopicTest.php similarity index 98% rename from tests/Ratchet/Tests/Wamp/TopicTest.php rename to tests/unit/Wamp/TopicTest.php index d5358d1..0a2102b 100644 --- a/tests/Ratchet/Tests/Wamp/TopicTest.php +++ b/tests/unit/Wamp/TopicTest.php @@ -1,5 +1,5 @@