mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Adjust the CommandProvider to use plugin capabilities and test actual command creation, refs #3377
This commit is contained in:
parent
4319435154
commit
090295dbcb
8 changed files with 92 additions and 30 deletions
|
@ -1,6 +1,5 @@
|
|||
{
|
||||
"name": "plugin-v5",
|
||||
<<<<<<< HEAD
|
||||
"version": "1.0.0",
|
||||
"type": "composer-plugin",
|
||||
"autoload": { "psr-0": { "Installer": "" } },
|
||||
|
@ -9,17 +8,5 @@
|
|||
},
|
||||
"require": {
|
||||
"composer-plugin-api": "*"
|
||||
=======
|
||||
"version": "5.0.0",
|
||||
"type": "composer-plugin",
|
||||
"autoload": { "psr-0": { "Installer": "" } },
|
||||
"extra": {
|
||||
"class": [
|
||||
"Installer\\Plugin"
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"composer-plugin-api": "1.0.0"
|
||||
>>>>>>> jderusse/plugin-with-commands
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Installer;
|
||||
|
||||
use Composer\Plugin\Capability\CommandProvider;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Composer\Command\BaseCommand;
|
||||
|
||||
class CommandProvider implements CommandProvider
|
||||
{
|
||||
public function __construct(array $args)
|
||||
{
|
||||
}
|
||||
|
||||
public function getCommands()
|
||||
{
|
||||
return array(new Command);
|
||||
}
|
||||
}
|
||||
|
||||
class Command extends BaseCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('custom-plugin-command');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
}
|
|
@ -5,9 +5,9 @@ namespace Installer;
|
|||
use Composer\Composer;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Plugin\PluginInterface;
|
||||
use Composer\Plugin\CommandsProviderInterface;
|
||||
use Composer\Plugin\Capable;
|
||||
|
||||
class Plugin8 implements PluginInterface, CommandsProviderInterface
|
||||
class Plugin8 implements PluginInterface, Capable
|
||||
{
|
||||
public $version = 'installer-v8';
|
||||
|
||||
|
@ -15,8 +15,10 @@ class Plugin8 implements PluginInterface, CommandsProviderInterface
|
|||
{
|
||||
}
|
||||
|
||||
public function getCommands()
|
||||
public function getCapabilities()
|
||||
{
|
||||
return null;
|
||||
return array(
|
||||
'Composer\Plugin\Capability\CommandProvider' => 'Installer\CommandProvider',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
]
|
||||
},
|
||||
"require": {
|
||||
"composer-plugin-api": "1.0.0"
|
||||
"composer-plugin-api": "1.1.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -297,6 +297,24 @@ class PluginInstallerTest extends TestCase
|
|||
$this->assertCount(0, $this->pm->getPlugins());
|
||||
}
|
||||
|
||||
public function testCommandProviderCapability()
|
||||
{
|
||||
$this->repository
|
||||
->expects($this->exactly(2))
|
||||
->method('getPackages')
|
||||
->will($this->returnValue(array($this->packages[7])));
|
||||
$installer = new PluginInstaller($this->io, $this->composer);
|
||||
$this->pm->loadInstalledPlugins();
|
||||
|
||||
$caps = $this->pm->getPluginCapabilities('Composer\Plugin\Capability\CommandProvider');
|
||||
$this->assertCount(1, $caps);
|
||||
$this->assertInstanceOf('Composer\Plugin\Capability\CommandProvider', $caps[0]);
|
||||
|
||||
$commands = $caps[0]->getCommands();
|
||||
$this->assertCount(1, $commands);
|
||||
$this->assertInstanceOf('Composer\Command\BaseCommand', $commands[0]);
|
||||
}
|
||||
|
||||
public function testIncapablePluginIsCorrectlyDetected()
|
||||
{
|
||||
$plugin = $this->getMockBuilder('Composer\Plugin\PluginInterface')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue