/**
  * Tests getSource().
  *
  * @param string $target
  * @param string $source
  * @dataProvider dataProviderGetSource
  */
 public function testGetSource($target, $source)
 {
     $connection = Phake::mock('\\Phergie\\Irc\\ConnectionInterface');
     Phake::when($connection)->getNickname()->thenReturn('bot');
     $this->event->setNick('user');
     $this->event->setConnection($connection);
     $this->event->setTargets(array($target));
     $this->assertSame($source, $this->event->getSource());
 }
 /**
  * @param Url $url
  * @param UserEvent $event
  * @param EventQueue $queue
  */
 protected function sendMessage(Url $url, UserEvent $event, EventQueue $queue)
 {
     $message = $this->getHandler()->handle($url);
     $queue->ircPrivmsg($event->getSource(), $message);
 }
 /**
  * Modifies a term's karma.
  *
  * @param string $term   Term to modify
  * @param string $action Karma action (either ++ or --)
  * @param \Phergie\Irc\Event\UserEvent $event
  * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
  * @return bool|\React\Promise\Promise
  */
 protected function modifyKarma($term, $action, UserEvent $event, Queue $queue)
 {
     $nick = $event->getNick();
     $canonicalTerm = $this->getCanonicalTerm($term, $nick);
     if ($canonicalTerm == strtolower($nick)) {
         $message = 'You can\'t give yourself karma.';
         $queue->ircPrivmsg($event->getSource(), $message);
         return false;
     }
     $karma = 0;
     return $this->messenger->rpc(MessageFactory::rpc('fetchKarma', ['term' => $canonicalTerm]))->then(function ($payload) use($event, $queue, $action, $term, $canonicalTerm, &$karma) {
         $this->logDebug('payload: ' . var_export($payload, true));
         $karma = $payload['karma'] + ($action == '++' ? 1 : -1);
         return MessageFactory::rpc('modifyKarma', ['term' => $canonicalTerm, 'karma' => $karma]);
     })->then([$this->messenger, 'rpc'])->then(function ($payload) use($event, $queue, $action, $term) {
         $this->logDebug('payload: ' . var_export($payload, true));
         $queue->ircPrivmsg($event->getSource(), $this->getUserMessage('karma' . $action, $term));
         return $payload['karma'];
     });
 }