diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index 6fe8899fb..9c7c436bc 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -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'])); } diff --git a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php index 07aaf7034..37c259676 100644 --- a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php @@ -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')