1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 08:32:56 +00:00

feat: improve Composer's output reproducibility (#11663)

* AutoloadGenerator: add `Locker` parameter to the `dump` method
* AutoloadGenerator: do not create a random hash, re-use the one from the lock file if it exists
* FileSystem: make sure `safeCopy` copy also the file time metadata
This commit is contained in:
Pol Dellaiera 2023-09-28 11:43:52 +02:00 committed by GitHub
parent 77fadf0e1e
commit b608b8e87e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 187 additions and 56 deletions

View file

@ -102,4 +102,86 @@ class DumpAutoloadCommandTest extends TestCase
$this->expectExceptionMessage('You can not use both --no-dev and --dev as they conflict with each other.');
$appTester->run(['command' => 'dump-autoload', '--dev' => true, '--no-dev' => true]);
}
public function testWithCustomAutoloaderSuffix(): void
{
$dir = $this->initTempComposer([
'config' => [
'autoloader-suffix' => 'Foobar',
],
]);
$appTester = $this->getApplicationTester();
$this->assertSame(0, $appTester->run(['command' => 'dump-autoload']));
self::assertStringContainsString('ComposerAutoloaderInitFoobar', (string) file_get_contents($dir . '/vendor/autoload.php'));
}
public function testWithExistingComposerLockAndAutoloaderSuffix(): void
{
$dir = $this->initTempComposer(
[
'config' => [
'autoloader-suffix' => 'Foobar',
],
],
[],
[
"_readme" => [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash" => "d751713988987e9331980363e24189ce",
"packages" => [],
"packages-dev" => [],
"aliases" => [],
"minimum-stability" => "stable",
"stability-flags" => [],
"prefer-stable" => false,
"prefer-lowest" => false,
"platform" => [],
"platform-dev" => [],
"plugin-api-version" => "2.6.0"
]
);
$appTester = $this->getApplicationTester();
$this->assertSame(0, $appTester->run(['command' => 'dump-autoload']));
self::assertStringContainsString('ComposerAutoloaderInitFoobar', (string) file_get_contents($dir . '/vendor/autoload.php'));
}
public function testWithExistingComposerLockWithoutAutoloaderSuffix(): void
{
$dir = $this->initTempComposer(
[
'name' => 'foo/bar',
],
[],
[
"_readme" => [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash" => "2d4a6be9a93712c5d6a119b26734a047",
"packages" => [],
"packages-dev" => [],
"aliases" => [],
"minimum-stability" => "stable",
"stability-flags" => [],
"prefer-stable" => false,
"prefer-lowest" => false,
"platform" => [],
"platform-dev" => [],
"plugin-api-version" => "2.6.0"
]
);
$appTester = $this->getApplicationTester();
$this->assertSame(0, $appTester->run(['command' => 'dump-autoload']));
self::assertStringContainsString('ComposerAutoloaderInit2d4a6be9a93712c5d6a119b26734a047', (string) file_get_contents($dir . '/vendor/autoload.php'));
}
}