Completed
Pull Request — master (#8)
by
unknown
08:50 queued 06:53
created

MigrationTest::testGetBaseSqlNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 13 and the first side effect is on line 10.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace Test;
3
4
use ByJG\AnyDataset\Store\PdoMysql;
5
use ByJG\DbMigration\Migration;
6
use ByJG\Util\Uri;
7
8
// backward compatibility
9
if (!class_exists('\PHPUnit\Framework\TestCase')) {
10
    class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
11
}
12
13
class MigrationTest extends \PHPUnit\Framework\TestCase
14
{
15
    /**
16
     * @var Migration
17
     */
18
    protected $object;
19
20
    public function setUp()
21
    {
22
        $this->object = new Migration(new Uri('mysql://localhost'), __DIR__ . '/dirstructure');
23
    }
24
25
    public function tearDown()
26
    {
27
        $this->object = null;
28
    }
29
30
    public function testGetBaseSql()
31
    {
32
        $base = $this->object->getBaseSql();
33
        $this->assertEquals(__DIR__ . '/dirstructure/base.sql', $base);
34
    }
35
36
    public function testGetMigrationSql1()
37
    {
38
        $version = $this->object->getMigrationSql(1, 1);
39
        $this->assertEquals(__DIR__ . '/dirstructure/migrations/up/00001.sql', $version);
40
    }
41
42
    public function testGetMigrationSql2()
43
    {
44
        $version = $this->object->getMigrationSql(2, 1);
45
        $this->assertEquals(__DIR__ . '/dirstructure/migrations/up/00002.sql', $version);
46
    }
47
48
    public function testGetMigrationSql3()
49
    {
50
        $version = $this->object->getMigrationSql(12, 1);
51
        $this->assertEquals(__DIR__ . '/dirstructure/migrations/up/00012-dev.sql', $version);
52
    }
53
54
    /**
55
     * @expectedException \ByJG\DbMigration\Exception\InvalidMigrationFile
56
     * @expectedExceptionMessage version number '13'
57
     */
58
    public function testGetMigrationSql4()
59
    {
60
        $this->object->getMigrationSql(13, 1);
61
    }
62
63
    public function testGetMigrationSqlDown1()
64
    {
65
        $version = $this->object->getMigrationSql(1, -1);
66
        $this->assertEquals(__DIR__ . '/dirstructure/migrations/down/00001.sql', $version);
67
    }
68
69
    public function testGetMigrationSqlDown2()
70
    {
71
        $version = $this->object->getMigrationSql(2, -1);
72
        $this->assertEquals(__DIR__ . '/dirstructure/migrations/down/00002.sql', $version);
73
    }
74
75
    public function testGetMigrationSqlDown3()
76
    {
77
        $version = $this->object->getMigrationSql(12, -1);
78
        $this->assertEquals(__DIR__ . '/dirstructure/migrations/down/00012-dev.sql', $version);
79
    }
80
81
    /**
82
     * @expectedException \ByJG\DbMigration\Exception\InvalidMigrationFile
83
     * @expectedExceptionMessage version number '13'
84
     */
85
    public function testGetMigrationSqlDown4()
86
    {
87
        $this->object->getMigrationSql(13, -1);
88
    }
89
}
90