Refactor based on code review
- Move the version api getter to the PluginManager And make it such that it can be mocked, but not pollute the public interface. That means "protected" visibility. - The plugin api version constant should still be used throughout the code. - Use different fixtures class names - Use regex possessive quantifiers for performance - Use full words for readabilitypull/4089/head
parent
eb2aa14830
commit
3032f0a538
|
@ -341,14 +341,4 @@ class Config
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the version of the internal composer-plugin-api package.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPluginApiVersion()
|
|
||||||
{
|
|
||||||
return PluginInterface::PLUGIN_API_VERSION;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,7 +246,7 @@ class VersionParser
|
||||||
private function isOldStylePluginApiVersion($requiredPluginApiVersion)
|
private function isOldStylePluginApiVersion($requiredPluginApiVersion)
|
||||||
{
|
{
|
||||||
// catch "1.0", "1.0.0", "1.0.0.0" etc.
|
// catch "1.0", "1.0.0", "1.0.0.0" etc.
|
||||||
return (bool) preg_match('#^1(\.0)+$#', trim($requiredPluginApiVersion));
|
return (bool) preg_match('#^1(\.0)++$#', trim($requiredPluginApiVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,6 @@ interface PluginInterface
|
||||||
* Version number of the fake composer-plugin-api package
|
* Version number of the fake composer-plugin-api package
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* @deprecated Use \Composer\Config::getPluginApiVersion() instead.
|
|
||||||
*/
|
*/
|
||||||
const PLUGIN_API_VERSION = '1.0.0';
|
const PLUGIN_API_VERSION = '1.0.0';
|
||||||
|
|
||||||
|
|
|
@ -130,10 +130,11 @@ class PluginManager
|
||||||
throw new \RuntimeException("Plugin ".$package->getName()." is missing a require statement for a version of the composer-plugin-api package.");
|
throw new \RuntimeException("Plugin ".$package->getName()." is missing a require statement for a version of the composer-plugin-api package.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$currPluginApiVersion = $this->composer->getConfig()->getPluginApiVersion();
|
$currentPluginApiVersion = $this->getPluginApiVersion();
|
||||||
$currPluginApiConstraint = new VersionConstraint('==', $this->versionParser->normalize($currPluginApiVersion));
|
$currentPluginApiConstraint = new VersionConstraint('==', $this->versionParser->normalize($currentPluginApiVersion));
|
||||||
if (!$requiresComposer->matches($currPluginApiConstraint)) {
|
|
||||||
$this->io->writeError('<warning>The "' . $package->getName() . '" plugin was skipped because it requires a Plugin API version ("' . $requiresComposer->getPrettyString() . '") that does not match your Composer installation ("' . $currPluginApiVersion . '"). You may need to run composer update with the "--no-plugins" option.</warning>');
|
if (!$requiresComposer->matches($currentPluginApiConstraint)) {
|
||||||
|
$this->io->writeError('<warning>The "' . $package->getName() . '" plugin was skipped because it requires a Plugin API version ("' . $requiresComposer->getPrettyString() . '") that does not match your Composer installation ("' . $currentPluginApiVersion . '"). You may need to run composer update with the "--no-plugins" option.</warning>');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,4 +277,14 @@ class PluginManager
|
||||||
|
|
||||||
return $this->globalComposer->getInstallationManager()->getInstallPath($package);
|
return $this->globalComposer->getInstallationManager()->getInstallPath($package);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the version of the internal composer-plugin-api package.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getPluginApiVersion()
|
||||||
|
{
|
||||||
|
return PluginInterface::PLUGIN_API_VERSION;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,6 @@ class PlatformRepository extends ArrayRepository
|
||||||
*/
|
*/
|
||||||
private $overrides;
|
private $overrides;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Config
|
|
||||||
*/
|
|
||||||
private $config;
|
|
||||||
|
|
||||||
public function __construct(array $packages = array(), array $overrides = array())
|
public function __construct(array $packages = array(), array $overrides = array())
|
||||||
{
|
{
|
||||||
parent::__construct($packages);
|
parent::__construct($packages);
|
||||||
|
@ -68,7 +63,7 @@ class PlatformRepository extends ArrayRepository
|
||||||
parent::addPackage($package);
|
parent::addPackage($package);
|
||||||
}
|
}
|
||||||
|
|
||||||
$prettyVersion = $this->getConfig()->getPluginApiVersion();
|
$prettyVersion = PluginInterface::PLUGIN_API_VERSION;
|
||||||
$version = $versionParser->normalize($prettyVersion);
|
$version = $versionParser->normalize($prettyVersion);
|
||||||
$composerPluginApi = new CompletePackage('composer-plugin-api', $version, $prettyVersion);
|
$composerPluginApi = new CompletePackage('composer-plugin-api', $version, $prettyVersion);
|
||||||
$composerPluginApi->setDescription('The Composer Plugin API');
|
$composerPluginApi->setDescription('The Composer Plugin API');
|
||||||
|
@ -216,23 +211,4 @@ class PlatformRepository extends ArrayRepository
|
||||||
{
|
{
|
||||||
return 'ext-' . str_replace(' ', '-', $name);
|
return 'ext-' . str_replace(' ', '-', $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Config $config
|
|
||||||
*/
|
|
||||||
public function setConfig(Config $config)
|
|
||||||
{
|
|
||||||
$this->config = $config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Config
|
|
||||||
*/
|
|
||||||
public function getConfig()
|
|
||||||
{
|
|
||||||
if (!$this->config) {
|
|
||||||
$this->config = new Config;
|
|
||||||
}
|
|
||||||
return $this->config;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use Composer\Composer;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Plugin\PluginInterface;
|
use Composer\Plugin\PluginInterface;
|
||||||
|
|
||||||
class Plugin implements PluginInterface
|
class Plugin5 implements PluginInterface
|
||||||
{
|
{
|
||||||
public function activate(Composer $composer, IOInterface $io)
|
public function activate(Composer $composer, IOInterface $io)
|
||||||
{
|
{
|
|
@ -4,7 +4,7 @@
|
||||||
"type": "composer-plugin",
|
"type": "composer-plugin",
|
||||||
"autoload": { "psr-0": { "Installer": "" } },
|
"autoload": { "psr-0": { "Installer": "" } },
|
||||||
"extra": {
|
"extra": {
|
||||||
"class": "Installer\\Plugin"
|
"class": "Installer\\Plugin5"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"composer-plugin-api": "*"
|
"composer-plugin-api": "*"
|
||||||
|
|
|
@ -6,7 +6,7 @@ use Composer\Composer;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Plugin\PluginInterface;
|
use Composer\Plugin\PluginInterface;
|
||||||
|
|
||||||
class Plugin implements PluginInterface
|
class Plugin6 implements PluginInterface
|
||||||
{
|
{
|
||||||
public function activate(Composer $composer, IOInterface $io)
|
public function activate(Composer $composer, IOInterface $io)
|
||||||
{
|
{
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "plugin-v5",
|
"name": "plugin-v6",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"type": "composer-plugin",
|
"type": "composer-plugin",
|
||||||
"autoload": { "psr-0": { "Installer": "" } },
|
"autoload": { "psr-0": { "Installer": "" } },
|
||||||
"extra": {
|
"extra": {
|
||||||
"class": "Installer\\Plugin"
|
"class": "Installer\\Plugin6"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"composer-plugin-api": "~1.2"
|
"composer-plugin-api": "~1.2"
|
||||||
|
|
|
@ -6,7 +6,7 @@ use Composer\Composer;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Plugin\PluginInterface;
|
use Composer\Plugin\PluginInterface;
|
||||||
|
|
||||||
class Plugin implements PluginInterface
|
class Plugin7 implements PluginInterface
|
||||||
{
|
{
|
||||||
public function activate(Composer $composer, IOInterface $io)
|
public function activate(Composer $composer, IOInterface $io)
|
||||||
{
|
{
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "plugin-v5",
|
"name": "plugin-v7",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"type": "composer-plugin",
|
"type": "composer-plugin",
|
||||||
"autoload": { "psr-0": { "Installer": "" } },
|
"autoload": { "psr-0": { "Installer": "" } },
|
||||||
"extra": {
|
"extra": {
|
||||||
"class": "Installer\\Plugin"
|
"class": "Installer\\Plugin7"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"composer-plugin-api": ">=3.0.0 <5.5"
|
"composer-plugin-api": ">=3.0.0 <5.5"
|
||||||
|
|
|
@ -222,19 +222,15 @@ class PluginInstallerTest extends TestCase
|
||||||
private function setPluginApiVersionWithPlugins($newPluginApiVersion, array $plugins = array())
|
private function setPluginApiVersionWithPlugins($newPluginApiVersion, array $plugins = array())
|
||||||
{
|
{
|
||||||
// reset the plugin manager's installed plugins
|
// reset the plugin manager's installed plugins
|
||||||
$this->pm = new PluginManager($this->io, $this->composer);
|
$this->pm = $this->getMockBuilder('Composer\Plugin\PluginManager')
|
||||||
|
->setMethods(array('getPluginApiVersion'))
|
||||||
|
->setConstructorArgs(array($this->io, $this->composer))
|
||||||
|
->getMock();
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject $config */
|
// mock the Plugin API version
|
||||||
$config = $this->getMock('Composer\Config', array('getPluginApiVersion'));
|
$this->pm->expects($this->any())
|
||||||
|
->method('getPluginApiVersion')
|
||||||
// mock Config to return whatever Plugin API version we wish
|
->will($this->returnValue($newPluginApiVersion));
|
||||||
$config->expects($this->any())
|
|
||||||
->method('getPluginApiVersion')
|
|
||||||
->will($this->returnValue($newPluginApiVersion));
|
|
||||||
|
|
||||||
// transfer the defaults in our Config mock and set it
|
|
||||||
$config->merge($this->composer->getConfig()->raw());
|
|
||||||
$this->composer->setConfig($config);
|
|
||||||
|
|
||||||
$plugApiInternalPackage = $this->getPackage(
|
$plugApiInternalPackage = $this->getPackage(
|
||||||
'composer-plugin-api',
|
'composer-plugin-api',
|
||||||
|
|
Loading…
Reference in New Issue