diff --git a/src/Tempest/Http/src/Commands/MakeRequestCommand.php b/src/Tempest/Http/src/Commands/MakeRequestCommand.php new file mode 100644 index 000000000..ee8907269 --- /dev/null +++ b/src/Tempest/Http/src/Commands/MakeRequestCommand.php @@ -0,0 +1,46 @@ +getSuggestedPath($className); + $targetPath = $this->promptTargetPath($suggestedPath); + $shouldOverride = $this->askForOverride($targetPath); + + try { + $this->stubFileGenerator->generateClassFile( + stubFile: StubFile::from(RequestStub::class), + targetPath: $targetPath, + shouldOverride: $shouldOverride, + ); + + $this->success(sprintf('Request successfully created at "%s".', $targetPath)); + } catch (FileGenerationAbortedException|FileGenerationFailedException $e) { + $this->error($e->getMessage()); + } + } +} diff --git a/src/Tempest/Http/src/Stubs/RequestStub.php b/src/Tempest/Http/src/Stubs/RequestStub.php new file mode 100644 index 000000000..6b598b8e6 --- /dev/null +++ b/src/Tempest/Http/src/Stubs/RequestStub.php @@ -0,0 +1,17 @@ +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:request {$commandArgs}") + ->submit(); + + $this->installer + ->assertFileExists($expectedPath) + ->assertFileContains($expectedPath, 'namespace ' . $expectedNamespace . ';'); + } + + public static function command_input_provider(): array + { + return [ + 'make_with_defaults' => [ + 'commandArgs' => 'BookRequest', + 'expectedPath' => 'App/BookRequest.php', + 'expectedNamespace' => 'App', + ], + 'make_with_other_namespace' => [ + 'commandArgs' => 'Requests\\BookRequest', + 'expectedPath' => 'App/Requests/BookRequest.php', + 'expectedNamespace' => 'App\\Requests', + ], + 'make_with_input_path' => [ + 'commandArgs' => 'Requests/BookRequest', + 'expectedPath' => 'App/Requests/BookRequest.php', + 'expectedNamespace' => 'App\\Requests', + ], + ]; + } +}