From f2423f09e564215f96c7b954c85b0c4a55cc9006 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Tue, 6 Sep 2011 14:30:14 -0400 Subject: [PATCH] Fixed Socket bugs from Unit Testing --- .gitignore | 1 + lib/Ratchet/Socket.php | 6 +++--- tests/Ratchet/Tests/Mock/Socket.php | 2 +- tests/Ratchet/Tests/SocketTest.php | 3 +-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 7c2eb7e..2a2625d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ phpunit.xml coverage +docs sandbox \ No newline at end of file diff --git a/lib/Ratchet/Socket.php b/lib/Ratchet/Socket.php index 1265a4b..2982025 100644 --- a/lib/Ratchet/Socket.php +++ b/lib/Ratchet/Socket.php @@ -41,9 +41,7 @@ class Socket { */ public static function createFromConfig(ProtocolInterface $protocol) { $config = $protocol::getDefaultConfig(); - -// todo - this is wrong when class is extended, I don't have internet, can't look up the fn - unit test fails - $class = __CLASS__; + $class = get_called_class(); $socket = new $class($config['domain'] ?: null, $config['type'] ?: null, $config['protocol'] ?: null); @@ -54,6 +52,8 @@ class Socket { } } } + + return $socket; } /** diff --git a/tests/Ratchet/Tests/Mock/Socket.php b/tests/Ratchet/Tests/Mock/Socket.php index 76c2649..9cf8eea 100644 --- a/tests/Ratchet/Tests/Mock/Socket.php +++ b/tests/Ratchet/Tests/Mock/Socket.php @@ -30,7 +30,7 @@ class Socket extends RealSocket { } public function set_option($level, $optname, $optval) { - if (!is_array($this->_options[$level])) { + if (!isset($this->_options[$level])) { $this->_options[$level] = Array(); } diff --git a/tests/Ratchet/Tests/SocketTest.php b/tests/Ratchet/Tests/SocketTest.php index fd6cad7..967638b 100644 --- a/tests/Ratchet/Tests/SocketTest.php +++ b/tests/Ratchet/Tests/SocketTest.php @@ -54,8 +54,7 @@ class SocketTest extends \PHPUnit_Framework_TestCase { $protocol = new Protocol(); $socket = Socket::createFromConfig($protocol); - $constraint = $this->isInstanceOf('\\Ratchet\\Socket'); - $this->assertThat($socket, $constraint); + $this->assertInstanceOf('\\Ratchet\\Socket', $socket); } public function testCreationFromConfigOutputMatchesInput() {