From 879524d8e3fc04a0bd9a1b6f29ea49f1280741c0 Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Wed, 30 Aug 2023 16:09:05 +0200 Subject: [PATCH] Add tests for DumpAutoloadCommand (#11581) --- .../Test/Command/DumpAutoloadCommandTest.php | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/Composer/Test/Command/DumpAutoloadCommandTest.php diff --git a/tests/Composer/Test/Command/DumpAutoloadCommandTest.php b/tests/Composer/Test/Command/DumpAutoloadCommandTest.php new file mode 100644 index 000000000..3d5e5b67f --- /dev/null +++ b/tests/Composer/Test/Command/DumpAutoloadCommandTest.php @@ -0,0 +1,77 @@ +getApplicationTester(); + $this->assertSame(0, $appTester->run(['command' => 'dump-autoload'])); + + $output = $appTester->getDisplay(true); + $this->assertStringContainsString('Generating autoload files', $output); + $this->assertStringContainsString('Generated autoload files', $output); + } + + public function testDumpDevAutoload(): void + { + $appTester = $this->getApplicationTester(); + $this->assertSame(0, $appTester->run(['command' => 'dump-autoload', '--dev' => true])); + + $output = $appTester->getDisplay(true); + $this->assertStringContainsString('Generating autoload files', $output); + $this->assertStringContainsString('Generated autoload files', $output); + } + + public function testDumpNoDevAutoload(): void + { + $appTester = $this->getApplicationTester(); + $this->assertSame(0, $appTester->run(['command' => 'dump-autoload', '--dev' => true])); + + $output = $appTester->getDisplay(true); + $this->assertStringContainsString('Generating autoload files', $output); + $this->assertStringContainsString('Generated autoload files', $output); + } + + public function testUsingOptimizeAndStrictPsr(): void + { + $appTester = $this->getApplicationTester(); + $this->assertSame(0, $appTester->run(['command' => 'dump-autoload', '--optimize' => true, '--strict-psr' => true])); + + $output = $appTester->getDisplay(true); + $this->assertStringContainsString('Generating optimized autoload files', $output); + $this->assertMatchesRegularExpression('/Generated optimized autoload files containing \d+ classes/', $output); + } + + public function testUsingClassmapAuthoritative(): void + { + $appTester = $this->getApplicationTester(); + $this->assertSame(0, $appTester->run(['command' => 'dump-autoload', '--classmap-authoritative' => true])); + + $output = $appTester->getDisplay(true); + $this->assertStringContainsString('Generating optimized autoload files (authoritative)', $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.'); + $appTester->run(['command' => 'dump-autoload', '--strict-psr' => true]); + } + + public function testDevAndNoDevCannotBeCombined(): void + { + $appTester = $this->getApplicationTester(); + + $this->expectException(InvalidArgumentException::class); + $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]); + } +}