diff --git a/src/CrudMake.php b/src/CrudMake.php index 41ed901..16e7a75 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -43,6 +43,7 @@ class CrudMake extends Command public function handle() { $this->getModelName(); + $this->generateResourceRoute(); $this->generateModel(); $this->generateMigration(); @@ -130,6 +131,13 @@ class CrudMake extends Command $this->info($this->modelName.'Test (model) generated.'); } + public function generateResourceRoute() + { + $webRoutePath = $this->makeRouteFile(base_path('routes'), 'web.php'); + $this->files->append($webRoutePath, $this->getWebRouteContent()); + $this->info($this->modelName.' resource route generated on routes/web.php.'); + } + public function getControllerContent() { $stub = $this->files->get(__DIR__.'/stubs/controller.model.stub'); @@ -178,6 +186,12 @@ class CrudMake extends Command return $this->replaceUnitTestDummyStrings($stub)->replaceClass($stub); } + public function getWebRouteContent() + { + $stub = $this->files->get(__DIR__.'/stubs/route-web.stub'); + return $this->replaceViewDummyStrings($stub)->replaceClass($stub); + } + protected function makeDirectory($path) { if (! $this->files->isDirectory($path)) { @@ -187,6 +201,19 @@ class CrudMake extends Command return $path; } + protected function makeRouteFile($routeDirPath, $filename) + { + if (! $this->files->isDirectory($routeDirPath)) { + $this->files->makeDirectory($routeDirPath, 0777, true, true); + } + + if (! $this->files->exists($routeDirPath.'/'.$filename)) { + $this->files->put($routeDirPath.'/'.$filename, "assertFileExists(resource_path("views/{$this->tableName}/forms.blade.php")); $this->assertFileExists(resource_path("lang/en/{$this->singleModelName}.php")); $this->assertFileExists(database_path("factories/{$this->modelName}Factory.php")); + $this->assertFileExists(base_path("routes/web.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$this->pluralModelName}Test.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$this->modelName}Test.php")); } diff --git a/tests/Generators/RouteWebGeneratorTest.php b/tests/Generators/RouteWebGeneratorTest.php new file mode 100644 index 0000000..af9bcb3 --- /dev/null +++ b/tests/Generators/RouteWebGeneratorTest.php @@ -0,0 +1,22 @@ +artisan('make:crud', ['name' => $this->modelName, '--no-interaction' => true]); + + $routeWebPath = base_path('routes/web.php'); + $this->assertFileExists($routeWebPath); + $routeWebFileContent = "assertEquals($routeWebFileContent, file_get_contents($routeWebPath)); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 74f31c3..b707c78 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -27,6 +27,7 @@ abstract class TestCase extends BaseTestCase exec('rm -r '.app_path('Http')); exec('rm '.database_path('migrations/*')); exec('rm -r '.resource_path('views/'.$this->tableName)); + exec('rm -r '.base_path('routes')); exec('rm -r '.base_path('tests/Feature')); exec('rm -r '.base_path('tests/Unit'));