Skip to content

Commit

Permalink
Merge branch 'phergie-irc-plugin-react-magic-eightball-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
David Stockton committed Nov 28, 2014
2 parents ad5ed22 + 4ec4d6f commit 318dcb4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ See Phergie documentation for more information on
The Magic Eightball plugin requires a response provider with the AnswerProvider interface. The EightballProvider comes
with the plugin but you can provide your own class if you want to provide different answers.

```php
new \Phergie\Irc\Plugin\React\MagicEightBall\Plugin()
```

By default, the Plugin will provide \Phergie\Irc\Plugin\React\MagicEightBall\EightballProvider() if you do not
specify a provider. You can also create your own provider and send it into the plugin to get different responses.

```php
new \Phergie\Irc\Plugin\React\MagicEightBall\Plugin(
new \Phergie\Irc\Plugin\React\MagicEightBall\EightballProvider()
new \Phergie\Irc\Plugin\React\MagicEightBall\EightballProvider() // Replace with your own provider
)
```


## Tests

To run the unit test suite:
Expand Down
5 changes: 4 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ class Plugin extends AbstractPlugin
*/
protected $provider;

public function __construct(AnswerProvider $provider)
public function __construct(AnswerProvider $provider = null)
{
if (is_null($provider)) {
$provider = new EightballProvider();
}
$this->provider = $provider;
}

Expand Down
13 changes: 12 additions & 1 deletion tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

use Phake;
use Phergie\Irc\Bot\React\EventQueueInterface as Queue;
use Phergie\Irc\Plugin\React\MagicEightBall\Plugin;
use Phergie\Irc\Plugin\React\MagicEightBall\AnswerProvider;
use Phergie\Irc\Plugin\React\MagicEightBall\Plugin;

/**
* Tests for the Plugin class.
Expand All @@ -24,6 +24,7 @@
class PluginTest extends \PHPUnit_Framework_TestCase
{
protected $plugin;
/** @var \PHPUnit_Framework_MockObject_MockObject|AnswerProvider */
protected $provider;

function setUp()
Expand All @@ -34,6 +35,16 @@ function setUp()
$this->plugin = new Plugin($this->provider);
}

/**
* Ensures the default AnswerProvider is created if no provider is sent into the constructor
*/
public function testDefaultProviderIsSetIfNotProvided()
{
$plugin = new Plugin();

$this->assertAttributeInstanceOf('Phergie\Irc\Plugin\React\MagicEightBall\AnswerProvider', 'provider', $plugin);
}

/**
* Tests that getSubscribedEvents() returns an array.
*/
Expand Down

0 comments on commit 318dcb4

Please sign in to comment.