From d62e06f3c106918bc3707b96435c3cc0c07fc26d Mon Sep 17 00:00:00 2001 From: Ozair Patel Date: Thu, 25 Jan 2018 11:00:04 -0600 Subject: [PATCH 1/9] Writes `.api` stubs --- .../Routing/Console/stubs/controller.api.stub | 64 +++++++++++++++++ .../Console/stubs/controller.model.api.stub | 65 +++++++++++++++++ .../Console/stubs/controller.nested.api.stub | 71 +++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 src/Illuminate/Routing/Console/stubs/controller.api.stub create mode 100644 src/Illuminate/Routing/Console/stubs/controller.model.api.stub create mode 100644 src/Illuminate/Routing/Console/stubs/controller.nested.api.stub diff --git a/src/Illuminate/Routing/Console/stubs/controller.api.stub b/src/Illuminate/Routing/Console/stubs/controller.api.stub new file mode 100644 index 000000000000..e11e43af6e6a --- /dev/null +++ b/src/Illuminate/Routing/Console/stubs/controller.api.stub @@ -0,0 +1,64 @@ + Date: Thu, 25 Jan 2018 11:00:09 -0600 Subject: [PATCH 2/9] Updates ControllerMakeCommand to support --api flag --- .../Routing/Console/ControllerMakeCommand.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/Console/ControllerMakeCommand.php b/src/Illuminate/Routing/Console/ControllerMakeCommand.php index 4ce15afd985a..448254c8d737 100755 --- a/src/Illuminate/Routing/Console/ControllerMakeCommand.php +++ b/src/Illuminate/Routing/Console/ControllerMakeCommand.php @@ -37,6 +37,8 @@ class ControllerMakeCommand extends GeneratorCommand */ protected function getStub() { + $stub = null; + if ($this->option('parent')) { return __DIR__.'/stubs/controller.nested.stub'; } elseif ($this->option('model')) { @@ -45,7 +47,13 @@ protected function getStub() return __DIR__.'/stubs/controller.stub'; } - return __DIR__.'/stubs/controller.plain.stub'; + if ($this->option('api') && $stub !== null) { + $stub = substr_replace($stub, '.api', -5, 0); + } + + $stub = $stub ?? __DIR__.'/stubs/controller.plain.stub'; + + return $stub; } /** From 4c0474dafc6b2175163434be713fcbcc2ec006c3 Mon Sep 17 00:00:00 2001 From: Ozair Patel Date: Thu, 25 Jan 2018 11:32:20 -0600 Subject: [PATCH 3/9] Adds --api flag to command options --- src/Illuminate/Routing/Console/ControllerMakeCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Illuminate/Routing/Console/ControllerMakeCommand.php b/src/Illuminate/Routing/Console/ControllerMakeCommand.php index 448254c8d737..b5e8ff8875c5 100755 --- a/src/Illuminate/Routing/Console/ControllerMakeCommand.php +++ b/src/Illuminate/Routing/Console/ControllerMakeCommand.php @@ -175,6 +175,8 @@ protected function getOptions() ['resource', 'r', InputOption::VALUE_NONE, 'Generate a resource controller class.'], ['parent', 'p', InputOption::VALUE_OPTIONAL, 'Generate a nested resource controller class.'], + + ['api', 'a', InputOption::VALUE_OPTIONAL, 'Generate a api resource controller class.'], ]; } } From ad819889ae20c1153458a1f79826b8f74c10a736 Mon Sep 17 00:00:00 2001 From: Ozair Patel Date: Wed, 31 Jan 2018 16:53:19 -0600 Subject: [PATCH 4/9] Prevents early return from #getStub, and sets command param to none --- .../Routing/Console/ControllerMakeCommand.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Routing/Console/ControllerMakeCommand.php b/src/Illuminate/Routing/Console/ControllerMakeCommand.php index b5e8ff8875c5..8fb0884e6aa7 100755 --- a/src/Illuminate/Routing/Console/ControllerMakeCommand.php +++ b/src/Illuminate/Routing/Console/ControllerMakeCommand.php @@ -40,20 +40,20 @@ protected function getStub() $stub = null; if ($this->option('parent')) { - return __DIR__.'/stubs/controller.nested.stub'; + $stub = '/stubs/controller.nested.stub'; } elseif ($this->option('model')) { - return __DIR__.'/stubs/controller.model.stub'; + $stub = '/stubs/controller.model.stub'; } elseif ($this->option('resource')) { - return __DIR__.'/stubs/controller.stub'; + $stub = '/stubs/controller.stub'; } if ($this->option('api') && $stub !== null) { $stub = substr_replace($stub, '.api', -5, 0); } - $stub = $stub ?? __DIR__.'/stubs/controller.plain.stub'; + $stub = $stub ?? '/stubs/controller.plain.stub'; - return $stub; + return __DIR__ . $stub; } /** @@ -176,7 +176,7 @@ protected function getOptions() ['parent', 'p', InputOption::VALUE_OPTIONAL, 'Generate a nested resource controller class.'], - ['api', 'a', InputOption::VALUE_OPTIONAL, 'Generate a api resource controller class.'], + ['api', 'a', InputOption::VALUE_NONE, 'Generate a api resource controller class.'], ]; } } From e86d957529ff4b05be2d1de11a5bb3552e85061b Mon Sep 17 00:00:00 2001 From: Ozair Patel Date: Wed, 31 Jan 2018 16:57:46 -0600 Subject: [PATCH 5/9] Updates description of --api option --- src/Illuminate/Routing/Console/ControllerMakeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/Console/ControllerMakeCommand.php b/src/Illuminate/Routing/Console/ControllerMakeCommand.php index 8fb0884e6aa7..dc685b068a85 100755 --- a/src/Illuminate/Routing/Console/ControllerMakeCommand.php +++ b/src/Illuminate/Routing/Console/ControllerMakeCommand.php @@ -176,7 +176,7 @@ protected function getOptions() ['parent', 'p', InputOption::VALUE_OPTIONAL, 'Generate a nested resource controller class.'], - ['api', 'a', InputOption::VALUE_NONE, 'Generate a api resource controller class.'], + ['api', 'a', InputOption::VALUE_NONE, 'Generate api resource methods only for a controller class.'], ]; } } From cb417e734da45dc2f9f54beaf8ab2e431f17022b Mon Sep 17 00:00:00 2001 From: Ozair Patel Date: Thu, 1 Feb 2018 22:22:16 -0600 Subject: [PATCH 6/9] Writes ControllerMakeCommand integration test --- .../APIResourceController.php.assertion | 63 ++++++++++ .../Assertions/BasicController.php.assertion | 10 ++ .../BasicResourceController.php.assertion | 84 +++++++++++++ .../ParentResourceController.php.assertion | 93 ++++++++++++++ .../Console/ControllerMakeCommandTest.php | 117 ++++++++++++++++++ 5 files changed, 367 insertions(+) create mode 100644 tests/Integration/Routing/Console/Assertions/APIResourceController.php.assertion create mode 100644 tests/Integration/Routing/Console/Assertions/BasicController.php.assertion create mode 100644 tests/Integration/Routing/Console/Assertions/BasicResourceController.php.assertion create mode 100644 tests/Integration/Routing/Console/Assertions/ParentResourceController.php.assertion create mode 100644 tests/Integration/Routing/Console/ControllerMakeCommandTest.php diff --git a/tests/Integration/Routing/Console/Assertions/APIResourceController.php.assertion b/tests/Integration/Routing/Console/Assertions/APIResourceController.php.assertion new file mode 100644 index 000000000000..c64898468c5d --- /dev/null +++ b/tests/Integration/Routing/Console/Assertions/APIResourceController.php.assertion @@ -0,0 +1,63 @@ +controllerPath = $this->app->basePath('app/Http/Controllers'); + $this->fs = new Filesystem; + } + + /** + * Assert the contents of two files equal each other + * + * @param string $assertingFile + * @param string $assertingAgainst + * + * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException + */ + protected function assertFileContents (string $assertingFile, string $assertingAgainst) + { + $this->assertEquals($this->fs->get($assertingFile), $this->fs->get($assertingAgainst)); + } + + /** + * @test + */ + public function test_basic_controller_make_command () + { + $assertingFile = $this->controllerPath . '/BasicController.php'; + $assertingAgainst = __DIR__ . '/Assertions/BasicController.php.assertion'; + + $this->artisan('make:controller', [ + 'name' => 'BasicController', + '--no-interaction' => TRUE + ]); + + $this->assertFileContents($assertingFile, $assertingAgainst); + $this->fs->delete($assertingFile); + } + + /** + * @test + */ + public function test_basic_resource_controller_make_command () + { + $assertingFile = $this->controllerPath . '/BasicResourceController.php'; + $assertingAgainst = __DIR__ . '/Assertions/BasicResourceController.php.assertion'; + + $this->artisan('make:controller', [ + 'name' => 'BasicResourceController', + '--resource' => TRUE, + '--no-interaction' => TRUE + ]); + + $this->assertFileContents($assertingFile, $assertingAgainst); + $this->fs->delete($assertingFile); + } + + /** + * @test + */ + public function test_parent_resource_controller_make_command () + { + $assertingFile = $this->controllerPath . '/ParentResourceController.php'; + $assertingAgainst = __DIR__ . '/Assertions/ParentResourceController.php.assertion'; + + $this->artisan('make:controller', [ + 'name' => 'ParentResourceController', + '--resource' => TRUE, + '--parent' => 'BasicResourceController', + '--no-interaction' => TRUE + ]); + + $this->assertFileContents($assertingFile, $assertingAgainst); + $this->fs->delete($assertingFile); + } + + /** + * @test + */ + public function test_api_resource_controller_make_command () + { + $assertingFile = $this->controllerPath . '/APIResourceController.php'; + $assertingAgainst = __DIR__ . '/Assertions/APIResourceController.php.assertion'; + + $this->artisan('make:controller', [ + 'name' => 'APIResourceController', + '--resource' => TRUE, + '--api' => TRUE, + '--no-interaction' => TRUE + ]); + + $this->assertFileContents($assertingFile, $assertingAgainst); + $this->fs->delete($assertingFile); + } + +} From 2cfee68c82cf432746427978a502b0f93ee6bc3c Mon Sep 17 00:00:00 2001 From: Ozair Patel Date: Thu, 1 Feb 2018 22:35:58 -0600 Subject: [PATCH 7/9] Adds test for both `--api` and `--parent` flag --- .../ParentAPIResourceController.php.assertion | 70 +++++++++++++++++++ .../Console/ControllerMakeCommandTest.php | 20 ++++++ 2 files changed, 90 insertions(+) create mode 100644 tests/Integration/Routing/Console/Assertions/ParentAPIResourceController.php.assertion diff --git a/tests/Integration/Routing/Console/Assertions/ParentAPIResourceController.php.assertion b/tests/Integration/Routing/Console/Assertions/ParentAPIResourceController.php.assertion new file mode 100644 index 000000000000..d9c76d3aa347 --- /dev/null +++ b/tests/Integration/Routing/Console/Assertions/ParentAPIResourceController.php.assertion @@ -0,0 +1,70 @@ +fs->delete($assertingFile); } + /** + * @test + */ + public function test_parent_api_resource_controller_make_command () + { + $assertingFile = $this->controllerPath . '/ParentAPIResourceController.php'; + $assertingAgainst = __DIR__ . '/Assertions/ParentAPIResourceController.php.assertion'; + + $this->artisan('make:controller', [ + 'name' => 'ParentAPIResourceController', + '--resource' => TRUE, + '--api' => TRUE, + '--parent' => 'BasicController', + '--no-interaction' => TRUE + ]); + + $this->assertFileContents($assertingFile, $assertingAgainst); + $this->fs->delete($assertingFile); + } + } From 7bcba219add05e3e1796db64b86ba0380a303e75 Mon Sep 17 00:00:00 2001 From: Ozair Patel Date: Fri, 2 Feb 2018 19:12:00 -0600 Subject: [PATCH 8/9] Removes artisan make:controller tests --- .../APIResourceController.php.assertion | 63 -------- .../Assertions/BasicController.php.assertion | 10 -- .../BasicResourceController.php.assertion | 84 ----------- .../ParentAPIResourceController.php.assertion | 70 --------- .../ParentResourceController.php.assertion | 93 ------------ .../Console/ControllerMakeCommandTest.php | 137 ------------------ 6 files changed, 457 deletions(-) delete mode 100644 tests/Integration/Routing/Console/Assertions/APIResourceController.php.assertion delete mode 100644 tests/Integration/Routing/Console/Assertions/BasicController.php.assertion delete mode 100644 tests/Integration/Routing/Console/Assertions/BasicResourceController.php.assertion delete mode 100644 tests/Integration/Routing/Console/Assertions/ParentAPIResourceController.php.assertion delete mode 100644 tests/Integration/Routing/Console/Assertions/ParentResourceController.php.assertion delete mode 100644 tests/Integration/Routing/Console/ControllerMakeCommandTest.php diff --git a/tests/Integration/Routing/Console/Assertions/APIResourceController.php.assertion b/tests/Integration/Routing/Console/Assertions/APIResourceController.php.assertion deleted file mode 100644 index c64898468c5d..000000000000 --- a/tests/Integration/Routing/Console/Assertions/APIResourceController.php.assertion +++ /dev/null @@ -1,63 +0,0 @@ -controllerPath = $this->app->basePath('app/Http/Controllers'); - $this->fs = new Filesystem; - } - - /** - * Assert the contents of two files equal each other - * - * @param string $assertingFile - * @param string $assertingAgainst - * - * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException - */ - protected function assertFileContents (string $assertingFile, string $assertingAgainst) - { - $this->assertEquals($this->fs->get($assertingFile), $this->fs->get($assertingAgainst)); - } - - /** - * @test - */ - public function test_basic_controller_make_command () - { - $assertingFile = $this->controllerPath . '/BasicController.php'; - $assertingAgainst = __DIR__ . '/Assertions/BasicController.php.assertion'; - - $this->artisan('make:controller', [ - 'name' => 'BasicController', - '--no-interaction' => TRUE - ]); - - $this->assertFileContents($assertingFile, $assertingAgainst); - $this->fs->delete($assertingFile); - } - - /** - * @test - */ - public function test_basic_resource_controller_make_command () - { - $assertingFile = $this->controllerPath . '/BasicResourceController.php'; - $assertingAgainst = __DIR__ . '/Assertions/BasicResourceController.php.assertion'; - - $this->artisan('make:controller', [ - 'name' => 'BasicResourceController', - '--resource' => TRUE, - '--no-interaction' => TRUE - ]); - - $this->assertFileContents($assertingFile, $assertingAgainst); - $this->fs->delete($assertingFile); - } - - /** - * @test - */ - public function test_parent_resource_controller_make_command () - { - $assertingFile = $this->controllerPath . '/ParentResourceController.php'; - $assertingAgainst = __DIR__ . '/Assertions/ParentResourceController.php.assertion'; - - $this->artisan('make:controller', [ - 'name' => 'ParentResourceController', - '--resource' => TRUE, - '--parent' => 'BasicResourceController', - '--no-interaction' => TRUE - ]); - - $this->assertFileContents($assertingFile, $assertingAgainst); - $this->fs->delete($assertingFile); - } - - /** - * @test - */ - public function test_api_resource_controller_make_command () - { - $assertingFile = $this->controllerPath . '/APIResourceController.php'; - $assertingAgainst = __DIR__ . '/Assertions/APIResourceController.php.assertion'; - - $this->artisan('make:controller', [ - 'name' => 'APIResourceController', - '--resource' => TRUE, - '--api' => TRUE, - '--no-interaction' => TRUE - ]); - - $this->assertFileContents($assertingFile, $assertingAgainst); - $this->fs->delete($assertingFile); - } - - /** - * @test - */ - public function test_parent_api_resource_controller_make_command () - { - $assertingFile = $this->controllerPath . '/ParentAPIResourceController.php'; - $assertingAgainst = __DIR__ . '/Assertions/ParentAPIResourceController.php.assertion'; - - $this->artisan('make:controller', [ - 'name' => 'ParentAPIResourceController', - '--resource' => TRUE, - '--api' => TRUE, - '--parent' => 'BasicController', - '--no-interaction' => TRUE - ]); - - $this->assertFileContents($assertingFile, $assertingAgainst); - $this->fs->delete($assertingFile); - } - -} From 8628885c6223f84f6d9fa93e9cce661335fdce85 Mon Sep 17 00:00:00 2001 From: Ozair Patel Date: Fri, 2 Feb 2018 19:17:51 -0600 Subject: [PATCH 9/9] Updates code style on ControllerMakeCommand --- src/Illuminate/Routing/Console/ControllerMakeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/Console/ControllerMakeCommand.php b/src/Illuminate/Routing/Console/ControllerMakeCommand.php index dc685b068a85..7866d8e75da4 100755 --- a/src/Illuminate/Routing/Console/ControllerMakeCommand.php +++ b/src/Illuminate/Routing/Console/ControllerMakeCommand.php @@ -53,7 +53,7 @@ protected function getStub() $stub = $stub ?? '/stubs/controller.plain.stub'; - return __DIR__ . $stub; + return __DIR__.$stub; } /**