diff --git a/lib/Ratchet/ApplicationInterface.php b/lib/Ratchet/ApplicationInterface.php deleted file mode 100644 index 1241c5f..0000000 --- a/lib/Ratchet/ApplicationInterface.php +++ /dev/null @@ -1,15 +0,0 @@ - AF_INET + , 'type' => SOCK_STREAM + , 'protocol' => SOL_TCP + , 'options' => Array( + SOL_SOCKET => Array(SO_REUSEADDR => 1) + ) + ); + } + + /** + * @return string + */ + function getName() { + return __CLASS__; + } + + function handleConnect() { + } + + function handleMessage() { + } + + function handleClose() { + } +} \ No newline at end of file diff --git a/lib/Ratchet/Protocol/WebSocket/Server.php b/lib/Ratchet/Protocol/WebSocket/Server.php deleted file mode 100644 index b896111..0000000 --- a/lib/Ratchet/Protocol/WebSocket/Server.php +++ /dev/null @@ -1,32 +0,0 @@ -_server = $server; - } - - /** - * @return Array - */ - public static function getDefaultConfig() { - return Array( - 'domain' => AF_INET - , 'type' => SOCK_STREAM - , 'protocol' => SOL_TCP - , 'options' => Array( - SOL_SOCKET => Array(SO_REUSEADDR => 1) - ) - ); - } - - public function attatchApplication(ApplicationInterface $app) {} - - public function run($address = '127.0.0.1', $port = 1025) { - } -} \ No newline at end of file diff --git a/lib/Ratchet/ReceiverInterface.php b/lib/Ratchet/ReceiverInterface.php new file mode 100644 index 0000000..feadd46 --- /dev/null +++ b/lib/Ratchet/ReceiverInterface.php @@ -0,0 +1,15 @@ +_debug = (boolean)$debug; } - public function attatchApplication(ApplicationInterface $app) { - $this->_app = $app; + public function attatchReceiver(ReceiverInterface $receiver) { + $this->_receivers[spl_object_hash($receiver)] = $receiver; } /* @@ -28,8 +28,8 @@ class Server implements ServerInterface { * @throws Ratchet\Exception */ public function run($address = '127.0.0.1', $port = 1025) { - if (!($this->_app instanceof ApplicationInterface)) { - throw new \RuntimeException("No application has been bound to the server"); + if (count($this->_receivers) == 0) { + throw new \RuntimeException("No receiver has been attatched to the server"); } set_time_limit(0); diff --git a/lib/Ratchet/ServerInterface.php b/lib/Ratchet/ServerInterface.php index 0566126..b39d3ee 100644 --- a/lib/Ratchet/ServerInterface.php +++ b/lib/Ratchet/ServerInterface.php @@ -2,7 +2,7 @@ namespace Ratchet; interface ServerInterface { - function attatchApplication(ApplicationInterface $app); + function attatchReceiver(ReceiverInterface $receiver); function run($address = '127.0.0.1', $port = 1025); } \ No newline at end of file diff --git a/tests/Ratchet/Tests/Mock/Application.php b/tests/Ratchet/Tests/Mock/Application.php index 43cb3c6..08e8c79 100644 --- a/tests/Ratchet/Tests/Mock/Application.php +++ b/tests/Ratchet/Tests/Mock/Application.php @@ -1,18 +1,18 @@ _server = new WebServer(new Server(new Socket())); - } - - public function testServerImplementsServerInterface() { - $constraint = $this->isInstanceOf('\\Ratchet\\ServerInterface'); - $this->assertThat($this->_server, $constraint); - } - - public function testServerImplementsProtocolInterface() { - $constraint = $this->isInstanceOf('\\Ratchet\\Protocol\ProtocolInterface'); - $this->assertThat($this->_server, $constraint); - } - - public function testGetConfigReturnsArray() { - $this->assertInternalType('array', $this->_server->getDefaultConfig()); - } -} \ No newline at end of file diff --git a/tests/Ratchet/Tests/Protocol/WebSocketTest.php b/tests/Ratchet/Tests/Protocol/WebSocketTest.php new file mode 100644 index 0000000..3aabc49 --- /dev/null +++ b/tests/Ratchet/Tests/Protocol/WebSocketTest.php @@ -0,0 +1,29 @@ +_ws = new WebSocket(); + } + + public function testServerImplementsServerInterface() { + $constraint = $this->isInstanceOf('\\Ratchet\\ReceiverInterface'); + $this->assertThat($this->_ws, $constraint); + } + + public function testServerImplementsProtocolInterface() { + $constraint = $this->isInstanceOf('\\Ratchet\\Protocol\ProtocolInterface'); + $this->assertThat($this->_ws, $constraint); + } + + public function testGetConfigReturnsArray() { + $this->assertInternalType('array', $this->_ws->getDefaultConfig()); + } +} \ No newline at end of file diff --git a/tests/Ratchet/Tests/ServerTest.php b/tests/Ratchet/Tests/ServerTest.php index f271e92..b7d193e 100644 --- a/tests/Ratchet/Tests/ServerTest.php +++ b/tests/Ratchet/Tests/ServerTest.php @@ -24,17 +24,18 @@ class ServerTest extends \PHPUnit_Framework_TestCase { $this->_server->run(); } - public function testAttatchedApplicationIsSet() { + public function testAttatchedReceiverIsSet() { $app = new TestApp(); - $this->_server->attatchApplication($app); - $this->assertAttributeEquals($app, '_app', $this->_server); + $this->_server->attatchReceiver($app); +// todo, use proper assertions...can't look them up atm, no internet + $this->assertAttributeEquals(Array(spl_object_hash($app) => $app), '_receivers', $this->_server); } public function testBindToInvalidAddress() { $app = new TestApp(); - $this->_server->attatchApplication($app); + $this->_server->attatchReceiver($app); $this->setExpectedException('\\Ratchet\\Exception'); $this->_server->run('la la la', 80);