1
0
Fork 0

Show that no version was found in composer show/license if root package is auto-versioned, fixes #4158

pull/4146/merge
Jordi Boggiano 2015-06-18 23:47:17 +01:00
parent c8eca6f198
commit a943827371
2 changed files with 31 additions and 1 deletions

View File

@ -50,6 +50,7 @@ class RootPackageLoader extends ArrayLoader
if (!isset($config['name'])) {
$config['name'] = '__root__';
}
$autoVersioned = false;
if (!isset($config['version'])) {
// override with env var if available
if (getenv('COMPOSER_ROOT_VERSION')) {
@ -60,17 +61,21 @@ class RootPackageLoader extends ArrayLoader
if (!$version) {
$version = '1.0.0';
$autoVersioned = true;
}
$config['version'] = $version;
}
$realPackage = $package = parent::load($config, $class);
if ($realPackage instanceof AliasPackage) {
$realPackage = $package->getAliasOf();
}
if ($autoVersioned) {
$realPackage->replaceVersion($realPackage->getVersion(), 'No version set (parsed as 1.0.0)');
}
if (isset($config['minimum-stability'])) {
$realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
}

View File

@ -118,6 +118,31 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("dev-foo", $package->getVersion());
}
public function testNoVersionIsVisibleInPrettyVersion()
{
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
->disableOriginalConstructor()
->getMock();
$self = $this;
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')
->disableOriginalConstructor()
->getMock();
$processExecutor->expects($this->any())
->method('execute')
->willReturn(null);
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
$package = $loader->load(array());
$this->assertEquals("1.0.0.0", $package->getVersion());
$this->assertEquals("No version set (parsed as 1.0.0)", $package->getPrettyVersion());
}
protected function loadPackage($data)
{
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')