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 diff --git a/src/PackageVersions/FallbackVersions.php b/src/PackageVersions/FallbackVersions.php index e62d9e7..7c20e41 100644 --- a/src/PackageVersions/FallbackVersions.php +++ b/src/PackageVersions/FallbackVersions.php @@ -61,8 +61,10 @@ 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', ]; diff --git a/test/PackageVersionsTest/E2EInstallerTest.php b/test/PackageVersionsTest/E2EInstallerTest.php index 3add4ca..4778fc3 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; @@ -185,6 +187,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 +289,29 @@ private function writeComposerJsonFile(array $config, string $directory) : void ); } + private function writePackageVersionUsingFile(string $directory) : void + { + file_put_contents( + $directory . '/use-package-versions.php', + <<<'PHP' +