Skip to content

Commit

Permalink
fix plugin boot
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed Jul 1, 2020
1 parent 927d212 commit 85361af
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
31 changes: 31 additions & 0 deletions src/Command/CommandProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace IonBazan\ComposerDiff\Command;

use Composer\Composer;
use Composer\Plugin\Capability\CommandProvider as BaseCommandProvider;
use IonBazan\ComposerDiff\PackageDiff;

class CommandProvider implements BaseCommandProvider
{
/**
* @var Composer
*/
private $composer;

/**
* @param array{composer:Composer} $args
*/
public function __construct(array $args)
{
$this->composer = $args['composer'];
}

/**
* {@inheritdoc}
*/
public function getCommands()
{
return array(new DiffCommand(new PackageDiff(), $this->composer->getConfig()->get('gitlab-domains')));
}
}
14 changes: 2 additions & 12 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
);
}

Expand Down
24 changes: 24 additions & 0 deletions tests/Command/CommandProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace IonBazan\ComposerDiff\Tests\Command;

use IonBazan\ComposerDiff\Command\CommandProvider;
use IonBazan\ComposerDiff\Command\DiffCommand;
use IonBazan\ComposerDiff\PackageDiff;
use IonBazan\ComposerDiff\Tests\TestCase;

class CommandProviderTest extends TestCase
{
public function testProvider()
{
$composer = $this->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());
}
}
9 changes: 1 addition & 8 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@

namespace IonBazan\ComposerDiff\Tests;

use IonBazan\ComposerDiff\Command\DiffCommand;
use IonBazan\ComposerDiff\PackageDiff;
use IonBazan\ComposerDiff\Plugin;

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);
}
Expand Down

0 comments on commit 85361af

Please sign in to comment.