diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php index a6c6a5ae4..2014940c3 100644 --- a/src/Composer/Command/DumpAutoloadCommand.php +++ b/src/Composer/Command/DumpAutoloadCommand.php @@ -70,8 +70,8 @@ EOT $apcuPrefix = $input->getOption('apcu-prefix'); $apcu = $apcuPrefix !== null || $input->getOption('apcu') || $config->get('apcu-autoloader'); - if ($input->getOption('strict-psr') && !$optimize) { - throw new \InvalidArgumentException('--strict-psr mode only works with optimized autoloader, use --optimize if you want a strict return value.'); + if ($input->getOption('strict-psr') && !$optimize && !$authoritative) { + throw new \InvalidArgumentException('--strict-psr mode only works with optimized autoloader, use --optimize or --classmap-authoritative if you want a strict return value.'); } if ($authoritative) { diff --git a/tests/Composer/Test/Command/DumpAutoloadCommandTest.php b/tests/Composer/Test/Command/DumpAutoloadCommandTest.php index 6ac3ce5db..de58f5295 100644 --- a/tests/Composer/Test/Command/DumpAutoloadCommandTest.php +++ b/tests/Composer/Test/Command/DumpAutoloadCommandTest.php @@ -75,12 +75,22 @@ class DumpAutoloadCommandTest extends TestCase $this->assertMatchesRegularExpression('/Generated optimized autoload files \(authoritative\) containing \d+ classes/', $output); } + public function testUsingClassmapAuthoritativeAndStrictPsr(): void + { + $appTester = $this->getApplicationTester(); + $this->assertSame(0, $appTester->run(['command' => 'dump-autoload', '--classmap-authoritative' => true, '--strict-psr' => true])); + + $output = $appTester->getDisplay(true); + $this->assertStringContainsString('Generating optimized autoload files', $output); + $this->assertMatchesRegularExpression('/Generated optimized autoload files \(authoritative\) containing \d+ classes/', $output); + } + public function testStrictPsrDoesNotWorkWithoutOptimizedAutoloader(): void { $appTester = $this->getApplicationTester(); $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('--strict-psr mode only works with optimized autoloader, use --optimize if you want a strict return value.'); + $this->expectExceptionMessage('--strict-psr mode only works with optimized autoloader, use --optimize or --classmap-authoritative if you want a strict return value.'); $appTester->run(['command' => 'dump-autoload', '--strict-psr' => true]); }