Skip to content

Commit

Permalink
Merge pull request #9 from nicolas-grekas/sync-upstream
Browse files Browse the repository at this point in the history
Sync with v1.11.0
  • Loading branch information
Seldaek committed Aug 25, 2020
2 parents 68c9b50 + 3969dab commit c8c9aa8
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ before_script:
# aliasing current branch as `master`, since otherwise composer cannot determine the current branch-alias
- git branch -D master || true
- git checkout -b master
- composer self-update
- if [[ $DEPENDENCIES = '--no-scripts' ]]; then composer self-update --2; else composer self-update; fi
- if [[ $LOCKED_DEPENDENCIES = '1' ]]; then composer install; fi
- if [[ $LOCKED_DEPENDENCIES = '' ]]; then composer update $DEPENDENCIES; fi

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"composer-plugin-api": "^1.1.0 || ^2.0"
},
"replace": {
"ocramius/package-versions": "1.10.99"
"ocramius/package-versions": "1.11.99"
},
"require-dev": {
"phpunit/phpunit": "^6.5 || ^7",
Expand Down
24 changes: 19 additions & 5 deletions src/PackageVersions/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ final class Installer implements PluginInterface, EventSubscriberInterface
use Composer\InstalledVersions;
use OutOfBoundsException;
class_exists(InstalledVersions::class);
/**
* This class is generated by composer/package-versions-deprecated, specifically by
* @see \PackageVersions\Installer
Expand All @@ -54,9 +56,7 @@ final class Installer implements PluginInterface, EventSubscriberInterface
%s
{
/**
* @deprecated please use {@see \Composer\InstalledVersions::getRootPackage()} instead. The
* equivalent expression for this constant's contents is
* `\Composer\InstalledVersions::getRootPackage()['name']`.
* @deprecated please use {@see self::rootPackageName()} instead.
* This constant will be removed in version 2.0.0.
*/
const ROOT_PACKAGE_NAME = '%s';
Expand All @@ -72,7 +72,21 @@ final class Installer implements PluginInterface, EventSubscriberInterface
private function __construct()
{
class_exists(InstalledVersions::class);
}
/**
* @psalm-pure
*
* @psalm-suppress ImpureMethodCall we know that {@see InstalledVersions} interaction does not
* cause any side effects here.
*/
public static function rootPackageName() : string
{
if (!class_exists(InstalledVersions::class, false) || !InstalledVersions::getRawData()) {
return self::ROOT_PACKAGE_NAME;
}
return InstalledVersions::getRootPackage()['name'];
}
/**
Expand All @@ -86,7 +100,7 @@ class_exists(InstalledVersions::class);
*/
public static function getVersion(string $packageName): string
{
if (class_exists(InstalledVersions::class, false)) {
if (class_exists(InstalledVersions::class, false) && InstalledVersions::getRawData()) {
return InstalledVersions::getPrettyVersion($packageName)
. '@' . InstalledVersions::getReference($packageName);
}
Expand Down
35 changes: 29 additions & 6 deletions src/PackageVersions/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use OutOfBoundsException;
use UnexpectedValueException;

class_exists(InstalledVersions::class);

/**
* This is a stub class: it is in place only for scenarios where PackageVersions
* is installed with a `--no-scripts` flag, in which scenarios the Versions class
Expand All @@ -19,17 +21,31 @@
final class Versions
{
/**
* @deprecated please use {@see \Composer\InstalledVersions::getRootPackage()} instead. The
* equivalent expression for this constant's contents is
* `\Composer\InstalledVersions::getRootPackage()['name']`.
* @deprecated please use {@see self::rootPackageName()} instead.
* This constant will be removed in version 2.0.0.
*/
const ROOT_PACKAGE_NAME = FallbackVersions::ROOT_PACKAGE_NAME;
const ROOT_PACKAGE_NAME = 'unknown/root-package@UNKNOWN';

/** @internal */
const VERSIONS = [];

private function __construct()
{
class_exists(InstalledVersions::class);
}

/**
* @psalm-pure
*
* @psalm-suppress ImpureMethodCall we know that {@see InstalledVersions} interaction does not
* cause any side effects here.
*/
public static function rootPackageName() : string
{
if (!class_exists(InstalledVersions::class, false) || !InstalledVersions::getRawData()) {
return self::ROOT_PACKAGE_NAME;
}

return InstalledVersions::getRootPackage()['name'];
}

/**
Expand All @@ -38,10 +54,17 @@ class_exists(InstalledVersions::class);
*/
public static function getVersion(string $packageName): string
{
if (!class_exists(InstalledVersions::class, false)) {
if (!class_exists(InstalledVersions::class, false) || !InstalledVersions::getRawData()) {
return FallbackVersions::getVersion($packageName);
}

/** @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
96 changes: 76 additions & 20 deletions test/PackageVersionsTest/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ public function testDumpVersionsClass()
use Composer\InstalledVersions;
use OutOfBoundsException;
class_exists(InstalledVersions::class);
/**
* This class is generated by composer/package-versions-deprecated, specifically by
* @see \PackageVersions\Installer
Expand All @@ -280,9 +282,7 @@ public function testDumpVersionsClass()
final class Versions
{
/**
* @deprecated please use {@see \Composer\InstalledVersions::getRootPackage()} instead. The
* equivalent expression for this constant's contents is
* `\Composer\InstalledVersions::getRootPackage()['name']`.
* @deprecated please use {@see self::rootPackageName()} instead.
* This constant will be removed in version 2.0.0.
*/
const ROOT_PACKAGE_NAME = 'root/package';
Expand All @@ -305,7 +305,21 @@ final class Versions
private function __construct()
{
class_exists(InstalledVersions::class);
}
/**
* @psalm-pure
*
* @psalm-suppress ImpureMethodCall we know that {@see InstalledVersions} interaction does not
* cause any side effects here.
*/
public static function rootPackageName() : string
{
if (!class_exists(InstalledVersions::class, false) || !InstalledVersions::getRawData()) {
return self::ROOT_PACKAGE_NAME;
}
return InstalledVersions::getRootPackage()['name'];
}
/**
Expand All @@ -319,7 +333,7 @@ class_exists(InstalledVersions::class);
*/
public static function getVersion(string $packageName): string
{
if (class_exists(InstalledVersions::class, false)) {
if (class_exists(InstalledVersions::class, false) && InstalledVersions::getRawData()) {
return InstalledVersions::getPrettyVersion($packageName)
. '@' . InstalledVersions::getReference($packageName);
}
Expand Down Expand Up @@ -404,6 +418,8 @@ public function testDumpVersionsClassNoDev()
use Composer\InstalledVersions;
use OutOfBoundsException;
class_exists(InstalledVersions::class);
/**
* This class is generated by composer/package-versions-deprecated, specifically by
* @see \PackageVersions\Installer
Expand All @@ -415,9 +431,7 @@ public function testDumpVersionsClassNoDev()
final class Versions
{
/**
* @deprecated please use {@see \Composer\InstalledVersions::getRootPackage()} instead. The
* equivalent expression for this constant's contents is
* `\Composer\InstalledVersions::getRootPackage()['name']`.
* @deprecated please use {@see self::rootPackageName()} instead.
* This constant will be removed in version 2.0.0.
*/
const ROOT_PACKAGE_NAME = 'root/package';
Expand All @@ -439,7 +453,21 @@ final class Versions
private function __construct()
{
class_exists(InstalledVersions::class);
}
/**
* @psalm-pure
*
* @psalm-suppress ImpureMethodCall we know that {@see InstalledVersions} interaction does not
* cause any side effects here.
*/
public static function rootPackageName() : string
{
if (!class_exists(InstalledVersions::class, false) || !InstalledVersions::getRawData()) {
return self::ROOT_PACKAGE_NAME;
}
return InstalledVersions::getRootPackage()['name'];
}
/**
Expand All @@ -453,7 +481,7 @@ class_exists(InstalledVersions::class);
*/
public static function getVersion(string $packageName): string
{
if (class_exists(InstalledVersions::class, false)) {
if (class_exists(InstalledVersions::class, false) && InstalledVersions::getRawData()) {
return InstalledVersions::getPrettyVersion($packageName)
. '@' . InstalledVersions::getReference($packageName);
}
Expand Down Expand Up @@ -542,6 +570,8 @@ public function testDumpVersionsWithoutPackageSourceDetails()
use Composer\InstalledVersions;
use OutOfBoundsException;
class_exists(InstalledVersions::class);
/**
* This class is generated by composer/package-versions-deprecated, specifically by
* @see \PackageVersions\Installer
Expand All @@ -553,9 +583,7 @@ public function testDumpVersionsWithoutPackageSourceDetails()
final class Versions
{
/**
* @deprecated please use {@see \Composer\InstalledVersions::getRootPackage()} instead. The
* equivalent expression for this constant's contents is
* `\Composer\InstalledVersions::getRootPackage()['name']`.
* @deprecated please use {@see self::rootPackageName()} instead.
* This constant will be removed in version 2.0.0.
*/
const ROOT_PACKAGE_NAME = 'root/package';
Expand All @@ -577,7 +605,21 @@ final class Versions
private function __construct()
{
class_exists(InstalledVersions::class);
}
/**
* @psalm-pure
*
* @psalm-suppress ImpureMethodCall we know that {@see InstalledVersions} interaction does not
* cause any side effects here.
*/
public static function rootPackageName() : string
{
if (!class_exists(InstalledVersions::class, false) || !InstalledVersions::getRawData()) {
return self::ROOT_PACKAGE_NAME;
}
return InstalledVersions::getRootPackage()['name'];
}
/**
Expand All @@ -591,7 +633,7 @@ class_exists(InstalledVersions::class);
*/
public static function getVersion(string $packageName): string
{
if (class_exists(InstalledVersions::class, false)) {
if (class_exists(InstalledVersions::class, false) && InstalledVersions::getRawData()) {
return InstalledVersions::getPrettyVersion($packageName)
. '@' . InstalledVersions::getReference($packageName);
}
Expand Down Expand Up @@ -973,6 +1015,8 @@ public function testGetVersionsIsNotNormalizedForRootPackage()
use Composer\InstalledVersions;
use OutOfBoundsException;
class_exists(InstalledVersions::class);
/**
* This class is generated by composer/package-versions-deprecated, specifically by
* @see \PackageVersions\Installer
Expand All @@ -984,9 +1028,7 @@ public function testGetVersionsIsNotNormalizedForRootPackage()
final class Versions
{
/**
* @deprecated please use {@see \Composer\InstalledVersions::getRootPackage()} instead. The
* equivalent expression for this constant's contents is
* `\Composer\InstalledVersions::getRootPackage()['name']`.
* @deprecated please use {@see self::rootPackageName()} instead.
* This constant will be removed in version 2.0.0.
*/
const ROOT_PACKAGE_NAME = 'root/package';
Expand All @@ -1006,7 +1048,21 @@ final class Versions
private function __construct()
{
class_exists(InstalledVersions::class);
}
/**
* @psalm-pure
*
* @psalm-suppress ImpureMethodCall we know that {@see InstalledVersions} interaction does not
* cause any side effects here.
*/
public static function rootPackageName() : string
{
if (!class_exists(InstalledVersions::class, false) || !InstalledVersions::getRawData()) {
return self::ROOT_PACKAGE_NAME;
}
return InstalledVersions::getRootPackage()['name'];
}
/**
Expand All @@ -1020,7 +1076,7 @@ class_exists(InstalledVersions::class);
*/
public static function getVersion(string $packageName): string
{
if (class_exists(InstalledVersions::class, false)) {
if (class_exists(InstalledVersions::class, false) && InstalledVersions::getRawData()) {
return InstalledVersions::getPrettyVersion($packageName)
. '@' . InstalledVersions::getReference($packageName);
}
Expand Down
19 changes: 14 additions & 5 deletions test/PackageVersionsTest/VersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
use function json_decode;
use function uniqid;

/**
* @uses \PackageVersions\FallbackVersions
*
* @covers \PackageVersions\Versions
*/
/** @covers \PackageVersions\Versions */
final class VersionsTest extends TestCase
{
public function testValidVersions()
Expand All @@ -36,6 +32,19 @@ public function testValidVersions()
}
}

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

/** @group #153 */
public function testCanRetrieveRootPackageName()
{
self::assertRegExp('/^[a-z0-9\\-]+\\/[a-z0-9\\-]+$/', Versions::rootPackageName());
}

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

0 comments on commit c8c9aa8

Please sign in to comment.