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

Commit 2d8c70e

Browse files
committed
Add EventLoopAwareInterface to AbstractPlugin
1 parent 92f9963 commit 2d8c70e

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/AbstractPlugin.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
namespace Phergie\Irc\Bot\React;
1212

1313
use Phergie\Irc\Client\React\ClientInterface;
14+
use Phergie\Irc\Client\React\LoopAwareInterface;
1415
use Evenement\EventEmitterInterface;
1516
use Psr\Log\LoggerInterface;
1617
use Psr\Log\LoggerAwareInterface;
18+
use React\EventLoop\LoopInterface;
1719

1820
/**
1921
* Base class for plugins.
@@ -26,7 +28,8 @@ abstract class AbstractPlugin implements
2628
LoggerAwareInterface,
2729
EventEmitterAwareInterface,
2830
ClientAwareInterface,
29-
EventQueueFactoryAwareInterface
31+
EventQueueFactoryAwareInterface,
32+
LoopAwareInterface
3033
{
3134
/**
3235
* Client for any adjustments the plugin may want to make
@@ -58,6 +61,13 @@ abstract class AbstractPlugin implements
5861
*/
5962
protected $queueFactory;
6063

64+
/**
65+
* Event loop instance
66+
*
67+
* @var \React\EventLoop\LoopInterface
68+
*/
69+
protected $eventLoop;
70+
6171
/**
6272
* Sets the client for the plugin to use.
6373
*
@@ -138,6 +148,26 @@ public function getEventQueueFactory()
138148
return $this->queueFactory;
139149
}
140150

151+
/**
152+
* Sets the event loop instance.
153+
*
154+
* @param \React\EventLoop\LoopInterface $loop
155+
*/
156+
public function setLoop(LoopInterface $loop)
157+
{
158+
$this->eventLoop = $loop;
159+
}
160+
161+
/**
162+
* Returns the event loop instance.
163+
*
164+
* @return \React\EventLoop\LoopInterface
165+
*/
166+
public function getLoop()
167+
{
168+
return $this->eventLoop;
169+
}
170+
141171
/**
142172
* Replaces bytes in a string that might cause it to be truncated or
143173
* otherwise misinterpreted by the server.

tests/AbstractPluginTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,25 @@ public function testGetEventQueueFactory()
113113
$this->assertNull($queueFactory);
114114
}
115115

116+
/**
117+
* Tests setLoop().
118+
*/
119+
public function testSetLoop()
120+
{
121+
$loop = Phake::mock('\React\EventLoop\LoopInterface');
122+
$this->plugin->setLoop($loop);
123+
$this->assertSame($loop, $this->plugin->getLoop());
124+
}
125+
126+
/**
127+
* Tests getLoop().
128+
*/
129+
public function testGetLoop()
130+
{
131+
$loop = $this->plugin->getLoop();
132+
$this->assertNull($loop);
133+
}
134+
116135
/**
117136
* Tests that the class under test implements PluginInterface.
118137
*/

tests/BotTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,9 @@ public function testRunWithDefaultPluginProcessors()
429429
$logger = $this->getMockLogger();
430430
$client = $this->getMockClient();
431431
$factory = $this->getMockEventQueueFactory();
432+
$loop = Phake::mock('\React\EventLoop\LoopInterface');
432433
Phake::when($client)->getLogger()->thenReturn($logger);
434+
Phake::when($client)->getLoop()->thenReturn($loop);
433435

434436
$config = array(
435437
'plugins' => array($plugin),
@@ -446,6 +448,7 @@ public function testRunWithDefaultPluginProcessors()
446448
Phake::verify($plugin)->setClient($client);
447449
Phake::verify($plugin)->setEventQueueFactory($factory);
448450
Phake::verify($plugin)->setLogger($logger);
451+
Phake::verify($plugin)->setLoop($loop);
449452
}
450453

451454
/**

0 commit comments

Comments
 (0)