diff --git a/src/AbstractPlugin.php b/src/AbstractPlugin.php index 77c44e1..287c29e 100644 --- a/src/AbstractPlugin.php +++ b/src/AbstractPlugin.php @@ -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. @@ -26,7 +28,8 @@ abstract class AbstractPlugin implements LoggerAwareInterface, EventEmitterAwareInterface, ClientAwareInterface, - EventQueueFactoryAwareInterface + EventQueueFactoryAwareInterface, + LoopAwareInterface { /** * Client for any adjustments the plugin may want to make @@ -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. * @@ -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) { diff --git a/tests/AbstractPluginTest.php b/tests/AbstractPluginTest.php index 1ec9bed..b5df210 100644 --- a/tests/AbstractPluginTest.php +++ b/tests/AbstractPluginTest.php @@ -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. */ diff --git a/tests/BotTest.php b/tests/BotTest.php index 9c73c8a..540a91d 100644 --- a/tests/BotTest.php +++ b/tests/BotTest.php @@ -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), @@ -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); } /**