Skip to content

Commit

Permalink
Merge pull request #102 from Ocramius/fix/#101-correct-fallback-versi…
Browse files Browse the repository at this point in the history
…ons-behavior-with-no-scripts-installation

#101 corrected scanned locations for `installed.json` and `composer.json`
  • Loading branch information
Ocramius committed Jul 17, 2019
2 parents da0d9d3 + 1053ea0 commit 1d32342
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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

Expand Down
2 changes: 2 additions & 0 deletions src/PackageVersions/FallbackVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
Expand Down
57 changes: 57 additions & 0 deletions test/PackageVersionsTest/E2EInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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'
<?php
require_once __DIR__ . '/vendor/autoload.php';
echo \PackageVersions\Versions::getVersion('ocramius/package-versions');
PHP
);
}

private function assertPackageVersionsIsUsable(string $directory) : void
{
exec(PHP_BINARY . ' ' . escapeshellarg($directory . '/use-package-versions.php'), $output, $exitCode);

self::assertSame(0, $exitCode);
self::assertCount(1, $output);
self::assertRegExp('/^1\\..*\\@[a-f0-9]*$/', $output[0]);
}

/**
* @return mixed[]
*/
Expand Down

0 comments on commit 1d32342

Please sign in to comment.