Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix compilation of projects using dev composer plugins #879

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fix
  • Loading branch information
theofidry committed Feb 16, 2023
commit 2f1f75461f6bee36661a8862409e3e7d6178fe34
29 changes: 25 additions & 4 deletions tests/Console/Command/CompileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CompileTest extends FileSystemTestCase
{
use RequiresPharReadonlyOff;

private const NUMBER_OF_FILES = 48;
private const NUMBER_OF_FILES = 50;

private const BOX_FILES = [
'/.box/',
Expand Down Expand Up @@ -138,6 +138,8 @@ class CompileTest extends FileSystemTestCase
'/vendor/autoload.php',
'/vendor/composer/',
'/vendor/composer/ClassLoader.php',
'/vendor/composer/InstalledVersions.php',
'/vendor/composer/installed.php',
'/vendor/composer/LICENSE',
'/vendor/composer/autoload_classmap.php',
'/vendor/composer/autoload_namespaces.php',
Expand Down Expand Up @@ -633,7 +635,7 @@ public function test_it_can_build_a_phar_with_complete_mapping(): void
No recommendation found.
No warning found.

// PHAR: 13 files (100B)
// PHAR: 15 files (100B)
// You can inspect the generated PHAR with the "info" command.

// Memory usage: 5.00MB (peak: 10.00MB), time: 0.00s
Expand Down Expand Up @@ -698,7 +700,9 @@ public function test_it_can_build_a_phar_with_complete_mapping(): void
'/vendor/autoload.php',
'/vendor/composer/',
'/vendor/composer/ClassLoader.php',
'/vendor/composer/InstalledVersions.php',
'/vendor/composer/LICENSE',
'/vendor/composer/installed.php',
'/vendor/composer/autoload_classmap.php',
'/vendor/composer/autoload_namespaces.php',
'/vendor/composer/autoload_psr4.php',
Expand Down Expand Up @@ -794,7 +798,7 @@ public function test_it_can_build_a_phar_file_in_verbose_mode(): void

$shebang = sprintf('#!%s', (new PhpExecutableFinder())->find());

$expectedNumberOfClasses = 1;
$expectedNumberOfClasses = 4;
$expectedNumberOfFiles = self::NUMBER_OF_FILES;

dump_file(
Expand Down Expand Up @@ -873,6 +877,9 @@ public function test_it_can_build_a_phar_file_in_verbose_mode(): void
'rand' => {$rand},
)
? Dumping the Composer autoloader
> '/usr/local/bin/composer' 'install' '--no-dev' '--no-scripts' '--no-plugins'
Composer install output

> '/usr/local/bin/composer' 'dump-autoload' '--classmap-authoritative' '--no-dev'
Generating optimized autoload files (authoritative)
Generated optimized autoload files (authoritative) containing {$expectedNumberOfClasses} classes
Expand Down Expand Up @@ -902,6 +909,7 @@ public function test_it_can_build_a_phar_file_in_verbose_mode(): void
$expected,
ExitCode::SUCCESS,
self::createComposerPathNormalizer(),
self::createComposerInstallNoDevNormalizer(),
);
}

Expand All @@ -915,7 +923,7 @@ public function test_it_can_build_a_phar_file_in_very_verbose_mode(): void

$shebang = sprintf('#!%s', (new PhpExecutableFinder())->find());

$expectedNumberOfClasses = 1;
$expectedNumberOfClasses = 4;
$expectedNumberOfFiles = self::NUMBER_OF_FILES;

dump_file(
Expand Down Expand Up @@ -998,6 +1006,9 @@ public function test_it_can_build_a_phar_file_in_very_verbose_mode(): void
'rand' => {$rand},
)
? Dumping the Composer autoloader
> '/usr/local/bin/composer' 'install' '--no-dev' '--no-scripts' '--no-plugins' '-v'
Composer install output

> '/usr/local/bin/composer' 'dump-autoload' '--classmap-authoritative' '--no-dev' '-v'
Generating optimized autoload files (authoritative)
Generated optimized autoload files (authoritative) containing {$expectedNumberOfClasses} classes
Expand Down Expand Up @@ -1033,6 +1044,7 @@ public function test_it_can_build_a_phar_file_in_very_verbose_mode(): void
$expected,
ExitCode::SUCCESS,
self::createComposerPathNormalizer(),
self::createComposerInstallNoDevNormalizer(),
);
}

Expand Down Expand Up @@ -3042,6 +3054,15 @@ private static function createComposerPathNormalizer(): callable
);
}

private static function createComposerInstallNoDevNormalizer(): callable
{
return static fn (string $output): string => preg_replace(
'/No composer\.lock file present\.[\s\S]*Generating autoload files/',
'Composer install output',
$output,
);
}

private function retrievePharFiles(Phar $phar, ?Traversable $traversable = null): array
{
$root = 'phar://'.str_replace('\\', '/', realpath($phar->getPath())).'/';
Expand Down