Skip to content

Commit

Permalink
Merge pull request #150 from Ocramius/fix/#148-retrieve-root-package-…
Browse files Browse the repository at this point in the history
…name-version

#148 retrieve root package version also when package is installed with `--no-scripts`
  • Loading branch information
Ocramius committed Aug 18, 2020
2 parents eac17b0 + 214acb9 commit e19f578
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/PackageVersions/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ private function __construct()
*/
public static function getVersion(string $packageName) : string
{
/** @psalm-suppress DeprecatedConstant */
if ($packageName === self::ROOT_PACKAGE_NAME) {
$rootPackage = InstalledVersions::getRootPackage();

return $rootPackage['pretty_version'] . '@' . $rootPackage['reference'];
}

return InstalledVersions::getPrettyVersion($packageName)
. '@' . InstalledVersions::getReference($packageName);
}
Expand Down
7 changes: 7 additions & 0 deletions test/PackageVersionsTest/VersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public function testValidVersions(): void
}
}

/** @group #148 */
public function testCanRetrieveRootPackageVersion(): void
{
/** @psalm-suppress DeprecatedConstant */
self::assertMatchesRegularExpression('/^.+\@[0-9a-f]+$/', Versions::getVersion(Versions::ROOT_PACKAGE_NAME));
}

public function testInvalidVersionsAreRejected(): void
{
$this->expectException(OutOfBoundsException::class);
Expand Down

0 comments on commit e19f578

Please sign in to comment.