Skip to content

Commit

Permalink
refactor: update parent test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed May 5, 2022
1 parent a4a3391 commit 414db85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
16 changes: 7 additions & 9 deletions Abstracts/Tests/PhpUnit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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();
Expand All @@ -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);
Expand Down
12 changes: 3 additions & 9 deletions Traits/TestCaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;

Expand Down

0 comments on commit 414db85

Please sign in to comment.