From 3d75b525300e2da5094af978007c1ad72acc5976 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Wed, 3 Apr 2019 10:39:59 +0800 Subject: [PATCH] Improve test cases Add generated policy test existance check --- tests/CrudApiMakeCommandTest.php | 7 ++++++- tests/CrudMakeCommandTest.php | 5 +++++ tests/CrudSimpleMakeCommandTest.php | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/CrudApiMakeCommandTest.php b/tests/CrudApiMakeCommandTest.php index 807dea0..de33b99 100644 --- a/tests/CrudApiMakeCommandTest.php +++ b/tests/CrudApiMakeCommandTest.php @@ -29,6 +29,7 @@ class CrudApiMakeCommandTest extends TestCase $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")); + $this->assertFileExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Api/Manage{$this->model_name}Test.php")); } @@ -53,11 +54,12 @@ class CrudApiMakeCommandTest extends TestCase $this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php")); $this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php")); $this->assertFileNotExists(base_path("tests/Unit/Models/{$this->model_name}Test.php")); + $this->assertFileNotExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Api/Manage{$this->model_name}Test.php")); } /** @test */ - public function it_cannot_generate_crud_files_if_namespaced_model_exists() + public function it_not_generate_api_crud_files_if_namespaced_model_exists() { $this->artisan('make:model', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]); $this->artisan('make:crud-api', ['name' => 'Entities/Projects/Problem', '--no-interaction' => true]); @@ -79,6 +81,7 @@ class CrudApiMakeCommandTest extends TestCase $this->assertFileNotExists(app_path("Policies/ProblemPolicy.php")); $this->assertFileNotExists(database_path("factories/ProblemFactory.php")); $this->assertFileNotExists(base_path("tests/Unit/Models/ProblemTest.php")); + $this->assertFileNotExists(base_path("tests/Unit/Policies/ProblemPolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Api/ManageProblemTest.php")); $this->removeFileOrDir(app_path('Entities/Projects')); @@ -115,6 +118,7 @@ class CrudApiMakeCommandTest extends TestCase $this->assertFileExists(app_path("Policies/{$modelName}Policy.php")); $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); + $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Api/Manage{$modelName}Test.php")); } @@ -147,6 +151,7 @@ class CrudApiMakeCommandTest extends TestCase $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); + $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php")); $this->assertFileExists(base_path("tests/Feature/Api/Manage{$modelName}Test.php")); } diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index 2a0e522..5029b18 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -31,6 +31,7 @@ class CrudMakeCommandTest extends TestCase $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")); + $this->assertFileExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php")); } @@ -60,6 +61,7 @@ class CrudMakeCommandTest extends TestCase $this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php")); $this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php")); $this->assertFileNotExists(base_path("tests/Unit/Models/{$this->model_name}Test.php")); + $this->assertFileNotExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php")); $this->assertFileNotExists(base_path("tests/Feature/Manage{$this->model_name}Test.php")); } @@ -88,6 +90,7 @@ class CrudMakeCommandTest extends TestCase $this->assertFileNotExists(app_path("Policies/ProblemPolicy.php")); $this->assertFileNotExists(database_path("factories/ProblemFactory.php")); $this->assertFileNotExists(base_path("tests/Unit/Models/ProblemTest.php")); + $this->assertFileNotExists(base_path("tests/Unit/Policies/ProblemPolicyTest.php")); $this->assertFileNotExists(base_path("tests/Feature/ManageProblemTest.php")); $this->removeFileOrDir(app_path('Entities/Projects')); @@ -126,6 +129,7 @@ class CrudMakeCommandTest extends TestCase $this->assertFileExists(app_path("Policies/{$modelName}Policy.php")); $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); + $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$modelName}Test.php")); } @@ -160,6 +164,7 @@ class CrudMakeCommandTest extends TestCase $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); + $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$modelName}Test.php")); } diff --git a/tests/CrudSimpleMakeCommandTest.php b/tests/CrudSimpleMakeCommandTest.php index 14bd5c9..155358c 100644 --- a/tests/CrudSimpleMakeCommandTest.php +++ b/tests/CrudSimpleMakeCommandTest.php @@ -29,6 +29,7 @@ class CrudSimpleCommandTest extends TestCase $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")); + $this->assertFileExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php")); } @@ -56,6 +57,7 @@ class CrudSimpleCommandTest extends TestCase $this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php")); $this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php")); $this->assertFileNotExists(base_path("tests/Unit/Models/{$this->model_name}Test.php")); + $this->assertFileNotExists(base_path("tests/Unit/Policies/{$this->model_name}PolicyTest.php")); $this->assertFileNotExists(base_path("tests/Feature/Manage{$this->model_name}Test.php")); } @@ -82,6 +84,7 @@ class CrudSimpleCommandTest extends TestCase $this->assertFileNotExists(app_path("Policies/ProblemPolicy.php")); $this->assertFileNotExists(database_path("factories/ProblemFactory.php")); $this->assertFileNotExists(base_path("tests/Unit/Models/ProblemTest.php")); + $this->assertFileNotExists(base_path("tests/Unit/Policies/ProblemPolicyTest.php")); $this->assertFileNotExists(base_path("tests/Feature/ManageProblemTest.php")); $this->removeFileOrDir(app_path('Entities/Projects')); @@ -118,6 +121,7 @@ class CrudSimpleCommandTest extends TestCase $this->assertFileExists(app_path("Policies/{$modelName}Policy.php")); $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); + $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$modelName}Test.php")); } @@ -150,6 +154,7 @@ class CrudSimpleCommandTest extends TestCase $this->assertFileExists(database_path("factories/{$modelName}Factory.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$modelName}Test.php")); + $this->assertFileExists(base_path("tests/Unit/Policies/{$modelName}PolicyTest.php")); $this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$modelName}Test.php")); }