/** * Tests handleEvent(). */ public function testHandleEvent() { $event1 = $this->getMockEvent(); $connection1 = $this->getMockConnection(); Phake::when($event1)->getConnection()->thenReturn($connection1); $queue1 = $this->getMockEventQueue(); $event2 = $this->getMockEvent(); $connection2 = $this->getMockConnection(); Phake::when($event2)->getConnection()->thenReturn($connection2); $queue2 = $this->getMockEventQueue(); $logger = $this->getMockLogger(); $plugin = new Plugin(['nicks' => ['Foo', 'Foo_', 'FooBar']]); $plugin->setLogger($logger); $plugin->handleEvent($event1, $queue1); $plugin->handleEvent($event1, $queue1); $plugin->handleEvent($event2, $queue2); $plugin->handleEvent($event1, $queue1); $plugin->handleEvent($event2, $queue2); $plugin->handleEvent($event1, $queue1); $plugin->handleEvent($event2, $queue2); $plugin->handleEvent($event2, $queue2); Phake::verify($logger, Phake::times(2))->debug("[AltNick] Switching nick to 'Foo'"); Phake::verify($logger, Phake::times(2))->debug("[AltNick] Switching nick to 'Foo_'"); Phake::verify($logger, Phake::times(2))->debug("[AltNick] Switching nick to 'FooBar'"); Phake::inOrder(Phake::verify($queue1)->ircNick('Foo'), Phake::verify($connection1)->setNickname('Foo'), Phake::verify($queue1)->ircNick('Foo_'), Phake::verify($connection1)->setNickname('Foo_'), Phake::verify($queue2)->ircNick('Foo'), Phake::verify($connection2)->setNickname('Foo'), Phake::verify($queue1)->ircNick('FooBar'), Phake::verify($connection1)->setNickname('FooBar'), Phake::verify($queue2)->ircNick('Foo_'), Phake::verify($connection2)->setNickname('Foo_'), Phake::verify($queue1)->ircQuit('All specified alternate nicks are in use'), Phake::verify($queue2)->ircNick('FooBar'), Phake::verify($connection2)->setNickname('FooBar'), Phake::verify($queue2)->ircQuit('All specified alternate nicks are in use')); }
/** * Tests handleQuit() with a nick that should be ignored. */ public function testHandleQuitIgnoreEvent() { $connection = $this->getMockConnection(); $event = $this->getMockUserEvent(); Phake::when($event)->getConnection()->thenReturn($connection); $userEvent = $this->getMockUserEvent(); Phake::when($userEvent)->getConnection()->thenReturn($connection); $queue = $this->getMockEventQueue(); $logger = $this->getMockLogger(); $plugin = new Plugin(['nicks' => ['Foo', 'Foo_'], 'recovery' => true]); $plugin->setLogger($logger); Phake::when($event)->getParams()->thenReturn([1 => 'Phergie', 2 => 'Nickname is already in use.']); $plugin->handleEvent($event, $queue); Phake::verifyNoFurtherInteraction($queue); Phake::when($userEvent)->getNick()->thenReturn('SomeoneElse'); $plugin->handleQuit($userEvent, $queue); }