From 02e4a2d1a3c6a6f85ab5daa4190d063178d6a90d Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Wed, 30 Aug 2023 21:42:45 +0200 Subject: [PATCH] Add test case for `DumpAutoloadCommand` with failing --strict-psr check (#11606) --- .../Test/Command/DumpAutoloadCommandTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/Composer/Test/Command/DumpAutoloadCommandTest.php b/tests/Composer/Test/Command/DumpAutoloadCommandTest.php index 3d5e5b67f..6ac3ce5db 100644 --- a/tests/Composer/Test/Command/DumpAutoloadCommandTest.php +++ b/tests/Composer/Test/Command/DumpAutoloadCommandTest.php @@ -47,6 +47,24 @@ class DumpAutoloadCommandTest extends TestCase $this->assertMatchesRegularExpression('/Generated optimized autoload files containing \d+ classes/', $output); } + public function testFailsUsingStrictPsrIfClassMapViolationsAreFound(): void + { + $dir = $this->initTempComposer([ + 'autoload' => [ + 'psr-4' => [ + 'Application\\' => 'src', + ] + ] + ]); + mkdir($dir . '/src/'); + file_put_contents($dir . '/src/Foo.php', 'getApplicationTester(); + $this->assertSame(1, $appTester->run(['command' => 'dump-autoload', '--optimize' => true, '--strict-psr' => true])); + + $output = $appTester->getDisplay(true); + $this->assertMatchesRegularExpression('/Class Application\\\Src\\\Foo located in .*? does not comply with psr-4 autoloading standard. Skipping./', $output); + } + public function testUsingClassmapAuthoritative(): void { $appTester = $this->getApplicationTester();