Skip to content

Commit

Permalink
phergie#6 handleNick emits 'nickserv.nick' when it receives a relevan…
Browse files Browse the repository at this point in the history
…t NICK event.
  • Loading branch information
Patrick Schwisow committed Apr 9, 2015
1 parent 9186aa7 commit eba3122
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function handleQuit(UserEvent $event, Queue $queue)

/**
* Changes the nick associated with the bot in local memory when a change
* to it is successfully registed with the server.
* to it is successfully registered with the server.
*
* @param \Phergie\Irc\Event\UserEventInterface $event
* @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
Expand All @@ -129,11 +129,12 @@ public function handleNick(UserEvent $event, Queue $queue)
if (strcasecmp($event->getNick(), $connection->getNickname()) === 0) {
$params = $event->getParams();
$connection->setNickname($params['nickname']);
$this->getEventEmitter()->emit('nickserv.nick', [$connection]);
}
}

/**
* Kills ghost connections.
* Kills ghost connections.
*
* @param \Phergie\Irc\Event\ServerEventInterface $event
* @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
Expand Down
21 changes: 21 additions & 0 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class PluginTest extends \PHPUnit_Framework_TestCase
*/
protected $connection;

/**
* Mock connection
*
* @var \Evenement\EventEmitterInterface
*/
protected $emitter;

/**
* Instantiates the class under test.
*/
Expand All @@ -62,6 +69,8 @@ protected function setUp()
$this->event = $this->getMockUserEvent();
Phake::when($this->event)->getConnection()->thenReturn($this->connection);
$this->queue = $this->getMockQueue();
$this->emitter = $this->getMockEventEmitter();
$this->plugin->setEventEmitter($this->emitter);
}

/**
Expand Down Expand Up @@ -131,6 +140,7 @@ public function testHandleQuitWithRelevantEvent()
public function testHandleNickWithIrrelevantEvent()
{
Phake::verifyNoFurtherInteraction($this->queue);
Phake::verifyNoFurtherInteraction($this->emitter);
$this->plugin->handleNick($this->event, $this->queue);
}

Expand All @@ -144,6 +154,7 @@ public function testHandleNickWithRelevantEvent()
Phake::when($this->event)->getParams()->thenReturn(array('nickname' => 'Phergie'));
$this->plugin->handleNick($this->event, $this->queue);
Phake::verify($this->connection)->setNickname('Phergie');
Phake::verify($this->emitter)->emit('nickserv.nick', [$this->connection]);
}

/**
Expand Down Expand Up @@ -236,4 +247,14 @@ protected function getMockConnection()
Phake::when($connection)->getNickname()->thenReturn('Phergie');
return $connection;
}

/**
* Returns a mock event emitter.
*
* @return \Evenement\EventEmitterInterface
*/
protected function getMockEventEmitter()
{
return Phake::mock('Evenement\EventEmitterInterface');
}
}

0 comments on commit eba3122

Please sign in to comment.