These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Test; |
||
3 | |||
4 | use ByJG\DbMigration\Migration; |
||
5 | use ByJG\Util\Uri; |
||
6 | |||
7 | class MigrationTest extends \PHPUnit\Framework\TestCase |
||
8 | { |
||
9 | /** |
||
10 | * @var Migration |
||
11 | */ |
||
12 | protected $object; |
||
13 | |||
14 | public function setUp() |
||
15 | { |
||
16 | $this->object = new Migration(new Uri('mysql://localhost'), __DIR__ . '/dirstructure'); |
||
17 | } |
||
18 | |||
19 | public function tearDown() |
||
20 | { |
||
21 | $this->object = null; |
||
22 | } |
||
23 | |||
24 | public function testGetBaseSql() |
||
25 | { |
||
26 | $base = $this->object->getBaseSql(); |
||
27 | $this->assertEquals(__DIR__ . '/dirstructure/base.sql', $base); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @expectedException \ByJG\DbMigration\Exception\InvalidMigrationFile |
||
32 | */ |
||
33 | public function testGetBaseSqlNotFound() |
||
34 | { |
||
35 | $this->object = new Migration(new Uri('mysql://localhost'), __DIR__ . '/invalid'); |
||
36 | $this->object->getBaseSql(); |
||
0 ignored issues
–
show
|
|||
37 | } |
||
38 | |||
39 | public function testGetBaseSqlNotFoundAndNotRequired() |
||
40 | { |
||
41 | $this->object = new Migration(new Uri('mysql://localhost'), __DIR__ . '/invalid', false); |
||
42 | $this->object->getBaseSql(); |
||
43 | $this->assertTrue(true); |
||
44 | } |
||
45 | |||
46 | public function testGetMigrationSql1() |
||
47 | { |
||
48 | $version = $this->object->getMigrationSql(1, 1); |
||
49 | $this->assertEquals(__DIR__ . '/dirstructure/migrations/up/00001.sql', $version); |
||
50 | } |
||
51 | |||
52 | public function testGetMigrationSql2() |
||
53 | { |
||
54 | $version = $this->object->getMigrationSql(2, 1); |
||
55 | $this->assertEquals(__DIR__ . '/dirstructure/migrations/up/00002.sql', $version); |
||
56 | } |
||
57 | |||
58 | public function testGetMigrationSql3() |
||
59 | { |
||
60 | $version = $this->object->getMigrationSql(12, 1); |
||
61 | $this->assertEquals(__DIR__ . '/dirstructure/migrations/up/00012-dev.sql', $version); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @expectedException \ByJG\DbMigration\Exception\InvalidMigrationFile |
||
66 | * @expectedExceptionMessage version number '13' |
||
67 | */ |
||
68 | public function testGetMigrationSql4() |
||
69 | { |
||
70 | $this->object->getMigrationSql(13, 1); |
||
71 | } |
||
72 | |||
73 | public function testGetMigrationSqlDown1() |
||
74 | { |
||
75 | $version = $this->object->getMigrationSql(1, -1); |
||
76 | $this->assertEquals(__DIR__ . '/dirstructure/migrations/down/00001.sql', $version); |
||
77 | } |
||
78 | |||
79 | public function testGetMigrationSqlDown2() |
||
80 | { |
||
81 | $version = $this->object->getMigrationSql(2, -1); |
||
82 | $this->assertEquals(__DIR__ . '/dirstructure/migrations/down/00002.sql', $version); |
||
83 | } |
||
84 | |||
85 | public function testGetMigrationSqlDown3() |
||
86 | { |
||
87 | $version = $this->object->getMigrationSql(12, -1); |
||
88 | $this->assertEquals(__DIR__ . '/dirstructure/migrations/down/00012-dev.sql', $version); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @expectedException \ByJG\DbMigration\Exception\InvalidMigrationFile |
||
93 | * @expectedExceptionMessage version number '13' |
||
94 | */ |
||
95 | public function testGetMigrationSqlDown4() |
||
96 | { |
||
97 | $this->object->getMigrationSql(13, -1); |
||
98 | } |
||
99 | } |
||
100 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: