From e340022cce29f99c2abbc0ffdd31619bd17be343 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 23 Nov 2011 16:47:23 +0100 Subject: [PATCH] Allow the use of self.version in package links --- src/Composer/Package/Loader/ArrayLoader.php | 9 +++-- .../Test/Package/Loader/ArrayLoaderTest.php | 39 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/Composer/Test/Package/Loader/ArrayLoaderTest.php 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/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()); + } +}