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\Cycle; |
13
|
|
|
|
14
|
|
|
use Spiral\Tests\Framework\ConsoleTest; |
15
|
|
|
|
16
|
|
|
class MigrateTest extends ConsoleTest |
17
|
|
|
{ |
18
|
|
|
public function setUp(): void |
19
|
|
|
{ |
20
|
|
|
$this->app = $this->makeApp([ |
21
|
|
|
'SAFE_MIGRATIONS' => true |
22
|
|
|
]); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testMigrate(): void |
26
|
|
|
{ |
27
|
|
|
$this->runCommandDebug('migrate:init', ['-vvv' => true]); |
28
|
|
|
|
29
|
|
|
$output = $this->runCommandDebug('cycle:migrate'); |
30
|
|
|
$this->assertStringContainsString('default.users', $output); |
31
|
|
|
|
32
|
|
|
$output = $this->runCommandDebug('cycle:migrate'); |
33
|
|
|
$this->assertStringContainsString('Outstanding migrations found', $output); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testMigrateNoChanges(): void |
37
|
|
|
{ |
38
|
|
|
$this->runCommandDebug('migrate:init', ['-vvv' => true]); |
39
|
|
|
|
40
|
|
|
$output = $this->runCommandDebug('cycle:migrate'); |
41
|
|
|
$this->assertStringContainsString('default.users', $output); |
42
|
|
|
|
43
|
|
|
$this->runCommand('migrate'); |
44
|
|
|
|
45
|
|
|
$output = $this->runCommandDebug('cycle:migrate'); |
46
|
|
|
$this->assertStringContainsString('no database changes', $output); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testAlterSchema(): void |
50
|
|
|
{ |
51
|
|
|
$this->runCommandDebug('migrate:init', ['-vvv' => true]); |
52
|
|
|
|
53
|
|
|
$output = $this->runCommandDebug('cycle:migrate', ['-r' => true]); |
54
|
|
|
$this->assertStringContainsString('default.users', $output); |
55
|
|
|
|
56
|
|
|
$user = file_get_contents(__DIR__ . '/../../app/src/User/User.php'); |
57
|
|
|
unlink(__DIR__ . '/../../app/src/User/User.php'); |
58
|
|
|
try { |
59
|
|
|
$output = $this->runCommandDebug('cycle:migrate', ['-r' => true]); |
60
|
|
|
$this->assertStringContainsString('drop foreign key', $output); |
61
|
|
|
} finally { |
62
|
|
|
file_put_contents(__DIR__ . '/../../app/src/User/User.php', $user); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|