|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @author Anton Titov (Wolfy-J) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Spiral\Tests\Framework\Migrate; |
|
13
|
|
|
|
|
14
|
|
|
use Spiral\Database\Database; |
|
15
|
|
|
use Spiral\Tests\Framework\ConsoleTest; |
|
16
|
|
|
|
|
17
|
|
|
class MigrateTest extends ConsoleTest |
|
18
|
|
|
{ |
|
19
|
|
|
public function setUp(): void |
|
20
|
|
|
{ |
|
21
|
|
|
parent::setUp(); |
|
22
|
|
|
|
|
23
|
|
|
$this->app->getEnvironment()->set('SAFE_MIGRATIONS', true); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testMigrate(): void |
|
27
|
|
|
{ |
|
28
|
|
|
/** @var Database $db */ |
|
29
|
|
|
$db = $this->app->get(Database::class); |
|
30
|
|
|
$this->assertSame([], $db->getTables()); |
|
31
|
|
|
|
|
32
|
|
|
$out = $this->runCommandDebug('migrate'); |
|
33
|
|
|
$this->assertStringContainsString('not', $out); |
|
34
|
|
|
|
|
35
|
|
|
$this->runCommandDebug('migrate:init'); |
|
36
|
|
|
$this->runCommandDebug('cycle:migrate'); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertSame(1, count($db->getTables())); |
|
39
|
|
|
|
|
40
|
|
|
$this->runCommandDebug('migrate'); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertSame(3, count($db->getTables())); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testMigrateRollback(): void |
|
46
|
|
|
{ |
|
47
|
|
|
/** @var Database $db */ |
|
48
|
|
|
$db = $this->app->get(Database::class); |
|
49
|
|
|
$this->assertSame([], $db->getTables()); |
|
50
|
|
|
|
|
51
|
|
|
$this->runCommandDebug('migrate:init'); |
|
52
|
|
|
|
|
53
|
|
|
$out = $this->runCommandDebug('migrate:rollback'); |
|
54
|
|
|
$this->assertStringContainsString('No', $out); |
|
55
|
|
|
|
|
56
|
|
|
$this->runCommandDebug('cycle:migrate'); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertSame(1, count($db->getTables())); |
|
59
|
|
|
|
|
60
|
|
|
$this->runCommandDebug('migrate'); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertSame(3, count($db->getTables())); |
|
63
|
|
|
|
|
64
|
|
|
$this->runCommandDebug('migrate:rollback'); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertSame(1, count($db->getTables())); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testMigrateReplay(): void |
|
70
|
|
|
{ |
|
71
|
|
|
/** @var Database $db */ |
|
72
|
|
|
$db = $this->app->get(Database::class); |
|
73
|
|
|
$this->assertSame([], $db->getTables()); |
|
74
|
|
|
|
|
75
|
|
|
$this->runCommandDebug('migrate:init'); |
|
76
|
|
|
|
|
77
|
|
|
$out = $this->runCommandDebug('migrate:replay'); |
|
78
|
|
|
$this->assertStringContainsString('No', $out); |
|
79
|
|
|
|
|
80
|
|
|
$this->runCommandDebug('cycle:migrate'); |
|
81
|
|
|
$this->assertSame(1, count($db->getTables())); |
|
82
|
|
|
|
|
83
|
|
|
$this->runCommandDebug('migrate'); |
|
84
|
|
|
$this->assertSame(3, count($db->getTables())); |
|
85
|
|
|
|
|
86
|
|
|
$this->runCommandDebug('migrate:replay'); |
|
87
|
|
|
$this->assertSame(3, count($db->getTables())); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|