-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added testing, refactored a little bit the configuration building ser…
…vices
- Loading branch information
Showing
6 changed files
with
167 additions
and
73 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace Psy\Test\Plugin; | ||
|
||
use Psy\Plugin\Manager; | ||
|
||
class ManagerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function setup() | ||
{ | ||
$prop = new \ReflectionProperty('Psy\Plugin\Manager', 'plugins'); | ||
$prop->setAccessible(true); | ||
$prop->setValue('Psy\Plugin\Manager', array()); | ||
} | ||
|
||
public function testRegisterMultiplePlugins() | ||
{ | ||
$mockedPlugin = $this->getMock('Psy\Plugin\AbstractPlugin'); | ||
Manager::register($mockedPlugin, 'mock1'); | ||
Manager::register($mockedPlugin, 'mock2'); | ||
|
||
$prop = new \ReflectionProperty('Psy\Plugin\Manager', 'plugins'); | ||
$prop->setAccessible(true); | ||
$plugins = $prop->getValue('Psy\Plugin\Manager'); | ||
$this->assertArrayHasKey('mock1', $plugins); | ||
$this->assertArrayHasKey('mock2', $plugins); | ||
} | ||
|
||
public function testConfigurationWithSinglePlugin() | ||
{ | ||
$commands = array( | ||
'cmd1', 'cmd2', | ||
); | ||
|
||
$presenters = array( | ||
'presenter1', 'presenter2', | ||
); | ||
|
||
$matchers = array( | ||
'matcher1', 'matcher2', | ||
); | ||
|
||
$stub = new PluginStub(); | ||
$stub->setCommands($commands); | ||
$stub->setPresenters($presenters); | ||
$stub->setMatchers($matchers); | ||
|
||
Manager::register($stub, 'mock'); | ||
|
||
$config = Manager::getConfiguration(); | ||
$this->assertArraySubset($commands, $config['commands']); | ||
$this->assertArraySubset($presenters, $config['presenters']); | ||
$this->assertArraySubset($matchers, $config['matchers']); | ||
} | ||
|
||
public function testConfigurationWithMultiplePlugins() | ||
{ | ||
$commands1 = array( | ||
'cmd1', 'cmd2', | ||
); | ||
|
||
$presenters1 = array( | ||
'presenter1', 'presenter2', | ||
); | ||
|
||
$matchers1 = array( | ||
'matcher1', 'matcher2', | ||
); | ||
|
||
$stub1 = new PluginStub(); | ||
$stub1->setCommands($commands1); | ||
$stub1->setPresenters($presenters1); | ||
$stub1->setMatchers($matchers1); | ||
|
||
Manager::register($stub1, 'mock1'); | ||
|
||
$commands2 = array( | ||
'cmd3', 'cmd4', | ||
); | ||
|
||
$presenters2 = array( | ||
'presenter3', 'presenter4', | ||
); | ||
|
||
$matchers2 = array( | ||
'matcher3', 'matcher4', | ||
); | ||
|
||
$stub2 = new PluginStub(); | ||
$stub2->setCommands($commands2); | ||
$stub2->setPresenters($presenters2); | ||
$stub2->setMatchers($matchers2); | ||
|
||
Manager::register($stub2, 'mock2'); | ||
|
||
$config = Manager::getConfiguration(); | ||
$this->assertArraySubset($commands1, $config['commands']); | ||
$this->assertArraySubset($presenters1, $config['presenters']); | ||
$this->assertArraySubset($matchers1, $config['matchers']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Psy\Test\Plugin; | ||
|
||
use Psy\Plugin\AbstractPlugin; | ||
|
||
class PluginStub extends AbstractPlugin | ||
{ | ||
// due to the static nature, and the negative of Mr bergmann to audit static code | ||
// the data here is treated as a FIFO pile. | ||
protected static $matchers = array(); | ||
protected static $presenters = array(); | ||
protected static $commands = array(); | ||
|
||
public function setMatchers(array $matchers) | ||
{ | ||
self::$matchers[] = $matchers; | ||
} | ||
|
||
public function setPresenters(array $presenters) | ||
{ | ||
self::$presenters[] = $presenters; | ||
} | ||
|
||
public function setCommands(array $commands) | ||
{ | ||
self::$commands[] = $commands; | ||
} | ||
|
||
public static function getMatchers() | ||
{ | ||
return array_shift(self::$matchers); | ||
} | ||
|
||
public static function getPresenters() | ||
{ | ||
return array_shift(self::$presenters); | ||
} | ||
|
||
public static function getCommands() | ||
{ | ||
return array_shift(self::$commands); | ||
} | ||
} |