diff --git a/composer.json b/composer.json index 6c383c7..5e4f325 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ }, "autoload-dev": { "classmap": [ + "tests/Traits", "tests/TestCase.php" ] }, diff --git a/tests/TestCase.php b/tests/TestCase.php index 3f96d3f..fa7492c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,6 +5,8 @@ use App\Entities\Users\User; class TestCase extends Illuminate\Foundation\Testing\TestCase { + use DatabaseMigrateSeeds; + /** * The base URL to use while testing the application. * @@ -27,6 +29,17 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase return $app; } + protected function setUpTraits() + { + parent::setUpTraits(); + $uses = array_flip(class_uses_recursive(static::class)); + + if (isset($uses[DatabaseMigrateSeeds::class])) { + $this->runDatabaseMigrateSeeds(); + } + + } + protected function adminUserSigningIn() { $user = factory(User::class)->create(); diff --git a/tests/Traits/DatabaseMigrateSeeds.php b/tests/Traits/DatabaseMigrateSeeds.php new file mode 100644 index 0000000..41a1f2b --- /dev/null +++ b/tests/Traits/DatabaseMigrateSeeds.php @@ -0,0 +1,23 @@ +artisan('migrate'); + $this->artisan('db:seed'); + + $this->app[Kernel::class]->setArtisan(null); + + $this->beforeApplicationDestroyed(function () { + $this->artisan('migrate:rollback'); + }); + } +} diff --git a/tests/api/ApiEventsTest.php b/tests/api/ApiEventsTest.php index 40d03ad..ec885a5 100644 --- a/tests/api/ApiEventsTest.php +++ b/tests/api/ApiEventsTest.php @@ -2,14 +2,9 @@ use App\Entities\Users\Event; use App\Entities\Users\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; class ApiEventsTest extends TestCase { - use DatabaseMigrations; - /** @test */ public function it_can_get_all_existing_events() { diff --git a/tests/api/ApiManageProjectsTest.php b/tests/api/ApiManageProjectsTest.php index 16a2c65..bf78657 100644 --- a/tests/api/ApiManageProjectsTest.php +++ b/tests/api/ApiManageProjectsTest.php @@ -2,14 +2,9 @@ use App\Entities\Projects\Project; use App\Entities\Users\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; class ApiManageProjectsTest extends TestCase { - use DatabaseMigrations; - /** @test */ public function user_can_get_project_lists() { diff --git a/tests/auth/ManageUsersTest.php b/tests/auth/ManageUsersTest.php index a655860..bd7b149 100644 --- a/tests/auth/ManageUsersTest.php +++ b/tests/auth/ManageUsersTest.php @@ -1,14 +1,9 @@ create(); + $user = factory(User::class)->create(); // Reset Request $this->visit(route('auth.reset-request')); diff --git a/tests/functional/ManageFeaturesTest.php b/tests/functional/ManageFeaturesTest.php index 5362f42..e7b41db 100644 --- a/tests/functional/ManageFeaturesTest.php +++ b/tests/functional/ManageFeaturesTest.php @@ -4,14 +4,9 @@ use App\Entities\Projects\Feature; use App\Entities\Projects\Project; use App\Entities\Projects\Task; use App\Entities\Users\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; class ManageFeaturesTest extends TestCase { - use DatabaseMigrations; - /** @test */ public function admin_can_entry_feature() { diff --git a/tests/functional/ManagePaymentsTest.php b/tests/functional/ManagePaymentsTest.php index 5f9793e..f0cf5e2 100644 --- a/tests/functional/ManagePaymentsTest.php +++ b/tests/functional/ManagePaymentsTest.php @@ -3,14 +3,9 @@ use App\Entities\Payments\Payment; use App\Entities\Projects\Project; use App\Entities\Users\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; class ManagePaymentsTest extends TestCase { - use DatabaseMigrations; - /** @test */ public function admin_can_entry_project_a_cashin_payment() { diff --git a/tests/functional/ManageProjectsTest.php b/tests/functional/ManageProjectsTest.php index d636fb2..8c42375 100644 --- a/tests/functional/ManageProjectsTest.php +++ b/tests/functional/ManageProjectsTest.php @@ -6,14 +6,9 @@ use App\Entities\Projects\Project; use App\Entities\Projects\Task; use App\Entities\Users\Role; use App\Entities\Users\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; class ManageProjectsTest extends TestCase { - use DatabaseMigrations; - /** @test */ public function admin_can_input_new_project_with_existing_customer() { diff --git a/tests/functional/ManageSubscriptionsTest.php b/tests/functional/ManageSubscriptionsTest.php index 0c5d844..8c87b2c 100644 --- a/tests/functional/ManageSubscriptionsTest.php +++ b/tests/functional/ManageSubscriptionsTest.php @@ -3,14 +3,9 @@ use App\Entities\Projects\Project; use App\Entities\Subscriptions\Subscription; use App\Entities\Users\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; class ManageSubscriptionsTest extends TestCase { - use DatabaseMigrations; - /** @test */ public function admin_can_entry_subscription() { diff --git a/tests/functional/ManageTasksTest.php b/tests/functional/ManageTasksTest.php index 8045cdb..5396a34 100644 --- a/tests/functional/ManageTasksTest.php +++ b/tests/functional/ManageTasksTest.php @@ -4,14 +4,9 @@ use App\Entities\Projects\Feature; use App\Entities\Projects\Project; use App\Entities\Projects\Task; use App\Entities\Users\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; class ManageTasksTest extends TestCase { - use DatabaseMigrations; - /** @test */ public function admin_can_entry_task() {