diff --git a/Abstracts/Tests/PhpUnit/TestCase.php b/Abstracts/Tests/PhpUnit/TestCase.php index 1809970dd..217180305 100644 --- a/Abstracts/Tests/PhpUnit/TestCase.php +++ b/Abstracts/Tests/PhpUnit/TestCase.php @@ -28,6 +28,11 @@ abstract class TestCase extends LaravelTestCase */ protected string $baseUrl; + /** + * Seed the DB on migrations + */ + protected bool $seed = true; + /** * Setup the test environment, before each test. */ @@ -46,15 +51,10 @@ protected function tearDown(): void /** * Refresh the in-memory database. - * Overridden refreshTestDatabase Trait */ protected function refreshInMemoryDatabase(): void { - // Migrate the database - $this->migrateDatabase(); - - // Seed the database - $this->seed(); + $this->artisan('migrate', $this->migrateUsing()); // Install Passport Client for Testing $this->setupPassportOAuth2(); @@ -64,13 +64,11 @@ protected function refreshInMemoryDatabase(): void /** * Refresh a conventional test database. - * Overridden refreshTestDatabase Trait */ protected function refreshTestDatabase(): void { if (!RefreshDatabaseState::$migrated) { - $this->artisan('migrate:fresh'); - $this->seed(); + $this->artisan('migrate:fresh', $this->migrateFreshUsing()); $this->setupPassportOAuth2(); $this->app[Kernel::class]->setArtisan(null); diff --git a/Traits/TestCaseTrait.php b/Traits/TestCaseTrait.php index 6fee369f7..9ee5421b9 100644 --- a/Traits/TestCaseTrait.php +++ b/Traits/TestCaseTrait.php @@ -2,17 +2,11 @@ namespace Apiato\Core\Traits; -use Illuminate\Support\Facades\Artisan; use Laravel\Passport\ClientRepository; use Laravel\Passport\PersonalAccessClient; trait TestCaseTrait { - public function migrateDatabase(): void - { - Artisan::call('migrate'); - } - /** * Override default URL subDomain in case you want to change it for some tests * @@ -34,9 +28,9 @@ public function overrideSubDomain($url = null) $array = explode('.', $info['host']); $withoutDomain = (array_key_exists( - count($array) - 2, - $array - ) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1]; + count($array) - 2, + $array + ) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1]; $newSubDomain = $info['scheme'] . '://' . $this->subDomain . '.' . $withoutDomain;