From ff17ac872ae896dd53baca0da51444457eb5db01 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Sun, 9 Oct 2022 21:59:17 +0200 Subject: [PATCH 1/2] Read autoload-dev when parsing composer psr-4 --- composer.json | 4 ++-- .../CommandArguments/CommandArgumentsParser.php | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 3f0e5407..58118880 100644 --- a/composer.json +++ b/composer.json @@ -46,8 +46,8 @@ }, "autoload-dev": { "psr-4": { - "GacelaData\\": "data", - "GacelaTest\\": "tests" + "GacelaData\\": "data/", + "GacelaTest\\": "tests/" } }, "bin": [ diff --git a/src/Console/Domain/CommandArguments/CommandArgumentsParser.php b/src/Console/Domain/CommandArguments/CommandArgumentsParser.php index 94a2d461..12e69268 100644 --- a/src/Console/Domain/CommandArguments/CommandArgumentsParser.php +++ b/src/Console/Domain/CommandArguments/CommandArgumentsParser.php @@ -10,11 +10,19 @@ final class CommandArgumentsParser implements CommandArgumentsParserInterface { - /** @var array{autoload: array{psr-4?:array}} */ + /** + * @var array{ + * autoload: array{psr-4?:array}, + * autoload-dev?: array{psr-4?:array}, + * } + */ private array $composerJson; /** - * @param array{autoload: array{psr-4?:array}} $composerJson + * @param array{ + * autoload: array{psr-4?:array}, + * autoload-dev?: array{psr-4?:array}, + * } $composerJson */ public function __construct(array $composerJson) { @@ -37,6 +45,8 @@ public function parse(string $desiredNamespace): CommandArguments } $psr4 = $this->composerJson['autoload']['psr-4']; + $psr4Dev = $this->composerJson['autoload-dev']['psr-4'] ?? []; + $allPsr4Combinations = $this->allPossiblePsr4Combinations($desiredNamespace); foreach ($allPsr4Combinations as $psr4Combination) { @@ -45,6 +55,9 @@ public function parse(string $desiredNamespace): CommandArguments if (isset($psr4[$psr4Key])) { return $this->foundPsr4($psr4Key, $psr4[$psr4Key], $desiredNamespace); } + if (isset($psr4Dev[$psr4Key])) { + return $this->foundPsr4($psr4Key, $psr4Dev[$psr4Key], $desiredNamespace); + } } throw CommandArgumentsException::noAutoloadPsr4MatchFound($desiredNamespace, array_keys($psr4)); From 6a4b2d1e228115bba6af53155771a6b6cbc79648 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Sun, 9 Oct 2022 22:07:34 +0200 Subject: [PATCH 2/2] Read autoload-dev psr-4 namespaces for gacela make commands --- .gitignore | 6 ++--- CHANGELOG.md | 4 ++++ data/.gitkeep | 0 .../CodeGenerator/MakeModuleCommandTest.php | 22 +++++++++---------- tests/Feature/CodeGenerator/composer.json | 5 +++++ 5 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 data/.gitkeep diff --git a/.gitignore b/.gitignore index 498137d4..19eaa72c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,10 @@ -coverage/ .idea/ .gacela/ .vscode/ -vendor/ -data/ .phpbench/ +coverage/ +data/ +vendor/ *.cache composer.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index ff65fd75..8544d322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### Unreleased + +- Read autoload-dev psr-4 namespaces for gacela make commands. + ### 0.26.0 #### 2022-10-01 diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/tests/Feature/CodeGenerator/MakeModuleCommandTest.php b/tests/Feature/CodeGenerator/MakeModuleCommandTest.php index 0283d5e6..577b39a2 100644 --- a/tests/Feature/CodeGenerator/MakeModuleCommandTest.php +++ b/tests/Feature/CodeGenerator/MakeModuleCommandTest.php @@ -15,13 +15,13 @@ final class MakeModuleCommandTest extends TestCase { public static function tearDownAfterClass(): void { - DirectoryUtil::removeDir('./src/TestModule'); + DirectoryUtil::removeDir('./data/TestModule'); } public function setUp(): void { Gacela::bootstrap(__DIR__); - DirectoryUtil::removeDir('./src/TestModule'); + DirectoryUtil::removeDir('./data/TestModule'); } /** @@ -29,7 +29,7 @@ public function setUp(): void */ public function test_make_module(string $fileName, string $shortName): void { - $input = new StringInput("make:module Psr4CodeGenerator/TestModule {$shortName}"); + $input = new StringInput("make:module Psr4CodeGeneratorData/TestModule {$shortName}"); $output = new BufferedOutput(); $bootstrap = new ConsoleBootstrap(); @@ -37,18 +37,18 @@ public function test_make_module(string $fileName, string $shortName): void $bootstrap->run($input, $output); $expectedOutput = << Path 'src/TestModule/{$fileName}Facade.php' created successfully -> Path 'src/TestModule/{$fileName}Factory.php' created successfully -> Path 'src/TestModule/{$fileName}Config.php' created successfully -> Path 'src/TestModule/{$fileName}DependencyProvider.php' created successfully +> Path 'data/TestModule/{$fileName}Facade.php' created successfully +> Path 'data/TestModule/{$fileName}Factory.php' created successfully +> Path 'data/TestModule/{$fileName}Config.php' created successfully +> Path 'data/TestModule/{$fileName}DependencyProvider.php' created successfully Module 'TestModule' created successfully OUT; self::assertSame($expectedOutput, trim($output->fetch())); - self::assertFileExists("./src/TestModule/{$fileName}Facade.php"); - self::assertFileExists("./src/TestModule/{$fileName}Factory.php"); - self::assertFileExists("./src/TestModule/{$fileName}Config.php"); - self::assertFileExists("./src/TestModule/{$fileName}DependencyProvider.php"); + self::assertFileExists("./data/TestModule/{$fileName}Facade.php"); + self::assertFileExists("./data/TestModule/{$fileName}Factory.php"); + self::assertFileExists("./data/TestModule/{$fileName}Config.php"); + self::assertFileExists("./data/TestModule/{$fileName}DependencyProvider.php"); } public function createModulesProvider(): iterable diff --git a/tests/Feature/CodeGenerator/composer.json b/tests/Feature/CodeGenerator/composer.json index 34ad9523..df8c97e0 100644 --- a/tests/Feature/CodeGenerator/composer.json +++ b/tests/Feature/CodeGenerator/composer.json @@ -3,5 +3,10 @@ "psr-4": { "Psr4CodeGenerator\\": "src/" } + }, + "autoload-dev": { + "psr-4": { + "Psr4CodeGeneratorData\\": "data/" + } } }