Completed
Push — master ( 17598f...abee1f )
by Kirill
13s queued 11s
created

MigrateTest::testMigrateRollback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 22
rs 9.9
c 0
b 0
f 0
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