diff --git a/src/CrudApiMake.php b/src/CrudApiMake.php index c9289cc..166331b 100644 --- a/src/CrudApiMake.php +++ b/src/CrudApiMake.php @@ -96,7 +96,7 @@ class CrudApiMake extends GeneratorCommand */ public function generateRoutes() { - app('Luthfi\CrudGenerator\Generators\WebRouteGenerator', ['command' => $this])->generate(); + app('Luthfi\CrudGenerator\Generators\RouteGenerator', ['command' => $this])->generate('api'); } /** diff --git a/src/CrudMake.php b/src/CrudMake.php index 6a7b3db..8d0f704 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -96,7 +96,7 @@ class CrudMake extends GeneratorCommand */ public function generateRoutes() { - app('Luthfi\CrudGenerator\Generators\WebRouteGenerator', ['command' => $this])->generate(); + app('Luthfi\CrudGenerator\Generators\RouteGenerator', ['command' => $this])->generate(); } /** diff --git a/src/CrudSimpleMake.php b/src/CrudSimpleMake.php index 35b3543..3521dfc 100644 --- a/src/CrudSimpleMake.php +++ b/src/CrudSimpleMake.php @@ -96,7 +96,7 @@ class CrudSimpleMake extends GeneratorCommand */ public function generateRoutes() { - app('Luthfi\CrudGenerator\Generators\WebRouteGenerator', ['command' => $this])->generate(); + app('Luthfi\CrudGenerator\Generators\RouteGenerator', ['command' => $this])->generate(); } /** diff --git a/src/Generators/WebRouteGenerator.php b/src/Generators/RouteGenerator.php similarity index 88% rename from src/Generators/WebRouteGenerator.php rename to src/Generators/RouteGenerator.php index 2383f4d..95a0476 100644 --- a/src/Generators/WebRouteGenerator.php +++ b/src/Generators/RouteGenerator.php @@ -3,20 +3,20 @@ namespace Luthfi\CrudGenerator\Generators; /** - * Web Route Generator Class + * Route Generator Class */ -class WebRouteGenerator extends BaseGenerator +class RouteGenerator extends BaseGenerator { /** * {@inheritDoc} */ - public function generate(string $type = 'full') + public function generate(string $type = 'web') { - $webRoutePath = $this->makeRouteFile(base_path('routes'), 'web.php'); + $webRoutePath = $this->makeRouteFile(base_path('routes'), $type.'.php'); - $this->files->append($webRoutePath, $this->getContent('route-web')); + $this->files->append($webRoutePath, $this->getContent('route-'.$type)); - $this->command->info($this->modelNames['model_name'].' resource route generated on routes/web.php.'); + $this->command->info($this->modelNames['model_name'].' resource route generated on routes/'.$type.'.php.'); } /** diff --git a/src/stubs/route-api.stub b/src/stubs/route-api.stub new file mode 100644 index 0000000..a14f14b --- /dev/null +++ b/src/stubs/route-api.stub @@ -0,0 +1,2 @@ + +Route::resource('masters', 'MastersController'); diff --git a/tests/CrudApiMakeCommandTest.php b/tests/CrudApiMakeCommandTest.php index bdcf21b..f2e0474 100644 --- a/tests/CrudApiMakeCommandTest.php +++ b/tests/CrudApiMakeCommandTest.php @@ -25,7 +25,7 @@ class CrudApiMakeCommandTest extends TestCase $localeConfig = config('app.locale'); $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); - $this->assertFileExists(base_path("routes/web.php")); + $this->assertFileExists(base_path("routes/api.php")); $this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php")); $this->assertFileExists(database_path("factories/{$this->model_name}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$this->model_name}Test.php")); diff --git a/tests/Generators/Api/RouteApiGeneratorTest.php b/tests/Generators/Api/RouteApiGeneratorTest.php new file mode 100644 index 0000000..1a164e1 --- /dev/null +++ b/tests/Generators/Api/RouteApiGeneratorTest.php @@ -0,0 +1,36 @@ +artisan('make:crud-api', ['name' => $this->model_name, '--no-interaction' => true]); + + $routeApiPath = base_path('routes/api.php'); + $this->assertFileExists($routeApiPath); + $routeApiFileContent = "table_name}', '{$this->plural_model_name}Controller'); +"; + $this->assertEquals($routeApiFileContent, file_get_contents($routeApiPath)); + } + + /** @test */ + public function it_creates_correct_api_route_content_with_parent_command_option() + { + $this->artisan('make:crud-api', ['name' => $this->model_name, '--parent' => 'Projects', '--no-interaction' => true]); + + $routeApiPath = base_path('routes/api.php'); + $this->assertFileExists($routeApiPath); + $routeApiFileContent = "table_name}', 'Projects\\{$this->plural_model_name}Controller'); +"; + $this->assertEquals($routeApiFileContent, file_get_contents($routeApiPath)); + } +}