-
Notifications
You must be signed in to change notification settings - Fork 1
/
RefreshDatabaseIfEmpty.php
46 lines (36 loc) · 1.41 KB
/
RefreshDatabaseIfEmpty.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php declare(strict_types = 1);
namespace LastDragon_ru\LaraASP\Testing\Database;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Database\DatabaseManager;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
use LastDragon_ru\LaraASP\Testing\Package;
use PHPUnit\Framework\TestCase;
use function trigger_deprecation;
// phpcs:disable PSR1.Files.SideEffects
trigger_deprecation(Package::Name, '6.2.0', 'Please use own trait.');
/**
* The trait is very similar to standard {@link RefreshDatabase} but there is one
* difference: it will refresh the database only if it is empty. This is very
* useful for local testing and allow significantly reduce bootstrap time.
*
* @deprecated 6.2.0 Please use own trait.
*
* @phpstan-require-extends TestCase
*/
trait RefreshDatabaseIfEmpty {
use RefreshDatabase {
refreshTestDatabase as protected laravelRefreshTestDatabase;
}
abstract protected function app(): Application;
protected function refreshTestDatabase(): void {
if (!RefreshDatabaseState::$migrated) {
$connection = $this->app()->make(DatabaseManager::class)->connection();
$tables = $connection->getSchemaBuilder()->getTables();
if ($tables !== []) {
RefreshDatabaseState::$migrated = true;
}
}
$this->laravelRefreshTestDatabase();
}
}