From 3b8ee5dd54556a32723f57ba4572c7e8afee100f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 20 Nov 2011 15:42:12 +0100 Subject: [PATCH 1/2] Use pretty name/version in lock file and debug:packages, fixes #98 --- src/Composer/Command/DebugPackagesCommand.php | 4 ++-- src/Composer/Package/Dumper/ArrayDumper.php | 2 +- src/Composer/Package/Locker.php | 4 ++-- src/Composer/Repository/ArrayRepository.php | 6 ++++++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/DebugPackagesCommand.php b/src/Composer/Command/DebugPackagesCommand.php index a953baed6..e609592a9 100644 --- a/src/Composer/Command/DebugPackagesCommand.php +++ b/src/Composer/Command/DebugPackagesCommand.php @@ -50,12 +50,12 @@ EOT $installedRepo = new PlatformRepository($localRepo); foreach ($installedRepo->getPackages() as $package) { - $output->writeln('installed: '.$package->getName().' '.$package->getVersion()); + $output->writeln('installed: '.$package->getPrettyName().' '.$package->getPrettyVersion().' ('.$package->getName().' '.$package->getVersion().')'); } foreach ($composer->getRepositoryManager()->getRepositories() as $repository) { foreach ($repository->getPackages() as $package) { - $output->writeln('available: '.$package->getName().' '.$package->getVersion()); + $output->writeln('available: '.$package->getPrettyName().' '.$package->getPrettyVersion().' ('.$package->getName().' '.$package->getVersion().')'); } } } diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index d82b60f24..480864b68 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -27,7 +27,6 @@ class ArrayDumper 'names', 'extra', 'installationSource' => 'installation-source', - 'version', 'license', 'requires', 'conflicts', @@ -41,6 +40,7 @@ class ArrayDumper $data = array(); $data['name'] = $package->getPrettyName(); + $data['version'] = $package->getPrettyVersion(); if ($package->getTargetDir()) { $data['target-dir'] = $package->getTargetDir(); } diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 9f99f3997..cf067487c 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -89,8 +89,8 @@ class Locker { $hash = array(); foreach ($packages as $package) { - $name = $package->getName(); - $version = $package->getVersion(); + $name = $package->getPrettyName(); + $version = $package->getPrettyVersion(); if (!$name || !$version) { throw new \LogicException(sprintf( diff --git a/src/Composer/Repository/ArrayRepository.php b/src/Composer/Repository/ArrayRepository.php index e76e718fc..cf6e3c1ac 100644 --- a/src/Composer/Repository/ArrayRepository.php +++ b/src/Composer/Repository/ArrayRepository.php @@ -13,6 +13,7 @@ namespace Composer\Repository; use Composer\Package\PackageInterface; +use Composer\Package\Version\VersionParser; /** * A repository implementation that simply stores packages in an array @@ -29,6 +30,11 @@ class ArrayRepository implements RepositoryInterface */ public function findPackage($name, $version) { + // normalize version & name + $versionParser = new VersionParser(); + $version = $versionParser->normalize($version); + $name = strtolower($name); + foreach ($this->getPackages() as $package) { if ($name === $package->getName() && $version === $package->getVersion()) { return $package; From b125926ad3e0781297879ff627cefcd9636f9805 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 20 Nov 2011 15:46:15 +0100 Subject: [PATCH 2/2] Fix tests --- tests/Composer/Test/Package/LockerTest.php | 10 +++++----- .../Test/Repository/FilesystemRepositoryTest.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Composer/Test/Package/LockerTest.php b/tests/Composer/Test/Package/LockerTest.php index 6ff2f6da0..1993e8cd5 100644 --- a/tests/Composer/Test/Package/LockerTest.php +++ b/tests/Composer/Test/Package/LockerTest.php @@ -122,20 +122,20 @@ class LockerTest extends \PHPUnit_Framework_TestCase $package1 ->expects($this->once()) - ->method('getName') + ->method('getPrettyName') ->will($this->returnValue('pkg1')); $package1 ->expects($this->once()) - ->method('getVersion') + ->method('getPrettyVersion') ->will($this->returnValue('1.0.0-beta')); $package2 ->expects($this->once()) - ->method('getName') + ->method('getPrettyName') ->will($this->returnValue('pkg2')); $package2 ->expects($this->once()) - ->method('getVersion') + ->method('getPrettyVersion') ->will($this->returnValue('0.1.10')); $json @@ -159,7 +159,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase $package1 = $this->createPackageMock(); $package1 ->expects($this->once()) - ->method('getName') + ->method('getPrettyName') ->will($this->returnValue('pkg1')); $this->setExpectedException('LogicException'); diff --git a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php index de69d34d5..372300472 100644 --- a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php +++ b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php @@ -99,7 +99,7 @@ class FilesystemRepositoryTest extends TestCase ->expects($this->once()) ->method('write') ->with(array( - array('name' => 'mypkg', 'type' => 'library', 'names' => array('mypkg'), 'version' => '0.1.10.0') + array('name' => 'mypkg', 'type' => 'library', 'names' => array('mypkg'), 'version' => '0.1.10') )); $repository->addPackage($this->getPackage('mypkg', '0.1.10'));