diff --git a/src/Command/CommandProvider.php b/src/Command/CommandProvider.php new file mode 100644 index 0000000..ca622e3 --- /dev/null +++ b/src/Command/CommandProvider.php @@ -0,0 +1,31 @@ +composer = $args['composer']; + } + + /** + * {@inheritdoc} + */ + public function getCommands() + { + return array(new DiffCommand(new PackageDiff(), $this->composer->getConfig()->get('gitlab-domains'))); + } +} diff --git a/src/Plugin.php b/src/Plugin.php index 63f4059..841ea6a 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -4,12 +4,10 @@ use Composer\Composer; use Composer\IO\IOInterface; -use Composer\Plugin\Capability\CommandProvider; use Composer\Plugin\Capable; use Composer\Plugin\PluginInterface; -use IonBazan\ComposerDiff\Command\DiffCommand; -class Plugin implements PluginInterface, Capable, CommandProvider +class Plugin implements PluginInterface, Capable { /** * @var Composer @@ -24,18 +22,10 @@ public function activate(Composer $composer, IOInterface $io) $this->composer = $composer; } - /** - * {@inheritdoc} - */ - public function getCommands() - { - return array(new DiffCommand(new PackageDiff(), $this->composer->getConfig()->get('gitlab-domains'))); - } - public function getCapabilities() { return array( - 'Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Plugin', + 'Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Command\CommandProvider', ); } diff --git a/tests/Command/CommandProviderTest.php b/tests/Command/CommandProviderTest.php new file mode 100644 index 0000000..db586dc --- /dev/null +++ b/tests/Command/CommandProviderTest.php @@ -0,0 +1,24 @@ +getMockBuilder('Composer\Composer')->getMock(); + $config = $this->getMockBuilder('Composer\Config')->disableOriginalConstructor()->getMock(); + $config->expects($this->once()) + ->method('get') + ->with('gitlab-domains') + ->willReturn(array()); + $composer->expects($this->once())->method('getConfig')->willReturn($config); + $provider = new CommandProvider(array('composer' => $composer)); + $this->assertEquals(array(new DiffCommand(new PackageDiff())), $provider->getCommands()); + } +} diff --git a/tests/PluginTest.php b/tests/PluginTest.php index 9cdbfc6..4e49f7f 100644 --- a/tests/PluginTest.php +++ b/tests/PluginTest.php @@ -2,8 +2,6 @@ namespace IonBazan\ComposerDiff\Tests; -use IonBazan\ComposerDiff\Command\DiffCommand; -use IonBazan\ComposerDiff\PackageDiff; use IonBazan\ComposerDiff\Plugin; class PluginTest extends TestCase @@ -11,20 +9,15 @@ class PluginTest extends TestCase public function testPlugin() { $composer = $this->getMockBuilder('Composer\Composer')->getMock(); - $config = $this->getMockBuilder('Composer\Config')->disableOriginalConstructor()->getMock(); - $config->method('get')->with('gitlab-domains')->willReturn(array()); - $composer->method('getConfig')->willReturn($config); $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $plugin = new Plugin(); $plugin->activate($composer, $io); - $command = new DiffCommand(new PackageDiff()); $this->assertSame( - array('Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Plugin'), + array('Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Command\CommandProvider'), $plugin->getCapabilities() ); - $this->assertEquals(array($command), $plugin->getCommands()); $plugin->deactivate($composer, $io); $plugin->uninstall($composer, $io); }