Fixed Socket bugs from Unit Testing

This commit is contained in:
Chris Boden 2011-09-06 14:30:14 -04:00
parent 203b68b9cb
commit f2423f09e5
4 changed files with 6 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
phpunit.xml phpunit.xml
coverage coverage
docs
sandbox sandbox

View File

@ -41,9 +41,7 @@ class Socket {
*/ */
public static function createFromConfig(ProtocolInterface $protocol) { public static function createFromConfig(ProtocolInterface $protocol) {
$config = $protocol::getDefaultConfig(); $config = $protocol::getDefaultConfig();
$class = get_called_class();
// todo - this is wrong when class is extended, I don't have internet, can't look up the fn - unit test fails
$class = __CLASS__;
$socket = new $class($config['domain'] ?: null, $config['type'] ?: null, $config['protocol'] ?: null); $socket = new $class($config['domain'] ?: null, $config['type'] ?: null, $config['protocol'] ?: null);
@ -54,6 +52,8 @@ class Socket {
} }
} }
} }
return $socket;
} }
/** /**

View File

@ -30,7 +30,7 @@ class Socket extends RealSocket {
} }
public function set_option($level, $optname, $optval) { public function set_option($level, $optname, $optval) {
if (!is_array($this->_options[$level])) { if (!isset($this->_options[$level])) {
$this->_options[$level] = Array(); $this->_options[$level] = Array();
} }

View File

@ -54,8 +54,7 @@ class SocketTest extends \PHPUnit_Framework_TestCase {
$protocol = new Protocol(); $protocol = new Protocol();
$socket = Socket::createFromConfig($protocol); $socket = Socket::createFromConfig($protocol);
$constraint = $this->isInstanceOf('\\Ratchet\\Socket'); $this->assertInstanceOf('\\Ratchet\\Socket', $socket);
$this->assertThat($socket, $constraint);
} }
public function testCreationFromConfigOutputMatchesInput() { public function testCreationFromConfigOutputMatchesInput() {