From 3e445f58a4f4bdab2b3365cb2fcba5ac5beefc79 Mon Sep 17 00:00:00 2001 From: Guillaume Turpin Date: Wed, 4 Dec 2024 15:13:56 +0100 Subject: [PATCH 01/11] :sparkles: Make the command --- .../src/Commands/MakeMiddlewareCommand.php | 69 +++++++++++++++++++ .../Console/src/Enums/MiddlewareType.php | 34 +++++++++ .../src/Stubs/CommandBusMiddlewareStub.php | 14 ++++ .../src/Stubs/ConsoleMiddlewareStub.php | 19 +++++ .../src/Stubs/EventBusMiddlewareStub.php | 14 ++++ .../Console/src/Stubs/HttpMiddlewareStub.php | 18 +++++ 6 files changed, 168 insertions(+) create mode 100644 src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php create mode 100644 src/Tempest/Console/src/Enums/MiddlewareType.php create mode 100644 src/Tempest/Console/src/Stubs/CommandBusMiddlewareStub.php create mode 100644 src/Tempest/Console/src/Stubs/ConsoleMiddlewareStub.php create mode 100644 src/Tempest/Console/src/Stubs/EventBusMiddlewareStub.php create mode 100644 src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php diff --git a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php new file mode 100644 index 000000000..4720a4831 --- /dev/null +++ b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php @@ -0,0 +1,69 @@ +getStubFileFromMiddlewareType($middlewareType); + $suggestedPath = $this->getSuggestedPath($className); + $targetPath = $this->promptTargetPath($suggestedPath); + $shouldOverride = $this->askForOverride($targetPath); + + $this->stubFileGenerator->generateClassFile( + stubFile: $stubFile, + targetPath: $targetPath, + shouldOverride: $shouldOverride, + ); + + $this->success(sprintf('Middleware successfully created at "%s".', $targetPath)); + } catch (FileGenerationAbortedException|FileGenerationFailedException|\InvalidArgumentException $e) { + $this->error($e->getMessage()); + } + } + + protected function getStubFileFromMiddlewareType(MiddlewareType $middlewareType): StubFile { + return match ($middlewareType) { + MiddlewareType::CONSOLE => StubFile::from( ConsoleMiddlewareStub::class ), + MiddlewareType::HTTP => StubFile::from( HttpMiddlewareStub::class ), + MiddlewareType::EVENT_BUS => StubFile::from( EventBusMiddlewareStub::class ), + MiddlewareType::COMMAND_BUS => StubFile::from( CommandBusMiddlewareStub::class ), + default => throw new \InvalidArgumentException(sprintf('The "%s" middleware type has no supported stub file.', $middlewareType->value)), + }; + } +} diff --git a/src/Tempest/Console/src/Enums/MiddlewareType.php b/src/Tempest/Console/src/Enums/MiddlewareType.php new file mode 100644 index 000000000..407d8dd0d --- /dev/null +++ b/src/Tempest/Console/src/Enums/MiddlewareType.php @@ -0,0 +1,34 @@ + ConsoleMiddleware::class, + self::HTTP => HttpMiddleware::class, + self::EVENT_BUS => EventBusMiddleware::class, + self::COMMAND_BUS => CommandBusMiddleware::class, + }; + } +} diff --git a/src/Tempest/Console/src/Stubs/CommandBusMiddlewareStub.php b/src/Tempest/Console/src/Stubs/CommandBusMiddlewareStub.php new file mode 100644 index 000000000..4bfbb234e --- /dev/null +++ b/src/Tempest/Console/src/Stubs/CommandBusMiddlewareStub.php @@ -0,0 +1,14 @@ + Date: Wed, 4 Dec 2024 15:17:16 +0100 Subject: [PATCH 02/11] :rotating_light: Fix phpstan issue --- src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php index 4720a4831..824099537 100644 --- a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php +++ b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php @@ -63,7 +63,7 @@ protected function getStubFileFromMiddlewareType(MiddlewareType $middlewareType) MiddlewareType::HTTP => StubFile::from( HttpMiddlewareStub::class ), MiddlewareType::EVENT_BUS => StubFile::from( EventBusMiddlewareStub::class ), MiddlewareType::COMMAND_BUS => StubFile::from( CommandBusMiddlewareStub::class ), - default => throw new \InvalidArgumentException(sprintf('The "%s" middleware type has no supported stub file.', $middlewareType->value)), + default => throw new \InvalidArgumentException(sprintf('The "%s" middleware type has no supported stub file.', $middlewareType->value)), // @phpstan-ignore-line Because this is a guardrail for the future implementations }; } } From 87cf568f70b41e9520487232759bd929ead23187 Mon Sep 17 00:00:00 2001 From: Guillaume Turpin Date: Wed, 4 Dec 2024 15:19:19 +0100 Subject: [PATCH 03/11] :art: Coding styles --- .../src/Commands/MakeMiddlewareCommand.php | 44 +++++++++---------- .../Console/src/Enums/MiddlewareType.php | 12 ++--- .../src/Stubs/CommandBusMiddlewareStub.php | 6 ++- .../src/Stubs/ConsoleMiddlewareStub.php | 10 +++-- .../src/Stubs/EventBusMiddlewareStub.php | 6 ++- .../Console/src/Stubs/HttpMiddlewareStub.php | 10 +++-- 6 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php index 824099537..81fa7288e 100644 --- a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php +++ b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php @@ -4,21 +4,21 @@ namespace Tempest\Console\Commands; -use function Tempest\Support\str; -use Tempest\Generation\Exceptions\FileGenerationFailedException; -use Tempest\Generation\Exceptions\FileGenerationAbortedException; -use Tempest\Generation\DataObjects\StubFile; -use Tempest\Core\PublishesFiles; -use Tempest\Console\Stubs\HttpMiddlewareStub; -use Tempest\Console\Stubs\EventBusMiddlewareStub; -use Tempest\Console\Stubs\ConsoleMiddlewareStub; - -use Tempest\Console\Stubs\CommandBusMiddlewareStub; -use Tempest\Console\Enums\MiddlewareType; -use Tempest\Console\ConsoleCommand; +use InvalidArgumentException; use Tempest\Console\ConsoleArgument; +use Tempest\Console\ConsoleCommand; +use Tempest\Console\Enums\MiddlewareType; +use Tempest\Console\Stubs\CommandBusMiddlewareStub; +use Tempest\Console\Stubs\ConsoleMiddlewareStub; +use Tempest\Console\Stubs\EventBusMiddlewareStub; +use Tempest\Console\Stubs\HttpMiddlewareStub; +use Tempest\Core\PublishesFiles; +use Tempest\Generation\DataObjects\StubFile; +use Tempest\Generation\Exceptions\FileGenerationAbortedException; +use Tempest\Generation\Exceptions\FileGenerationFailedException; -final class MakeMiddlewareCommand { +final class MakeMiddlewareCommand +{ use PublishesFiles; #[ConsoleCommand( @@ -31,14 +31,13 @@ public function __invoke( help: 'The name of the middleware class to create' )] string $className, - #[ConsoleArgument( name: 'type', help: 'The type of the middleware to create', )] MiddlewareType $middlewareType ) { - + try { $stubFile = $this->getStubFileFromMiddlewareType($middlewareType); $suggestedPath = $this->getSuggestedPath($className); @@ -52,18 +51,19 @@ public function __invoke( ); $this->success(sprintf('Middleware successfully created at "%s".', $targetPath)); - } catch (FileGenerationAbortedException|FileGenerationFailedException|\InvalidArgumentException $e) { + } catch (FileGenerationAbortedException|FileGenerationFailedException|InvalidArgumentException $e) { $this->error($e->getMessage()); } } - protected function getStubFileFromMiddlewareType(MiddlewareType $middlewareType): StubFile { + protected function getStubFileFromMiddlewareType(MiddlewareType $middlewareType): StubFile + { return match ($middlewareType) { - MiddlewareType::CONSOLE => StubFile::from( ConsoleMiddlewareStub::class ), - MiddlewareType::HTTP => StubFile::from( HttpMiddlewareStub::class ), - MiddlewareType::EVENT_BUS => StubFile::from( EventBusMiddlewareStub::class ), - MiddlewareType::COMMAND_BUS => StubFile::from( CommandBusMiddlewareStub::class ), - default => throw new \InvalidArgumentException(sprintf('The "%s" middleware type has no supported stub file.', $middlewareType->value)), // @phpstan-ignore-line Because this is a guardrail for the future implementations + MiddlewareType::CONSOLE => StubFile::from(ConsoleMiddlewareStub::class), + MiddlewareType::HTTP => StubFile::from(HttpMiddlewareStub::class), + MiddlewareType::EVENT_BUS => StubFile::from(EventBusMiddlewareStub::class), + MiddlewareType::COMMAND_BUS => StubFile::from(CommandBusMiddlewareStub::class), + default => throw new InvalidArgumentException(sprintf('The "%s" middleware type has no supported stub file.', $middlewareType->value)), // @phpstan-ignore-line Because this is a guardrail for the future implementations }; } } diff --git a/src/Tempest/Console/src/Enums/MiddlewareType.php b/src/Tempest/Console/src/Enums/MiddlewareType.php index 407d8dd0d..e102695df 100644 --- a/src/Tempest/Console/src/Enums/MiddlewareType.php +++ b/src/Tempest/Console/src/Enums/MiddlewareType.php @@ -4,15 +4,16 @@ namespace Tempest\Console\Enums; -use Tempest\Http\HttpMiddleware; -use Tempest\EventBus\EventBusMiddleware; -use Tempest\Console\ConsoleMiddleware; use Tempest\CommandBus\CommandBusMiddleware; +use Tempest\Console\ConsoleMiddleware; +use Tempest\EventBus\EventBusMiddleware; +use Tempest\Http\HttpMiddleware; /** * Represents available middleware types in Tempest. */ -enum MiddlewareType: string { +enum MiddlewareType: string +{ case CONSOLE = 'console'; case HTTP = 'http'; case EVENT_BUS = 'event-bus'; @@ -23,7 +24,8 @@ enum MiddlewareType: string { * * @return class-string */ - public function relatedInterface(): string { + public function relatedInterface(): string + { return match ($this) { self::CONSOLE => ConsoleMiddleware::class, self::HTTP => HttpMiddleware::class, diff --git a/src/Tempest/Console/src/Stubs/CommandBusMiddlewareStub.php b/src/Tempest/Console/src/Stubs/CommandBusMiddlewareStub.php index 4bfbb234e..fa672f114 100644 --- a/src/Tempest/Console/src/Stubs/CommandBusMiddlewareStub.php +++ b/src/Tempest/Console/src/Stubs/CommandBusMiddlewareStub.php @@ -7,8 +7,10 @@ use Tempest\CommandBus\CommandBusMiddleware; use Tempest\CommandBus\CommandBusMiddlewareCallable; -final class CommandBusMiddlewareStub implements CommandBusMiddleware { - public function __invoke(object $command, CommandBusMiddlewareCallable $next): void { +final class CommandBusMiddlewareStub implements CommandBusMiddleware +{ + public function __invoke(object $command, CommandBusMiddlewareCallable $next): void + { $next($command); } } diff --git a/src/Tempest/Console/src/Stubs/ConsoleMiddlewareStub.php b/src/Tempest/Console/src/Stubs/ConsoleMiddlewareStub.php index aee7c0625..192bb8b96 100644 --- a/src/Tempest/Console/src/Stubs/ConsoleMiddlewareStub.php +++ b/src/Tempest/Console/src/Stubs/ConsoleMiddlewareStub.php @@ -5,15 +5,17 @@ namespace Tempest\Console\Stubs; use Tempest\Console\ConsoleMiddleware; -use Tempest\Console\Initializers\Invocation; use Tempest\Console\ConsoleMiddlewareCallable; use Tempest\Console\ExitCode; use Tempest\Console\HasConsole; +use Tempest\Console\Initializers\Invocation; -final class ConsoleMiddlewareStub implements ConsoleMiddleware { +final class ConsoleMiddlewareStub implements ConsoleMiddleware +{ use HasConsole; - - public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next): ExitCode|int { + + public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next): ExitCode|int + { return $next($invocation); } } diff --git a/src/Tempest/Console/src/Stubs/EventBusMiddlewareStub.php b/src/Tempest/Console/src/Stubs/EventBusMiddlewareStub.php index a77429de0..7da307896 100644 --- a/src/Tempest/Console/src/Stubs/EventBusMiddlewareStub.php +++ b/src/Tempest/Console/src/Stubs/EventBusMiddlewareStub.php @@ -7,8 +7,10 @@ use Tempest\EventBus\EventBusMiddleware; use Tempest\EventBus\EventBusMiddlewareCallable; -final class EventBusMiddlewareStub implements EventBusMiddleware { - public function __invoke(object $event, EventBusMiddlewareCallable $next): void { +final class EventBusMiddlewareStub implements EventBusMiddleware +{ + public function __invoke(object $event, EventBusMiddlewareCallable $next): void + { $next($event); } } diff --git a/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php b/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php index a98b16fe6..5c00f468d 100644 --- a/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php +++ b/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php @@ -5,14 +5,16 @@ namespace Tempest\Console\Stubs; use Tempest\Http\HttpMiddleware; -use Tempest\Http\Request; use Tempest\Http\HttpMiddlewareCallable; +use Tempest\Http\Request; use Tempest\Http\Response; -final class HttpMiddlewareStub implements HttpMiddleware { - public function __invoke(Request $request, HttpMiddlewareCallable $next): Response { +final class HttpMiddlewareStub implements HttpMiddleware +{ + public function __invoke(Request $request, HttpMiddlewareCallable $next): Response + { $response = $next($request); - + return $response; } } From f9a1a4d9e79ea9965bf9bed4280b84c418cadadf Mon Sep 17 00:00:00 2001 From: Guillaume Turpin Date: Wed, 4 Dec 2024 16:13:41 +0100 Subject: [PATCH 04/11] :sparkles: Add tests --- .../Commands/MakeMiddlewareCommandTest.php | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php diff --git a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php new file mode 100644 index 000000000..da514c718 --- /dev/null +++ b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php @@ -0,0 +1,96 @@ +installer->configure( + __DIR__ . '/install', + new ComposerNamespace('App\\', __DIR__ . '/install/App') + ); + } + + protected function tearDown(): void + { + $this->installer->clean(); + + parent::tearDown(); + } + + #[Test] + #[DataProvider('command_input_provider')] + public function make_command( + string $commandArgs, + string $expectedPath, + string $expectedNamespace + ): void { + $this->console + ->call("make:middleware {$commandArgs}") + ->submit(); + + $this->installer + ->assertFileExists($expectedPath) + ->assertFileContains($expectedPath, 'namespace ' . $expectedNamespace . ';'); + } + + public static function command_input_provider(): array + { + return [ + 'make_with_defaults' => [ + 'commandArgs' => 'BookMiddleware http', + 'expectedPath' => 'App/BookMiddleware.php', + 'expectedNamespace' => 'App', + ], + 'make_with_other_namespace' => [ + 'commandArgs' => 'Middlewares\\BookMiddleware http', + 'expectedPath' => 'App/Middlewares/BookMiddleware.php', + 'expectedNamespace' => 'App\\Middlewares', + ], + 'make_with_input_path' => [ + 'commandArgs' => 'Middlewares/BookMiddleware http', + 'expectedPath' => 'App/Middlewares/BookMiddleware.php', + 'expectedNamespace' => 'App\\Middlewares', + ], + ]; + } + + #[Test] + #[DataProvider('middleware_type_provider')] + public function make_command_with_each_type( + MiddlewareType $middlewareType, + string $middlewareInterface + ): void { + $this->console + ->call("make:middelware TestMiddleware {$middlewareType->value}") + ->submit(); + + $filepath = 'App/TestMiddleware.php'; + $this->installer + ->assertFileExists($filepath) + ->assertFileContains($filepath, 'implements ' . $middlewareInterface); + } + + public static function middleware_type_provider(): array { + $cases = MiddlewareType::cases(); + + return array_combine( + keys: array_map(fn ( MiddlewareType $case ) => $case->value, $cases), + values: array_map(fn( MiddlewareType $case) => [ + 'middlewareType' => $case, + 'middlewareInterface' => $case->relatedInterface() + ], $cases) + ); + } +} From b2c6c64cfd51676d49ddcbb7098a72d635207867 Mon Sep 17 00:00:00 2001 From: Guillaume Turpin Date: Wed, 4 Dec 2024 16:18:33 +0100 Subject: [PATCH 05/11] :art: Coding styles --- .../Commands/MakeMiddlewareCommandTest.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php index da514c718..8b3173994 100644 --- a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php +++ b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php @@ -4,12 +4,15 @@ namespace Tests\Tempest\Integration\Console\Commands; -use Tests\Tempest\Integration\FrameworkIntegrationTestCase; -use Tempest\Core\ComposerNamespace; -use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Tempest\Console\Enums\MiddlewareType; +use Tempest\Core\ComposerNamespace; +use Tests\Tempest\Integration\FrameworkIntegrationTestCase; +/** + * @internal + */ final class MakeMiddlewareCommandTest extends FrameworkIntegrationTestCase { protected function setUp(): void @@ -75,21 +78,22 @@ public function make_command_with_each_type( $this->console ->call("make:middelware TestMiddleware {$middlewareType->value}") ->submit(); - + $filepath = 'App/TestMiddleware.php'; $this->installer ->assertFileExists($filepath) ->assertFileContains($filepath, 'implements ' . $middlewareInterface); } - public static function middleware_type_provider(): array { + public static function middleware_type_provider(): array + { $cases = MiddlewareType::cases(); return array_combine( - keys: array_map(fn ( MiddlewareType $case ) => $case->value, $cases), - values: array_map(fn( MiddlewareType $case) => [ + keys: array_map(fn (MiddlewareType $case) => $case->value, $cases), + values: array_map(fn (MiddlewareType $case) => [ 'middlewareType' => $case, - 'middlewareInterface' => $case->relatedInterface() + 'middlewareInterface' => $case->relatedInterface(), ], $cases) ); } From b39867b6e7c73719b03fb0b02590256af04ad422 Mon Sep 17 00:00:00 2001 From: Guillaume Turpin Date: Wed, 4 Dec 2024 16:19:49 +0100 Subject: [PATCH 06/11] :rotating_light: Run rector --- src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php | 5 ++--- src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php index 81fa7288e..f9d0ca5e0 100644 --- a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php +++ b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php @@ -36,8 +36,7 @@ public function __invoke( help: 'The type of the middleware to create', )] MiddlewareType $middlewareType - ) { - + ): void { try { $stubFile = $this->getStubFileFromMiddlewareType($middlewareType); $suggestedPath = $this->getSuggestedPath($className); @@ -56,7 +55,7 @@ public function __invoke( } } - protected function getStubFileFromMiddlewareType(MiddlewareType $middlewareType): StubFile + private function getStubFileFromMiddlewareType(MiddlewareType $middlewareType): StubFile { return match ($middlewareType) { MiddlewareType::CONSOLE => StubFile::from(ConsoleMiddlewareStub::class), diff --git a/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php b/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php index 5c00f468d..03cbaa6e4 100644 --- a/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php +++ b/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php @@ -13,8 +13,6 @@ final class HttpMiddlewareStub implements HttpMiddleware { public function __invoke(Request $request, HttpMiddlewareCallable $next): Response { - $response = $next($request); - - return $response; + return $next($request); } } From 30d08357abdb864fc5ae9aa61cae1e68b5340fb6 Mon Sep 17 00:00:00 2001 From: Guillaume Turpin Date: Tue, 10 Dec 2024 17:16:15 +0100 Subject: [PATCH 07/11] :art: Coding styles --- .../Console/src/Commands/MakeMiddlewareCommand.php | 6 +++--- .../Console/Commands/MakeMiddlewareCommandTest.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php index f9d0ca5e0..963c312a9 100644 --- a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php +++ b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php @@ -24,18 +24,18 @@ final class MakeMiddlewareCommand #[ConsoleCommand( name: 'make:middleware', description: 'Creates a new middleware class', - aliases: ['middleware:make', 'middleware:create', 'create:middleware'] + aliases: ['middleware:make', 'middleware:create', 'create:middleware'], )] public function __invoke( #[ConsoleArgument( - help: 'The name of the middleware class to create' + help: 'The name of the middleware class to create', )] string $className, #[ConsoleArgument( name: 'type', help: 'The type of the middleware to create', )] - MiddlewareType $middlewareType + MiddlewareType $middlewareType, ): void { try { $stubFile = $this->getStubFileFromMiddlewareType($middlewareType); diff --git a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php index 8b3173994..018bcbe82 100644 --- a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php +++ b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php @@ -21,7 +21,7 @@ protected function setUp(): void $this->installer->configure( __DIR__ . '/install', - new ComposerNamespace('App\\', __DIR__ . '/install/App') + new ComposerNamespace('App\\', __DIR__ . '/install/App'), ); } @@ -32,12 +32,12 @@ protected function tearDown(): void parent::tearDown(); } - #[Test] #[DataProvider('command_input_provider')] + #[Test] public function make_command( string $commandArgs, string $expectedPath, - string $expectedNamespace + string $expectedNamespace, ): void { $this->console ->call("make:middleware {$commandArgs}") @@ -69,11 +69,11 @@ public static function command_input_provider(): array ]; } - #[Test] #[DataProvider('middleware_type_provider')] + #[Test] public function make_command_with_each_type( MiddlewareType $middlewareType, - string $middlewareInterface + string $middlewareInterface, ): void { $this->console ->call("make:middelware TestMiddleware {$middlewareType->value}") @@ -94,7 +94,7 @@ public static function middleware_type_provider(): array values: array_map(fn (MiddlewareType $case) => [ 'middlewareType' => $case, 'middlewareInterface' => $case->relatedInterface(), - ], $cases) + ], $cases), ); } } From 1cb22b345fc2bfeaa37f42a243db17b4b5baccea Mon Sep 17 00:00:00 2001 From: Guillaume Turpin Date: Tue, 10 Dec 2024 17:49:04 +0100 Subject: [PATCH 08/11] :art: Update Router components namespaces --- src/Tempest/Console/src/Enums/MiddlewareType.php | 6 +++--- src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Tempest/Console/src/Enums/MiddlewareType.php b/src/Tempest/Console/src/Enums/MiddlewareType.php index e102695df..11e2c9fbb 100644 --- a/src/Tempest/Console/src/Enums/MiddlewareType.php +++ b/src/Tempest/Console/src/Enums/MiddlewareType.php @@ -4,10 +4,10 @@ namespace Tempest\Console\Enums; -use Tempest\CommandBus\CommandBusMiddleware; -use Tempest\Console\ConsoleMiddleware; +use Tempest\Router\HttpMiddleware; use Tempest\EventBus\EventBusMiddleware; -use Tempest\Http\HttpMiddleware; +use Tempest\Console\ConsoleMiddleware; +use Tempest\CommandBus\CommandBusMiddleware; /** * Represents available middleware types in Tempest. diff --git a/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php b/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php index 03cbaa6e4..1a77c5be3 100644 --- a/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php +++ b/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php @@ -4,10 +4,10 @@ namespace Tempest\Console\Stubs; -use Tempest\Http\HttpMiddleware; -use Tempest\Http\HttpMiddlewareCallable; -use Tempest\Http\Request; -use Tempest\Http\Response; +use Tempest\Router\Response; +use Tempest\Router\Request; +use Tempest\Router\HttpMiddlewareCallable; +use Tempest\Router\HttpMiddleware; final class HttpMiddlewareStub implements HttpMiddleware { From 2a00da042f34af0871110dc2c6f456eb8d123778 Mon Sep 17 00:00:00 2001 From: Guillaume Turpin Date: Tue, 10 Dec 2024 17:49:45 +0100 Subject: [PATCH 09/11] :white_check_mark: Fix tests --- .../Console/Commands/MakeMiddlewareCommandTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php index 018bcbe82..045d6e44a 100644 --- a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php +++ b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php @@ -10,6 +10,8 @@ use Tempest\Core\ComposerNamespace; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; +use function Tempest\Support\str; + /** * @internal */ @@ -76,10 +78,11 @@ public function make_command_with_each_type( string $middlewareInterface, ): void { $this->console - ->call("make:middelware TestMiddleware {$middlewareType->value}") + ->call("make:middleware TestMiddleware {$middlewareType->value}") ->submit(); $filepath = 'App/TestMiddleware.php'; + $middlewareInterface = str($middlewareInterface)->classBasename()->toString(); $this->installer ->assertFileExists($filepath) ->assertFileContains($filepath, 'implements ' . $middlewareInterface); From 9ed835aa6dfb6119c0253a9393910079e572d124 Mon Sep 17 00:00:00 2001 From: Guillaume Turpin Date: Tue, 10 Dec 2024 17:54:16 +0100 Subject: [PATCH 10/11] :art: Coding styles --- src/Tempest/Console/src/Enums/MiddlewareType.php | 6 +++--- src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php | 6 +++--- .../Console/Commands/MakeMiddlewareCommandTest.php | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Tempest/Console/src/Enums/MiddlewareType.php b/src/Tempest/Console/src/Enums/MiddlewareType.php index 11e2c9fbb..d3ebc1e05 100644 --- a/src/Tempest/Console/src/Enums/MiddlewareType.php +++ b/src/Tempest/Console/src/Enums/MiddlewareType.php @@ -4,10 +4,10 @@ namespace Tempest\Console\Enums; -use Tempest\Router\HttpMiddleware; -use Tempest\EventBus\EventBusMiddleware; -use Tempest\Console\ConsoleMiddleware; use Tempest\CommandBus\CommandBusMiddleware; +use Tempest\Console\ConsoleMiddleware; +use Tempest\EventBus\EventBusMiddleware; +use Tempest\Router\HttpMiddleware; /** * Represents available middleware types in Tempest. diff --git a/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php b/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php index 1a77c5be3..55995ec50 100644 --- a/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php +++ b/src/Tempest/Console/src/Stubs/HttpMiddlewareStub.php @@ -4,10 +4,10 @@ namespace Tempest\Console\Stubs; -use Tempest\Router\Response; -use Tempest\Router\Request; -use Tempest\Router\HttpMiddlewareCallable; use Tempest\Router\HttpMiddleware; +use Tempest\Router\HttpMiddlewareCallable; +use Tempest\Router\Request; +use Tempest\Router\Response; final class HttpMiddlewareStub implements HttpMiddleware { diff --git a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php index 045d6e44a..ce6597758 100644 --- a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php +++ b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php @@ -9,7 +9,6 @@ use Tempest\Console\Enums\MiddlewareType; use Tempest\Core\ComposerNamespace; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; - use function Tempest\Support\str; /** From 763b6c6b4cbd976125d741dfba0552409f325754 Mon Sep 17 00:00:00 2001 From: Guillaume Turpin Date: Wed, 11 Dec 2024 08:56:47 +0100 Subject: [PATCH 11/11] :rotating_light: Fix phpstan --- src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php index 963c312a9..df5d57d5c 100644 --- a/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php +++ b/src/Tempest/Console/src/Commands/MakeMiddlewareCommand.php @@ -61,8 +61,8 @@ private function getStubFileFromMiddlewareType(MiddlewareType $middlewareType): MiddlewareType::CONSOLE => StubFile::from(ConsoleMiddlewareStub::class), MiddlewareType::HTTP => StubFile::from(HttpMiddlewareStub::class), MiddlewareType::EVENT_BUS => StubFile::from(EventBusMiddlewareStub::class), - MiddlewareType::COMMAND_BUS => StubFile::from(CommandBusMiddlewareStub::class), - default => throw new InvalidArgumentException(sprintf('The "%s" middleware type has no supported stub file.', $middlewareType->value)), // @phpstan-ignore-line Because this is a guardrail for the future implementations + MiddlewareType::COMMAND_BUS => StubFile::from(CommandBusMiddlewareStub::class), // @phpstan-ignore match.alwaysTrue (Because this is a guardrail for the future implementations) + default => throw new InvalidArgumentException(sprintf('The "%s" middleware type has no supported stub file.', $middlewareType->value)), }; } }