-
Notifications
You must be signed in to change notification settings - Fork 11.3k
/
Copy pathDatabaseMigrationsTest.php
107 lines (84 loc) · 2.98 KB
/
DatabaseMigrationsTest.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Illuminate\Tests\Foundation\Testing;
use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Foundation\Testing\Concerns\InteractsWithConsole;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
use Mockery as m;
use Orchestra\Testbench\Concerns\ApplicationTestingHooks;
use Orchestra\Testbench\Foundation\Application as Testbench;
use PHPUnit\Framework\TestCase;
use function Orchestra\Testbench\package_path;
class DatabaseMigrationsTest extends TestCase
{
use ApplicationTestingHooks;
use DatabaseMigrations;
use InteractsWithConsole;
public $dropViews = false;
public $dropTypes = false;
protected function setUp(): void
{
RefreshDatabaseState::$migrated = false;
$this->afterApplicationCreated(function () {
$this->app['config']->set([
'database.default' => 'testing',
'database.connections.testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
],
]);
});
$this->setUpTheApplicationTestingHooks();
$this->withoutMockingConsoleOutput();
}
protected function tearDown(): void
{
$this->tearDownTheApplicationTestingHooks();
RefreshDatabaseState::$migrated = false;
}
protected function refreshApplication()
{
$this->app = Testbench::create(
basePath: package_path('vendor/orchestra/testbench-core/laravel'),
);
}
public function testRefreshTestDatabaseDefault()
{
$this->app->instance(ConsoleKernelContract::class, $kernel = m::spy(ConsoleKernel::class));
$kernel->shouldReceive('call')
->once()
->with('migrate:fresh', [
'--drop-views' => false,
'--drop-types' => false,
'--seed' => false,
]);
$this->runDatabaseMigrations();
}
public function testRefreshTestDatabaseWithDropViewsOption()
{
$this->dropViews = true;
$this->app->instance(ConsoleKernelContract::class, $kernel = m::spy(ConsoleKernel::class));
$kernel->shouldReceive('call')
->once()
->with('migrate:fresh', [
'--drop-views' => true,
'--drop-types' => false,
'--seed' => false,
]);
$this->runDatabaseMigrations();
}
public function testRefreshTestDatabaseWithDropTypesOption()
{
$this->dropTypes = true;
$this->app->instance(ConsoleKernelContract::class, $kernel = m::spy(ConsoleKernel::class));
$kernel->shouldReceive('call')
->once()
->with('migrate:fresh', [
'--drop-views' => false,
'--drop-types' => true,
'--seed' => false,
]);
$this->runDatabaseMigrations();
}
}