From b9c575867061d5afdbd62cb16478673f617eeadd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 15 Aug 2013 16:58:48 +0200 Subject: [PATCH] Make composer/io part of the activate plugin API rather than constructor args --- src/Composer/Plugin/PluginInterface.php | 6 +++++- src/Composer/Plugin/PluginManager.php | 6 +++--- .../Test/Plugin/Fixtures/plugin-v1/Installer/Plugin.php | 3 ++- .../Test/Plugin/Fixtures/plugin-v2/Installer/Plugin2.php | 3 ++- .../Test/Plugin/Fixtures/plugin-v3/Installer/Plugin2.php | 3 ++- .../Test/Plugin/Fixtures/plugin-v4/Installer/Plugin1.php | 3 ++- .../Test/Plugin/Fixtures/plugin-v4/Installer/Plugin2.php | 3 ++- tests/Composer/Test/Plugin/PluginInstallerTest.php | 8 ++++---- 8 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Composer/Plugin/PluginInterface.php b/src/Composer/Plugin/PluginInterface.php index 2c38d0f8d..302175a25 100644 --- a/src/Composer/Plugin/PluginInterface.php +++ b/src/Composer/Plugin/PluginInterface.php @@ -13,6 +13,7 @@ namespace Composer\Plugin; use Composer\Composer; +use Composer\IO\IOInterface; /** * Plugin interface @@ -23,6 +24,9 @@ interface PluginInterface { /** * Apply plugin modifications to composer + * + * @param Composer $composer + * @param IOInterface $io */ - public function activate(); + public function activate(Composer $composer, IOInterface $io); } diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index f13c9787d..a6956c24e 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -66,7 +66,7 @@ class PluginManager public function addPlugin(PluginInterface $plugin) { $this->plugins[] = $plugin; - $plugin->activate(); + $plugin->activate($this->composer, $this->io); if ($plugin instanceof EventSubscriberInterface) { $this->composer->getEventDispatcher()->addSubscriber($plugin); @@ -139,11 +139,11 @@ class PluginManager self::$classCounter++; } - $plugin = new $class($this->composer, $this->io); - if ($oldInstallerPlugin) { + $installer = new $class($this->composer, $this->io); $this->composer->getInstallationManager()->addInstaller($installer); } else { + $plugin = new $class(); $this->addPlugin($plugin); } } diff --git a/tests/Composer/Test/Plugin/Fixtures/plugin-v1/Installer/Plugin.php b/tests/Composer/Test/Plugin/Fixtures/plugin-v1/Installer/Plugin.php index 76c6cef09..f80acd325 100644 --- a/tests/Composer/Test/Plugin/Fixtures/plugin-v1/Installer/Plugin.php +++ b/tests/Composer/Test/Plugin/Fixtures/plugin-v1/Installer/Plugin.php @@ -3,13 +3,14 @@ namespace Installer; use Composer\Composer; +use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; class Plugin implements PluginInterface { public $version = 'installer-v1'; - public function activate() + public function activate(Composer $composer, IOInterface $io) { } } diff --git a/tests/Composer/Test/Plugin/Fixtures/plugin-v2/Installer/Plugin2.php b/tests/Composer/Test/Plugin/Fixtures/plugin-v2/Installer/Plugin2.php index 72e44a1b5..db5a4462e 100644 --- a/tests/Composer/Test/Plugin/Fixtures/plugin-v2/Installer/Plugin2.php +++ b/tests/Composer/Test/Plugin/Fixtures/plugin-v2/Installer/Plugin2.php @@ -3,13 +3,14 @@ namespace Installer; use Composer\Composer; +use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; class Plugin2 implements PluginInterface { public $version = 'installer-v2'; - public function activate() + public function activate(Composer $composer, IOInterface $io) { } } diff --git a/tests/Composer/Test/Plugin/Fixtures/plugin-v3/Installer/Plugin2.php b/tests/Composer/Test/Plugin/Fixtures/plugin-v3/Installer/Plugin2.php index e7130a1a6..861c1679b 100644 --- a/tests/Composer/Test/Plugin/Fixtures/plugin-v3/Installer/Plugin2.php +++ b/tests/Composer/Test/Plugin/Fixtures/plugin-v3/Installer/Plugin2.php @@ -3,13 +3,14 @@ namespace Installer; use Composer\Composer; +use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; class Plugin2 implements PluginInterface { public $version = 'installer-v3'; - public function activate() + public function activate(Composer $composer, IOInterface $io) { } } diff --git a/tests/Composer/Test/Plugin/Fixtures/plugin-v4/Installer/Plugin1.php b/tests/Composer/Test/Plugin/Fixtures/plugin-v4/Installer/Plugin1.php index 826e5d52f..93bcabc98 100644 --- a/tests/Composer/Test/Plugin/Fixtures/plugin-v4/Installer/Plugin1.php +++ b/tests/Composer/Test/Plugin/Fixtures/plugin-v4/Installer/Plugin1.php @@ -3,6 +3,7 @@ namespace Installer; use Composer\Composer; +use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; class Plugin1 implements PluginInterface @@ -10,7 +11,7 @@ class Plugin1 implements PluginInterface public $name = 'plugin1'; public $version = 'installer-v4'; - public function activate() + public function activate(Composer $composer, IOInterface $io) { } } diff --git a/tests/Composer/Test/Plugin/Fixtures/plugin-v4/Installer/Plugin2.php b/tests/Composer/Test/Plugin/Fixtures/plugin-v4/Installer/Plugin2.php index 5716e3fae..d946deb89 100644 --- a/tests/Composer/Test/Plugin/Fixtures/plugin-v4/Installer/Plugin2.php +++ b/tests/Composer/Test/Plugin/Fixtures/plugin-v4/Installer/Plugin2.php @@ -3,6 +3,7 @@ namespace Installer; use Composer\Composer; +use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; class Plugin2 implements PluginInterface @@ -10,7 +11,7 @@ class Plugin2 implements PluginInterface public $name = 'plugin2'; public $version = 'installer-v4'; - public function activate() + public function activate(Composer $composer, IOInterface $io) { } } diff --git a/tests/Composer/Test/Plugin/PluginInstallerTest.php b/tests/Composer/Test/Plugin/PluginInstallerTest.php index 8734993ea..5d21f59db 100644 --- a/tests/Composer/Test/Plugin/PluginInstallerTest.php +++ b/tests/Composer/Test/Plugin/PluginInstallerTest.php @@ -77,7 +77,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase public function testInstallNewPlugin() { $this->repository - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getPackages') ->will($this->returnValue(array())); $installer = new PluginInstaller($this->io, $this->composer); @@ -92,7 +92,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase public function testInstallMultiplePlugins() { $this->repository - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getPackages') ->will($this->returnValue(array())); $installer = new PluginInstaller($this->io, $this->composer); @@ -110,7 +110,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase public function testUpgradeWithNewClassName() { $this->repository - ->expects($this->once()) + ->expects($this->exactly(3)) ->method('getPackages') ->will($this->returnValue(array($this->packages[0]))); $this->repository @@ -129,7 +129,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase public function testUpgradeWithSameClassName() { $this->repository - ->expects($this->once()) + ->expects($this->exactly(3)) ->method('getPackages') ->will($this->returnValue(array($this->packages[1]))); $this->repository