mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Make plugins have actual constraints instead of fixed versions
Instead of developing plugins against a single, fixed Plugin API version - `"composer-plugin-api": "1.0.0"`, this change will allow plugin developers to use versions like `"composer-plugin-api": "~1.1"` or `"composer-plugin-api": ">=2.1 <3.0"`, aka actual Composer-compatible constraints. Only the "1.0", "1.0.0" and "1.0.0" Plugin API versions will be regarded as BC versions, and internally converted to "^1.0"; every other declared version string will be kept as it is. Because of this new constraint flexibility, plugin version mismatches will be skipped, which means those plugin will NOT be registered to the system. Previously, a mismatch triggered a warning, but plugins were still registered.
This commit is contained in:
parent
d4dbeeacc4
commit
eb2aa14830
13 changed files with 350 additions and 11 deletions
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace Composer\Test\Package\Version;
|
||||
|
||||
use Composer\Package\Link;
|
||||
use Composer\Package\Version\VersionParser;
|
||||
use Composer\Package\LinkConstraint\MultiConstraint;
|
||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||
|
@ -513,4 +514,70 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
|||
array('RC', '2.0.0rc1')
|
||||
);
|
||||
}
|
||||
|
||||
public function oldStylePluginApiVersions()
|
||||
{
|
||||
return array(
|
||||
array('1.0'),
|
||||
array('1.0.0'),
|
||||
array('1.0.0.0'),
|
||||
);
|
||||
}
|
||||
|
||||
public function newStylePluginApiVersions()
|
||||
{
|
||||
return array(
|
||||
array('1'),
|
||||
array('=1.0.0'),
|
||||
array('==1.0'),
|
||||
array('~1.0.0'),
|
||||
array('*'),
|
||||
array('3.0.*'),
|
||||
array('@stable'),
|
||||
array('1.0.0@stable'),
|
||||
array('^5.1'),
|
||||
array('>=1.0.0 <2.5'),
|
||||
array('x'),
|
||||
array('1.0.0-dev'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider oldStylePluginApiVersions
|
||||
*/
|
||||
public function testOldStylePluginApiVersionGetsConvertedIntoAnotherConstraintToKeepBc($apiVersion)
|
||||
{
|
||||
$parser = new VersionParser;
|
||||
|
||||
/** @var Link[] $links */
|
||||
$links = $parser->parseLinks('Plugin', '9.9.9', '', array('composer-plugin-api' => $apiVersion));
|
||||
|
||||
$this->assertArrayHasKey('composer-plugin-api', $links);
|
||||
$this->assertSame('^1.0', $links['composer-plugin-api']->getConstraint()->getPrettyString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider newStylePluginApiVersions
|
||||
*/
|
||||
public function testNewStylePluginApiVersionAreKeptAsDeclared($apiVersion)
|
||||
{
|
||||
$parser = new VersionParser;
|
||||
|
||||
/** @var Link[] $links */
|
||||
$links = $parser->parseLinks('Plugin', '9.9.9', '', array('composer-plugin-api' => $apiVersion));
|
||||
|
||||
$this->assertArrayHasKey('composer-plugin-api', $links);
|
||||
$this->assertSame($apiVersion, $links['composer-plugin-api']->getConstraint()->getPrettyString());
|
||||
}
|
||||
|
||||
public function testPluginApiVersionDoesSupportSelfVersion()
|
||||
{
|
||||
$parser = new VersionParser;
|
||||
|
||||
/** @var Link[] $links */
|
||||
$links = $parser->parseLinks('Plugin', '6.6.6', '', array('composer-plugin-api' => 'self.version'));
|
||||
|
||||
$this->assertArrayHasKey('composer-plugin-api', $links);
|
||||
$this->assertSame('6.6.6', $links['composer-plugin-api']->getConstraint()->getPrettyString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue