diff options
author | LEDfan <tobia@ledfan.be> | 2016-01-21 18:40:11 +0300 |
---|---|---|
committer | LEDfan <tobia@ledfan.be> | 2016-01-21 18:40:11 +0300 |
commit | 4b8761a130fe2adbddd2741f24e97a55dc285397 (patch) | |
tree | a6b3eba90a538945547e3d6432b1955bfae6e910 /tests/unit | |
parent | b9b303c5ae3bc570dc709474c25005b634a58519 (diff) |
Fix and add more test data to unit tests
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/controller/HttpBindControllerTest.php | 98 |
1 files changed, 84 insertions, 14 deletions
diff --git a/tests/unit/controller/HttpBindControllerTest.php b/tests/unit/controller/HttpBindControllerTest.php index d51d294..36a8a35 100644 --- a/tests/unit/controller/HttpBindControllerTest.php +++ b/tests/unit/controller/HttpBindControllerTest.php @@ -102,18 +102,30 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase { } public function IQProvider() { + $expStanza1 = new Stanza(); + $expStanza1->setStanza('<iq to="admin@localhost" type="result" id="2:sendIQ"><query xmlns="jabber:iq:roster"><item jid="derp@localhost" name="derp"></item></query></iq><iq to="admin@localhost" type="result" id="2:sendIQ"><query xmlns="jabber:iq:roster"><item jid="derp@localhost" name="derp"></item></query></iq><iq to="admin@localhost" type="result" id="2:sendIQ"><query xmlns="jabber:iq:roster"><item jid="derp@localhost" name="derp"></item></query></iq>'); + + $result1 = new Stanza(); + $result1->setStanza('<iq to="admin@localhost" type="result" id="2:sendIQ"><query xmlns="jabber:iq:roster"><item jid="derp@localhost" name="derp"></item></query></iq>'); + + $result2 = new Stanza(); + $result2->setStanza(null); + $expStanza2 = new Stanza(); + $expStanza2->setStanza(null); return [ [ '<body rid=\'897878733\' xmlns=\'http://jabber.org/protocol/httpbind\' sid=\'7862\'><iq from=\'admin@localhost\' to=\'localhost\' type=\'get\' xmlns=\'jabber:client\' id=\'1:sendIQ\'><query xmlns=\'http://jabber.org/protocol/disco#info\' node=\'undefined#undefined\'/></iq><iq type=\'get\' xmlns=\'jabber:client\' id=\'2:sendIQ\'><query xmlns=\'jabber:iq:roster\'/></iq><iq type=\'get\' to=\'admin@localhost\' xmlns=\'jabber:client\' id=\'3:sendIQ\'><vCard xmlns=\'vcard-temp\'/></iq></body>', - '<iq to="admin@localhost" type="result" id="2:sendIQ"><query xmlns="jabber:iq:roster"><item jid="derp@localhost" name="derp"></item></query></iq>', - '<iq to="admin@localhost" type="result" id="2:sendIQ"><query xmlns="jabber:iq:roster"><item jid="derp@localhost" name="derp"></item></query></iq><iq to="admin@localhost" type="result" id="2:sendIQ"><query xmlns="jabber:iq:roster"><item jid="derp@localhost" name="derp"></item></query></iq><iq to="admin@localhost" type="result" id="2:sendIQ"><query xmlns="jabber:iq:roster"><item jid="derp@localhost" name="derp"></item></query></iq>', // we ask for 3 IQ's thus return 3 values - $this->once() + $result1, + $expStanza1, // we ask for 3 IQ's thus return 3 values + $this->once(), + $this->exactly(3) ], [ '<body rid=\'897878734\' xmlns=\'http://jabber.org/protocol/httpbind\' sid=\'7862\'><iq from=\'admin@localhost\' to=\'localhost\' type=\'get\' xmlns=\'jabber:client\' id=\'1:sendIQ\'><query xmlns=\'http://jabber.org/protocol/disco#info\' node=\'undefined#undefined\'/></iq><iq type=\'get\' xmlns=\'jabber:client\' id=\'2:sendIQ\'><query xmlns=\'jabber:iq:roster\'/></iq><iq type=\'get\' to=\'admin@localhost\' xmlns=\'jabber:client\' id=\'3:sendIQ\'><vCard xmlns=\'vcard-temp\'/></iq></body>', - null, - null, - $this->exactly(10) + $result2, + $expStanza2, + $this->once(), + $this->exactly(3) ] ]; } @@ -121,14 +133,14 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase { /** * @dataProvider IQProvider */ - public function testIQHandlerWhenNoDbResults($body, $result, $expected, $pollCount) { + public function testIQHandlerWhenNoDbResults($body, $result, $expected, $pollCount, $handlerCount) { $ex = new DoesNotExistException(); $this->setUpController($body); $this->mockLock(); $expResponse = new XMPPResponse(); $expResponse->write($expected); - $this->iqHandler->expects($this->any()) // FIXME + $this->iqHandler->expects($handlerCount) ->method('handle') ->will($this->returnValue($result)); @@ -152,7 +164,7 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase { $expResponse = new XMPPResponse(); $expResponse->write($result); - $this->iqHandler->expects($this->any()) // FIXME + $this->iqHandler->expects($this->never()) ->method('handle') ->will($this->returnValue($result)); @@ -182,9 +194,69 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase { $expResponse = new XMPPResponse(); - $this->messageHandler->expects($this->any()) // FIXME + $this->messageHandler->expects($this->once()) + ->method('handle'); + + $this->stanzaMapper->expects($this->exactly(10)) + ->method('findByTo') + ->with('john') + ->will($this->throwException($ex)); + + $response = $this->controller->index(); + $this->assertEquals($expResponse, $response); + $this->assertEquals($expResponse->render(), $response->render()); + } + + + public function testMultipleMessageNoDbHandler() { + echo "================================================"; + $body = <<<XML + <body rid='897878959' xmlns='http://jabber.org/protocol/httpbind' sid='7862'> + <message to='derp@own.dev' type='chat' id='1452960296859-msg' xmlns='jabber:client'><body>abc</body></message> + <message to='derp@own.dev' type='chat' id='1452960296860-msg' xmlns='jabber:client'><body>abc2</body></message> + <message to='derp@own.dev' type='chat' id='1452960296861-msg' xmlns='jabber:client'><body>abc3</body></message> + </body> +XML; + $ex = new DoesNotExistException(); + $this->setUpController($body); + $this->mockLock(); + + $expResponse = new XMPPResponse(); + $this->messageHandler->expects($this->any()) ->method('handle'); + $this->messageHandler->expects($this->exactly(3)) + ->method('handle') + ->withConsecutive( + $this->equalTo( + [ 'name' => '{jabber:client}message', + ' value' => [ + '{jabber:client}body' => 'abc', + ], + 'attributes' => [ + 'to' => 'derp@own.dev', + 'type' => 'chat', + 'id' => '1452960296859-msg', + ]]), + $this->equalTo([ 'name' => '{jabber:client}message', + 'value' => [ + '{jabber:client}body' => 'abc2', + ], 'attributes' => [ + 'to' => 'derp@own.dev', + 'type' => 'chat', + 'id' => '1452960296860-msg', + ]]), + $this->equalTo([ 'name' => '{jabber:client}message', + 'value' => [ + '{jabber:client}body' => 'abc3', + ], 'attributes' => [ + 'to' => 'derp@own.dev', + 'type' => 'chat', + 'id' => '1452960296861-msg', + ]]) + + ); + $this->stanzaMapper->expects($this->exactly(10)) ->method('findByTo') ->with('john') @@ -203,8 +275,8 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase { $expResponse = new XMPPResponse(); $expResponse->write('test'); - $this->messageHandler->expects($this->any()) // FIXME - ->method('handle'); + $this->messageHandler->expects($this->once()) + ->method('handle'); $r1 = $this->getMockBuilder('Sabre\XML\XmlSerializable')->disableOriginalConstructor()->getMock(); $r1->expects($this->once()) @@ -239,6 +311,4 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase { $this->controller->index(); } - - } |