From 45fb69d68b41228b69939ded870b985bff342761 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Mon, 5 Sep 2011 17:34:51 -0400 Subject: [PATCH] Unit testing coverage --- lib/Ratchet/Socket.php | 10 ++++++++++ tests/Ratchet/Tests/Protocol/WebSocket/ServerTest.php | 4 ++++ tests/Ratchet/Tests/SocketTest.php | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/lib/Ratchet/Socket.php b/lib/Ratchet/Socket.php index 76af23d..2d493b8 100644 --- a/lib/Ratchet/Socket.php +++ b/lib/Ratchet/Socket.php @@ -35,6 +35,10 @@ class Socket { /** * @internal + * @param int Specifies the protocol family to be used by the socket. + * @param int The type of communication to be used by the socket + * @param int Sets the specific protocol within the specified domain to be used when communicating on the returned socket + * @return Array */ protected static function getConfig($domain = null, $type = null, $protocol = null) { foreach (static::$_defaults as $key => $val) { @@ -48,11 +52,17 @@ class Socket { /** * @internal + * @param string + * @param Array + * @return mixed + * @throws \BadMethodCallException */ public function __call($method, $arguments) { if (function_exists('socket_' . $method)) { array_unshift($arguments, $this->_socket); return call_user_func_array('socket_' . $method, $arguments); } + + throw new \BadMethodCallException("{$method} is not a valid socket function"); } } \ No newline at end of file diff --git a/tests/Ratchet/Tests/Protocol/WebSocket/ServerTest.php b/tests/Ratchet/Tests/Protocol/WebSocket/ServerTest.php index 08cbf2f..9acdad7 100644 --- a/tests/Ratchet/Tests/Protocol/WebSocket/ServerTest.php +++ b/tests/Ratchet/Tests/Protocol/WebSocket/ServerTest.php @@ -23,4 +23,8 @@ class ServerTest extends \PHPUnit_Framework_TestCase { $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/SocketTest.php b/tests/Ratchet/Tests/SocketTest.php index 72ec3e9..41d1ed1 100644 --- a/tests/Ratchet/Tests/SocketTest.php +++ b/tests/Ratchet/Tests/SocketTest.php @@ -38,4 +38,14 @@ class SocketTest extends \PHPUnit_Framework_TestCase { $this->setExpectedException('\\Ratchet\\Exception'); $socket = new RealSocket('invalid', 'param', 'derp'); } + + public function testConstructAndCallByOpenAndClose() { + $socket = new RealSocket(); + $socket->close(); + } + + public function testInvalidSocketCall() { + $this->setExpectedException('\\BadMethodCallException'); + $this->_socket->fake_method(); + } } \ No newline at end of file