diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index b4312c015..a68d3e3b5 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -140,7 +140,7 @@ class ArrayLoader if (isset($config[$type])) { $method = 'set'.ucfirst($description); $package->{$method}( - $this->loadLinksFromConfig($package->getName(), $description, $config[$type]) + $this->loadLinksFromConfig($package, $description, $config[$type]) ); } } @@ -152,12 +152,15 @@ class ArrayLoader return $package; } - private function loadLinksFromConfig($srcPackageName, $description, array $linksSpecs) + private function loadLinksFromConfig($package, $description, array $linksSpecs) { $links = array(); foreach ($linksSpecs as $packageName => $constraint) { + if ('self.version' === $constraint) { + $constraint = $package->getVersion(); + } $constraint = $this->versionParser->parseConstraints($constraint); - $links[] = new Package\Link($srcPackageName, $packageName, $constraint, $description, $constraint); + $links[] = new Package\Link($package->getName(), $packageName, $constraint, $description, $constraint); } return $links; diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 54d3ed1a6..80fb45c3c 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -135,18 +135,30 @@ class VersionParser // match wildcard constraints if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.\*$}', $constraint, $matches)) { if (isset($matches[3])) { - $lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.0'; $highVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.9999999'; + if ($matches[3] === '0') { + $lowVersion = $matches[1] . '.' . ($matches[2] - 1) . '.9999999.9999999'; + } else { + $lowVersion = $matches[1] . '.' . $matches[2] . '.' . ($matches[3] - 1). '.9999999'; + } } elseif (isset($matches[2])) { - $lowVersion = $matches[1] . '.' . $matches[2] . '.0.0'; $highVersion = $matches[1] . '.' . $matches[2] . '.9999999.9999999'; + if ($matches[2] === '0') { + $lowVersion = ($matches[1] - 1) . '.9999999.9999999.9999999'; + } else { + $lowVersion = $matches[1] . '.' . ($matches[2] - 1) . '.9999999.9999999'; + } } else { - $lowVersion = $matches[1] . '.0.0.0'; $highVersion = $matches[1] . '.9999999.9999999.9999999'; + if ($matches[1] === '0') { + return array(new VersionConstraint('<', $highVersion)); + } else { + $lowVersion = ($matches[1] - 1) . '.9999999.9999999.9999999'; + } } return array( - new VersionConstraint('>=', $lowVersion), + new VersionConstraint('>', $lowVersion), new VersionConstraint('<', $highVersion), ); } diff --git a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php new file mode 100644 index 000000000..025cb140a --- /dev/null +++ b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php @@ -0,0 +1,39 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Test\Package\Loader; + +use Composer\Package\Loader\ArrayLoader; + +class ArrayLoaderTest extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->manager = $this->getMock('Composer\Repository\RepositoryManager'); + $this->loader = new ArrayLoader($this->manager); + } + + public function testSelfVersion() + { + $config = array( + 'name' => 'A', + 'version' => '1.2.3.4', + 'replace' => array( + 'foo' => 'self.version', + ), + ); + + $package = $this->loader->load($config); + $replaces = $package->getReplaces(); + $this->assertEquals('== 1.2.3.4', (string) $replaces[0]->getConstraint()); + } +} diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index b3c8e24d2..faca00dc9 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -132,7 +132,11 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase public function testParseConstraintsWildcard($input, $min, $max) { $parser = new VersionParser; - $expected = new MultiConstraint(array($min, $max)); + if ($min) { + $expected = new MultiConstraint(array($min, $max)); + } else { + $expected = $max; + } $this->assertSame((string) $expected, (string) $parser->parseConstraints($input)); } @@ -140,12 +144,13 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase public function wildcardConstraints() { return array( - array('2.*', new VersionConstraint('>=', '2.0.0.0'), new VersionConstraint('<', '2.9999999.9999999.9999999')), - array('20.*', new VersionConstraint('>=', '20.0.0.0'), new VersionConstraint('<', '20.9999999.9999999.9999999')), - array('2.0.*', new VersionConstraint('>=', '2.0.0.0'), new VersionConstraint('<', '2.0.9999999.9999999')), - array('2.2.*', new VersionConstraint('>=', '2.2.0.0'), new VersionConstraint('<', '2.2.9999999.9999999')), - array('2.10.*', new VersionConstraint('>=', '2.10.0.0'), new VersionConstraint('<', '2.10.9999999.9999999')), - array('2.1.3.*', new VersionConstraint('>=', '2.1.3.0'), new VersionConstraint('<', '2.1.3.9999999')), + array('2.*', new VersionConstraint('>', '1.9999999.9999999.9999999'), new VersionConstraint('<', '2.9999999.9999999.9999999')), + array('20.*', new VersionConstraint('>', '19.9999999.9999999.9999999'), new VersionConstraint('<', '20.9999999.9999999.9999999')), + array('2.0.*', new VersionConstraint('>', '1.9999999.9999999.9999999'), new VersionConstraint('<', '2.0.9999999.9999999')), + array('2.2.*', new VersionConstraint('>', '2.1.9999999.9999999'), new VersionConstraint('<', '2.2.9999999.9999999')), + array('2.10.*', new VersionConstraint('>', '2.9.9999999.9999999'), new VersionConstraint('<', '2.10.9999999.9999999')), + array('2.1.3.*', new VersionConstraint('>', '2.1.2.9999999'), new VersionConstraint('<', '2.1.3.9999999')), + array('0.*', null, new VersionConstraint('<', '0.9999999.9999999.9999999')), ); }