From 11b945046fba36077ae9b5b6554cf4662ca2053f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pluchino?= Date: Mon, 21 Jul 2014 15:07:27 +0200 Subject: [PATCH] Register plugin only one time when it's present in global and project mode --- src/Composer/Plugin/PluginManager.php | 6 ++++++ .../Test/Plugin/PluginInstallerTest.php | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index d7c3ae07a..b6c88c90f 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -37,6 +37,7 @@ class PluginManager protected $versionParser; protected $plugins = array(); + protected $registeredPlugins = array(); private static $classCounter = 0; @@ -191,6 +192,10 @@ class PluginManager { $oldInstallerPlugin = ($package->getType() === 'composer-installer'); + if (in_array($package->getName(), $this->registeredPlugins)) { + return; + } + $extra = $package->getExtra(); if (empty($extra['class'])) { throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.'); @@ -233,6 +238,7 @@ class PluginManager } else { $plugin = new $class(); $this->addPlugin($plugin); + $this->registeredPlugins[] = $package->getName(); } } } diff --git a/tests/Composer/Test/Plugin/PluginInstallerTest.php b/tests/Composer/Test/Plugin/PluginInstallerTest.php index 08d0d1aab..bd9e2b554 100644 --- a/tests/Composer/Test/Plugin/PluginInstallerTest.php +++ b/tests/Composer/Test/Plugin/PluginInstallerTest.php @@ -164,4 +164,21 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase $plugins = $this->pm->getPlugins(); $this->assertEquals('installer-v3', $plugins[1]->version); } + + public function testRegisterPluginOnlyOneTime() + { + $this->repository + ->expects($this->exactly(2)) + ->method('getPackages') + ->will($this->returnValue(array())); + $installer = new PluginInstaller($this->io, $this->composer); + $this->pm->loadInstalledPlugins(); + + $installer->install($this->repository, $this->packages[0]); + $installer->install($this->repository, clone $this->packages[0]); + + $plugins = $this->pm->getPlugins(); + $this->assertCount(1, $plugins); + $this->assertEquals('installer-v1', $plugins[0]->version); + } }