Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #26 from Renegade334/devel
Browse files Browse the repository at this point in the history
Make AbstractPlugin loop aware
  • Loading branch information
elazar committed May 31, 2015
2 parents faa0351 + 2d8c70e commit 366faff
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/AbstractPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
namespace Phergie\Irc\Bot\React;

use Phergie\Irc\Client\React\ClientInterface;
use Phergie\Irc\Client\React\LoopAwareInterface;
use Evenement\EventEmitterInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerAwareInterface;
use React\EventLoop\LoopInterface;

/**
* Base class for plugins.
Expand All @@ -26,7 +28,8 @@ abstract class AbstractPlugin implements
LoggerAwareInterface,
EventEmitterAwareInterface,
ClientAwareInterface,
EventQueueFactoryAwareInterface
EventQueueFactoryAwareInterface,
LoopAwareInterface
{
/**
* Client for any adjustments the plugin may want to make
Expand Down Expand Up @@ -58,6 +61,13 @@ abstract class AbstractPlugin implements
*/
protected $queueFactory;

/**
* Event loop instance
*
* @var \React\EventLoop\LoopInterface
*/
protected $eventLoop;

/**
* Sets the client for the plugin to use.
*
Expand Down Expand Up @@ -138,12 +148,32 @@ public function getEventQueueFactory()
return $this->queueFactory;
}

/**
* Sets the event loop instance.
*
* @param \React\EventLoop\LoopInterface $loop
*/
public function setLoop(LoopInterface $loop)
{
$this->eventLoop = $loop;
}

/**
* Returns the event loop instance.
*
* @return \React\EventLoop\LoopInterface
*/
public function getLoop()
{
return $this->eventLoop;
}

/**
* Replaces bytes in a string that might cause it to be truncated or
* otherwise misinterpreted by the server.
*
* @param string $string
* @return string $string
* @return string
*/
public function escapeParam($string)
{
Expand Down
19 changes: 19 additions & 0 deletions tests/AbstractPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ public function testGetEventQueueFactory()
$this->assertNull($queueFactory);
}

/**
* Tests setLoop().
*/
public function testSetLoop()
{
$loop = Phake::mock('\React\EventLoop\LoopInterface');
$this->plugin->setLoop($loop);
$this->assertSame($loop, $this->plugin->getLoop());
}

/**
* Tests getLoop().
*/
public function testGetLoop()
{
$loop = $this->plugin->getLoop();
$this->assertNull($loop);
}

/**
* Tests that the class under test implements PluginInterface.
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/BotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ public function testRunWithDefaultPluginProcessors()
$logger = $this->getMockLogger();
$client = $this->getMockClient();
$factory = $this->getMockEventQueueFactory();
$loop = Phake::mock('\React\EventLoop\LoopInterface');
Phake::when($client)->getLogger()->thenReturn($logger);
Phake::when($client)->getLoop()->thenReturn($loop);

$config = array(
'plugins' => array($plugin),
Expand All @@ -446,6 +448,7 @@ public function testRunWithDefaultPluginProcessors()
Phake::verify($plugin)->setClient($client);
Phake::verify($plugin)->setEventQueueFactory($factory);
Phake::verify($plugin)->setLogger($logger);
Phake::verify($plugin)->setLoop($loop);
}

/**
Expand Down

0 comments on commit 366faff

Please sign in to comment.