diff --git a/lib/Ratchet/Socket.php b/lib/Ratchet/Socket.php index 92ed6d4..fdd4898 100644 --- a/lib/Ratchet/Socket.php +++ b/lib/Ratchet/Socket.php @@ -11,13 +11,18 @@ class Socket { ); public function __construct($domain = null, $type = null, $protocol = null) { - foreach (static::$_default as $key => $val) { + list($domain, $type, $protocol) = static::getConfig($domain, $type, $protocol); + $this->_socket = socket_create($domain, $type, $protocol); + } + + protected static function getConfig($domain = null, $type = null, $protocol = null) { + foreach (static::$_defaults as $key => $val) { if (null === $$key) { $$key = $val; } } - $this->_socket = socket_create($domain, $type, $protocol); + return Array($domain, $type, $protocol); } public function __call($method, $arguments) { diff --git a/tests/Ratchet/Tests/Mock/Socket.php b/tests/Ratchet/Tests/Mock/Socket.php new file mode 100644 index 0000000..5f7bbf9 --- /dev/null +++ b/tests/Ratchet/Tests/Mock/Socket.php @@ -0,0 +1,41 @@ +_options[$level][$optname]; + } + + public function listen($backlog) { + } + + public function recv($buf, $len, $flags) { + } + + public function set_option($level, $optname, $optval) { + if (!is_array($this->_options[$level])) { + $this->_options[$level] = Array(); + } + + $this->_options[$level][$optname] = $optval; + } + + public function write($buffer, $length = 0) { + } +} \ No newline at end of file diff --git a/tests/Ratchet/Tests/ServerTest.php b/tests/Ratchet/Tests/ServerTest.php new file mode 100644 index 0000000..78ab40e --- /dev/null +++ b/tests/Ratchet/Tests/ServerTest.php @@ -0,0 +1,20 @@ +_server = new Server(new Socket()); + } + + public function testServerHasServerInterface() { + $constraint = $this->isInstanceOf('\\Ratchet\\ServerInterface'); + $this->assertThat($this->_server, $constraint); + } +} \ No newline at end of file diff --git a/tests/Ratchet/Tests/SocketTest.php b/tests/Ratchet/Tests/SocketTest.php new file mode 100644 index 0000000..9538ddb --- /dev/null +++ b/tests/Ratchet/Tests/SocketTest.php @@ -0,0 +1,29 @@ +getMethod($name); + $method->setAccessible(true); + + return $method; + } + + public function setUp() { + $this->_socket = new Socket(); + } + + public function testGetConfigForConstruct() { + $ref_conf = static::getMethod('getConfig'); + $config = $ref_conf->invokeArgs($this->_socket, Array()); + + $this->assertEquals(array_values(Socket::$_defaults), $config); + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a8909cb..2f02d40 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,8 @@ register(); + $app = new SplClassLoader('Ratchet', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lib'); $app->register(); \ No newline at end of file