Passed
Pull Request — master (#277)
by Kirill
03:11
created

MigrateTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 24
c 3
b 0
f 0
dl 0
loc 47
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testMigrate() 0 9 1
A testAlterSchema() 0 14 1
A setUp() 0 4 1
A testMigrateNoChanges() 0 11 1
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