mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-02-05 03:00:52 -06:00
68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Tests;
|
|
|
|
use App\Console\Kernel;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Foundation\Testing\RefreshDatabaseState;
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
|
use JMac\Testing\Traits\AdditionalAssertions;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
use CreatesApplication;
|
|
use AdditionalAssertions;
|
|
use RefreshDatabase;
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->artisan('config:clear');
|
|
|
|
$this->artisan('route:clear');
|
|
|
|
$this->artisan('cache:clear');
|
|
}
|
|
|
|
/**
|
|
* Overrides the method in the default trait.
|
|
*
|
|
* @see https://alexvanderbist.com/posts/2019/how-migrations-might-be-slowing-down-your-laravel-tests
|
|
*/
|
|
protected function refreshTestDatabase()
|
|
{
|
|
if (! RefreshDatabaseState::$migrated) {
|
|
if (config('database.pristine-db-file')) {
|
|
// If a flat file is defined, load it.
|
|
|
|
$this->artisan('db:load --quiet');
|
|
|
|
$this->artisan('migrate');
|
|
} else {
|
|
// Otherwise, proceed using default strategy.
|
|
|
|
$this->artisan('migrate:fresh', [
|
|
'--drop-views' => $this->shouldDropViews(),
|
|
'--drop-types' => $this->shouldDropTypes(),
|
|
]);
|
|
}
|
|
|
|
$this->app[Kernel::class]->setArtisan(null);
|
|
|
|
RefreshDatabaseState::$migrated = true;
|
|
}
|
|
|
|
$connectionsNotToTransact = ['sqlite', 'pgsql', 'sqlsrv'];
|
|
|
|
$this->connectionsToTransact = array_keys(
|
|
array_diff_key(config('database.connections'), array_flip($connectionsNotToTransact))
|
|
);
|
|
|
|
$this->beginDatabaseTransaction();
|
|
}
|
|
}
|