From 2491bcff4be6781be00a6c515ac5e922743e70fd Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Sat, 8 Jun 2024 12:11:59 +0330 Subject: [PATCH] fix(BC): revert breaking --- src/Abstracts/Tests/PhpUnit/TestCase.php | 40 ++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Abstracts/Tests/PhpUnit/TestCase.php b/src/Abstracts/Tests/PhpUnit/TestCase.php index 59170240..4b7886f2 100644 --- a/src/Abstracts/Tests/PhpUnit/TestCase.php +++ b/src/Abstracts/Tests/PhpUnit/TestCase.php @@ -3,28 +3,62 @@ namespace Apiato\Core\Abstracts\Tests\PhpUnit; use Apiato\Core\Traits\HashIdTrait; +use Apiato\Core\Traits\TestCaseTrait; use Apiato\Core\Traits\TestTraits\PhpUnit\TestAssertionHelperTrait; use Apiato\Core\Traits\TestTraits\PhpUnit\TestAuthHelperTrait; use Apiato\Core\Traits\TestTraits\PhpUnit\TestRequestHelperTrait; +use Illuminate\Contracts\Console\Kernel; use Illuminate\Foundation\Testing\LazilyRefreshDatabase; +use Illuminate\Foundation\Testing\RefreshDatabaseState; use Illuminate\Foundation\Testing\TestCase as LaravelTestCase; -use Illuminate\Support\Facades\Artisan; abstract class TestCase extends LaravelTestCase { + use TestCaseTrait; use TestAuthHelperTrait; use TestRequestHelperTrait; use TestAssertionHelperTrait; use HashIdTrait; use LazilyRefreshDatabase; + /** + * The base URL to use while testing the application. + */ + protected string $baseUrl; + /** * Seed the DB on migrations. */ protected bool $seed = true; - protected function afterRefreshingDatabase(): void + /** + * Refresh the in-memory database. + */ + protected function refreshInMemoryDatabase(): void + { + $this->artisan('migrate', $this->migrateUsing()); + + // Install Passport Client for Testing + $this->setupPassportOAuth2(); + + $this->app[Kernel::class]->setArtisan(null); + } + + /** + * Refresh a conventional test database. + */ + protected function refreshTestDatabase(): void { - Artisan::call('passport:install'); + if (!RefreshDatabaseState::$migrated) { + $this->artisan('migrate:fresh', $this->migrateFreshUsing()); + $this->setupPassportOAuth2(); + + $this->app[Kernel::class]->setArtisan(null); + + RefreshDatabaseState::$migrated = true; + } + + $this->beginDatabaseTransaction(); } } +