Skip to content

Commit 85361af

Browse files
committed
fix plugin boot
1 parent 927d212 commit 85361af

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed

src/Command/CommandProvider.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace IonBazan\ComposerDiff\Command;
4+
5+
use Composer\Composer;
6+
use Composer\Plugin\Capability\CommandProvider as BaseCommandProvider;
7+
use IonBazan\ComposerDiff\PackageDiff;
8+
9+
class CommandProvider implements BaseCommandProvider
10+
{
11+
/**
12+
* @var Composer
13+
*/
14+
private $composer;
15+
16+
/**
17+
* @param array{composer:Composer} $args
18+
*/
19+
public function __construct(array $args)
20+
{
21+
$this->composer = $args['composer'];
22+
}
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function getCommands()
28+
{
29+
return array(new DiffCommand(new PackageDiff(), $this->composer->getConfig()->get('gitlab-domains')));
30+
}
31+
}

src/Plugin.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
use Composer\Composer;
66
use Composer\IO\IOInterface;
7-
use Composer\Plugin\Capability\CommandProvider;
87
use Composer\Plugin\Capable;
98
use Composer\Plugin\PluginInterface;
10-
use IonBazan\ComposerDiff\Command\DiffCommand;
119

12-
class Plugin implements PluginInterface, Capable, CommandProvider
10+
class Plugin implements PluginInterface, Capable
1311
{
1412
/**
1513
* @var Composer
@@ -24,18 +22,10 @@ public function activate(Composer $composer, IOInterface $io)
2422
$this->composer = $composer;
2523
}
2624

27-
/**
28-
* {@inheritdoc}
29-
*/
30-
public function getCommands()
31-
{
32-
return array(new DiffCommand(new PackageDiff(), $this->composer->getConfig()->get('gitlab-domains')));
33-
}
34-
3525
public function getCapabilities()
3626
{
3727
return array(
38-
'Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Plugin',
28+
'Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Command\CommandProvider',
3929
);
4030
}
4131

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace IonBazan\ComposerDiff\Tests\Command;
4+
5+
use IonBazan\ComposerDiff\Command\CommandProvider;
6+
use IonBazan\ComposerDiff\Command\DiffCommand;
7+
use IonBazan\ComposerDiff\PackageDiff;
8+
use IonBazan\ComposerDiff\Tests\TestCase;
9+
10+
class CommandProviderTest extends TestCase
11+
{
12+
public function testProvider()
13+
{
14+
$composer = $this->getMockBuilder('Composer\Composer')->getMock();
15+
$config = $this->getMockBuilder('Composer\Config')->disableOriginalConstructor()->getMock();
16+
$config->expects($this->once())
17+
->method('get')
18+
->with('gitlab-domains')
19+
->willReturn(array());
20+
$composer->expects($this->once())->method('getConfig')->willReturn($config);
21+
$provider = new CommandProvider(array('composer' => $composer));
22+
$this->assertEquals(array(new DiffCommand(new PackageDiff())), $provider->getCommands());
23+
}
24+
}

tests/PluginTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,22 @@
22

33
namespace IonBazan\ComposerDiff\Tests;
44

5-
use IonBazan\ComposerDiff\Command\DiffCommand;
6-
use IonBazan\ComposerDiff\PackageDiff;
75
use IonBazan\ComposerDiff\Plugin;
86

97
class PluginTest extends TestCase
108
{
119
public function testPlugin()
1210
{
1311
$composer = $this->getMockBuilder('Composer\Composer')->getMock();
14-
$config = $this->getMockBuilder('Composer\Config')->disableOriginalConstructor()->getMock();
15-
$config->method('get')->with('gitlab-domains')->willReturn(array());
16-
$composer->method('getConfig')->willReturn($config);
1712
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
1813

1914
$plugin = new Plugin();
2015
$plugin->activate($composer, $io);
21-
$command = new DiffCommand(new PackageDiff());
2216

2317
$this->assertSame(
24-
array('Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Plugin'),
18+
array('Composer\Plugin\Capability\CommandProvider' => 'IonBazan\ComposerDiff\Command\CommandProvider'),
2519
$plugin->getCapabilities()
2620
);
27-
$this->assertEquals(array($command), $plugin->getCommands());
2821
$plugin->deactivate($composer, $io);
2922
$plugin->uninstall($composer, $io);
3023
}

0 commit comments

Comments
 (0)