diff --git a/tests/Ratchet/Tests/Component/Server/IpBlackListComponentTest.php b/tests/Ratchet/Tests/Component/Server/IpBlackListComponentTest.php index 55755b7..88f4dc4 100644 --- a/tests/Ratchet/Tests/Component/Server/IpBlackListComponentTest.php +++ b/tests/Ratchet/Tests/Component/Server/IpBlackListComponentTest.php @@ -5,13 +5,15 @@ use Ratchet\Tests\Mock\Connection; use Ratchet\Tests\Mock\Component as MockComponent; /** - * @covers Ratchet\Component\Server\IpBlackList + * @covers Ratchet\Component\Server\IpBlackListComponent */ class IpBlackListComponentTest extends \PHPUnit_Framework_TestCase { protected $_comp; + protected $_mock; public function setUp() { - $this->_comp = new IpBlackListComponent(new MockComponent); + $this->_mock = new MockComponent; + $this->_comp = new IpBlackListComponent($this->_mock); } public function testBlockAndCloseOnOpen() { @@ -29,8 +31,41 @@ class IpBlackListComponentTest extends \PHPUnit_Framework_TestCase { $blockTwo = '192.168.1.1'; $unblock = '75.119.207.140'; - $this->_comp->blockAddress($unblock)->blockAddress($blockOne)->unblockAddress($unblock)->blockAddress($blockTwo); + $this->_comp + ->blockAddress($unblock) + ->blockAddress($blockOne) + ->unblockAddress($unblock) + ->blockAddress($blockTwo) + ; $this->assertEquals(array($blockOne, $blockTwo), $this->_comp->getBlockedAddresses()); } + + public function testDecoratingMethods() { + $conn1 = new Connection; + $conn2 = new Connection; + $conn3 = new Connection; + + $this->_comp->onOpen($conn1); + $this->_comp->onOpen($conn3); + $this->_comp->onOpen($conn2); + $this->assertSame($conn2, $this->_mock->last['onOpen'][0]); + + $msg = 'Hello World!'; + $this->_comp->onMessage($conn1, $msg); + $this->assertSame($conn1, $this->_mock->last['onMessage'][0]); + $this->assertEquals($msg, $this->_mock->last['onMessage'][1]); + + $this->_comp->onClose($conn3); + $this->assertSame($conn3, $this->_mock->last['onClose'][0]); + + try { + throw new \Exception('I threw an error'); + } catch (\Exception $e) { + } + + $this->_comp->onError($conn2, $e); + $this->assertEquals($conn2, $this->_mock->last['onError'][0]); + $this->assertEquals($e, $this->_mock->last['onError'][1]); + } } \ No newline at end of file