Merge remote-tracking branch 'zczapran/issue/1043_wrong_output_for_versions_when_updating'
commit
338730b19b
|
@ -74,7 +74,12 @@ class VersionParser
|
|||
return $package->getPrettyVersion();
|
||||
}
|
||||
|
||||
return $package->getPrettyVersion() . ' ' . ($truncate ? substr($package->getSourceReference(), 0, 6) : $package->getSourceReference());
|
||||
// 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() . ' ' . $package->getSourceReference();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,9 +15,44 @@ namespace Composer\Test\Package\Version;
|
|||
use Composer\Package\Version\VersionParser;
|
||||
use Composer\Package\LinkConstraint\MultiConstraint;
|
||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||
use Composer\Package\PackageInterface;
|
||||
|
||||
class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider formattedVersions
|
||||
*
|
||||
* @param \Composer\Package\PackageInterface $package
|
||||
* @param string $expected
|
||||
*/
|
||||
public function testFormatVersionForDevPackage(PackageInterface $package, $truncate, $expected)
|
||||
{
|
||||
$this->assertSame($expected, VersionParser::formatVersion($package, $truncate));
|
||||
}
|
||||
|
||||
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'),
|
||||
);
|
||||
|
||||
$self = $this;
|
||||
$createPackage = function($arr) use ($self) {
|
||||
$package = $self->getMock('\Composer\Package\PackageInterface');
|
||||
$package->expects($self->once())->method('isDev')->will($self->returnValue(true));
|
||||
$package->expects($self->once())->method('getSourceType')->will($self->returnValue('git'));
|
||||
$package->expects($self->once())->method('getPrettyVersion')->will($self->returnValue('PrettyVersion'));
|
||||
$package->expects($self->any())->method('getSourceReference')->will($self->returnValue($arr['sourceReference']));
|
||||
|
||||
return array($package, $arr['truncate'], $arr['expected']);
|
||||
};
|
||||
|
||||
return array_map($createPackage, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider successfulNormalizedVersions
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue