From 0932f65a1712c10b11a9e9bd3c87947660f68077 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 4 Sep 2012 16:27:22 +0200 Subject: [PATCH] Return 7 chars and not 6 for short git hashes, formatting fixes --- .../Package/Version/VersionParser.php | 2 +- .../Package/Version/VersionParserTest.php | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 1112856a1..9ace8c261 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -76,7 +76,7 @@ class VersionParser // if source reference is a sha1 hash -- truncate if ($truncate && strlen($package->getSourceReference()) === 40) { - return $package->getPrettyVersion() . ' ' . substr($package->getSourceReference(), 0, 6); + return $package->getPrettyVersion() . ' ' . substr($package->getSourceReference(), 0, 7); } return $package->getPrettyVersion() . ' ' . $package->getSourceReference(); diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index 40ed12fd8..f33e02f83 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -21,9 +21,6 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider formattedVersions - * - * @param \Composer\Package\PackageInterface $package - * @param string $expected */ public function testFormatVersionForDevPackage(PackageInterface $package, $truncate, $expected) { @@ -33,10 +30,26 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase public function formattedVersions() { $data = array( - array('sourceReference' => 'v2.1.0-RC2', 'truncate' => true, 'expected' => 'PrettyVersion v2.1.0-RC2'), - array('sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77', 'truncate' => true, 'expected' => 'PrettyVersion bbf527'), - array('sourceReference' => 'v1.0.0', 'truncate' => false, 'expected' => 'PrettyVersion v1.0.0'), - array('sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77', 'truncate' => false, 'expected' => 'PrettyVersion bbf527a27356414bfa9bf520f018c5cb7af67c77'), + array( + 'sourceReference' => 'v2.1.0-RC2', + 'truncate' => true, + 'expected' => 'PrettyVersion v2.1.0-RC2' + ), + array( + 'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77', + 'truncate' => true, + 'expected' => 'PrettyVersion bbf527a' + ), + array( + 'sourceReference' => 'v1.0.0', + 'truncate' => false, + 'expected' => 'PrettyVersion v1.0.0' + ), + array( + 'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77', + 'truncate' => false, + 'expected' => 'PrettyVersion bbf527a27356414bfa9bf520f018c5cb7af67c77' + ), ); $self = $this;