From c3b184edede5c9498c2bdf8abf1a9e3564cce4ec Mon Sep 17 00:00:00 2001 From: Aron Rotteveel Date: Fri, 15 Nov 2019 16:05:34 +0100 Subject: [PATCH 1/7] use the exact same paths for checking Composer dependencies as 1.5 --- src/PackageVersions/FallbackVersions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PackageVersions/FallbackVersions.php b/src/PackageVersions/FallbackVersions.php index e62d9e7..d20cd68 100644 --- a/src/PackageVersions/FallbackVersions.php +++ b/src/PackageVersions/FallbackVersions.php @@ -61,12 +61,14 @@ private static function getPackageData() : array $checkedPaths = [ // The top-level project's ./vendor/composer/installed.json getcwd() . '/vendor/composer/installed.json', + __DIR__ . '/../../../../composer/installed.json', // The top-level project's ./composer.lock getcwd() . '/composer.lock', + __DIR__ . '/../../../../../composer.lock', // This package's composer.lock __DIR__ . '/../../composer.lock', ]; - + $packageData = []; foreach ($checkedPaths as $path) { if (! file_exists($path)) { From 9352168901bed5750712efbf5201e907ff0d687d Mon Sep 17 00:00:00 2001 From: Aron Rotteveel Date: Fri, 15 Nov 2019 16:06:49 +0100 Subject: [PATCH 2/7] no whitespace --- src/PackageVersions/FallbackVersions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PackageVersions/FallbackVersions.php b/src/PackageVersions/FallbackVersions.php index d20cd68..7c20e41 100644 --- a/src/PackageVersions/FallbackVersions.php +++ b/src/PackageVersions/FallbackVersions.php @@ -68,7 +68,7 @@ private static function getPackageData() : array // This package's composer.lock __DIR__ . '/../../composer.lock', ]; - + $packageData = []; foreach ($checkedPaths as $path) { if (! file_exists($path)) { From 60dfd0e313108d81952a901308ad07585e60c92c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 17 Jul 2019 17:09:36 +0200 Subject: [PATCH 3/7] #101 corrected scanned locations for `installed.json` and `composer.json` Due to `getcwd()` returning an empty string in some environments, (or even `"."`, a dot, sometimes), this fallback versions logic was too fragile. Adding hardcoded paths that are supposed to be constant (relative to the installation path of `FallbackVersions.php`) gives us more stability. --- test/PackageVersionsTest/E2EInstallerTest.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/PackageVersionsTest/E2EInstallerTest.php b/test/PackageVersionsTest/E2EInstallerTest.php index 3add4ca..cc19f8e 100644 --- a/test/PackageVersionsTest/E2EInstallerTest.php +++ b/test/PackageVersionsTest/E2EInstallerTest.php @@ -185,6 +185,38 @@ public function testRemovingPluginWithNoDevDoesNotAttemptToGenerateVersions() : ); } + /** + * @group 101 + */ + public function testInstallingPluginWithNoScriptsLeadsToUsableVersionsClass() : void + { + $this->createPackageVersionsArtifact(); + $this->createArtifact(); + + $this->writeComposerJsonFile( + [ + 'name' => 'package-versions/e2e-local', + 'require' => ['ocramius/package-versions' => '1.0.0'], + 'repositories' => [ + ['packagist' => false], + [ + 'type' => 'artifact', + 'url' => $this->tempArtifact, + ], + ], + ], + $this->tempLocalComposerHome + ); + + $this->execComposerInDir('install --no-scripts', $this->tempLocalComposerHome); + $this->assertFileExists( + $this->tempLocalComposerHome . '/vendor/ocramius/package-versions/src/PackageVersions/Versions.php' + ); + + $this->writePackageVersionUsingFile($this->tempLocalComposerHome); + $this->assertPackageVersionsIsUsable($this->tempLocalComposerHome); + } + private function createPackageVersionsArtifact() : void { $zip = new ZipArchive(); @@ -255,6 +287,30 @@ private function writeComposerJsonFile(array $config, string $directory) : void ); } + private function writePackageVersionUsingFile(string $directory) : void + { + file_put_contents( + $directory . '/use-package-versions.php', + <<<'PHP' + Date: Wed, 17 Jul 2019 17:25:41 +0200 Subject: [PATCH 4/7] Aliasing current branch as `master` in CI Otherwise, composer cannot determine the current branch-alias, and fails early during installation. --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 9533b3f..3ad4419 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,9 @@ env: - DEPENDENCIES="--no-scripts" 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 - composer update --prefer-dist $DEPENDENCIES From 9eddffa5042060f3761b58693992c2199e68b3f8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 17 Jul 2019 17:25:55 +0200 Subject: [PATCH 5/7] CS (spacing, imports) --- test/PackageVersionsTest/E2EInstallerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/PackageVersionsTest/E2EInstallerTest.php b/test/PackageVersionsTest/E2EInstallerTest.php index cc19f8e..4617fd6 100644 --- a/test/PackageVersionsTest/E2EInstallerTest.php +++ b/test/PackageVersionsTest/E2EInstallerTest.php @@ -12,10 +12,12 @@ use ZipArchive; use const JSON_PRETTY_PRINT; use const JSON_UNESCAPED_SLASHES; +use const PHP_BINARY; use function array_filter; use function array_map; use function array_walk; use function chdir; +use function escapeshellarg; use function exec; use function file_get_contents; use function file_put_contents; @@ -298,7 +300,6 @@ private function writePackageVersionUsingFile(string $directory) : void echo \PackageVersions\Versions::getVersion('ocramius/package-versions'); PHP - ); } From 03e5174d2e68a9a72d8957c4668dbc01eb5a4072 Mon Sep 17 00:00:00 2001 From: Aron Rotteveel Date: Fri, 15 Nov 2019 17:01:55 +0100 Subject: [PATCH 6/7] update dev-master alias to point to 1.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2062e76..1f39b89 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "extra": { "class": "PackageVersions\\Installer", "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.5.x-dev" } }, "scripts": { From 4c3b36792453b3945bc5be9093973e4bfe56361c Mon Sep 17 00:00:00 2001 From: Aron Rotteveel Date: Fri, 15 Nov 2019 17:07:57 +0100 Subject: [PATCH 7/7] allow major versions to increment :) --- composer.json | 2 +- test/PackageVersionsTest/E2EInstallerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1f39b89..2062e76 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "extra": { "class": "PackageVersions\\Installer", "branch-alias": { - "dev-master": "1.5.x-dev" + "dev-master": "2.0.x-dev" } }, "scripts": { diff --git a/test/PackageVersionsTest/E2EInstallerTest.php b/test/PackageVersionsTest/E2EInstallerTest.php index 4617fd6..4778fc3 100644 --- a/test/PackageVersionsTest/E2EInstallerTest.php +++ b/test/PackageVersionsTest/E2EInstallerTest.php @@ -309,7 +309,7 @@ private function assertPackageVersionsIsUsable(string $directory) : void self::assertSame(0, $exitCode); self::assertCount(1, $output); - self::assertRegExp('/^1\\..*\\@[a-f0-9]*$/', $output[0]); + self::assertRegExp('/^\d+\\..*\\@[a-f0-9]*$/', $output[0]); } /**