Completed
Push — dev ( 94208d...ada7da )
by James Ekow Abaka
02:35
created

MigrateTest::setup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2014 ekow.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace yentu\tests\cases;
28
29
use org\bovigo\vfs\vfsStream;
30
use yentu\commands\Migrate;
31
32
class MigrateTest extends \yentu\tests\YentuTest
33
{
34
35
    public function setup()
36
    {
37
        $this->testDatabase = 'yentu_migration_test';
38
        parent::setup();
39
        $this->setupForMigration();
40
    }
41
42
    public function testMigration()
43
    {
44
        copy('tests/migrations/12345678901234_import.php', vfsStream::url('home/yentu/migrations/12345678901234_import.php'));
45
        $migrate = new Migrate($this->yentu, $this->getManipulatorFactory(), $this->io, $this->config);
46
        $migrate->run(array());
47
48
        $this->assertEquals(
49
            file_get_contents("tests/streams/migrate_output.txt"), file_get_contents(vfsStream::url('home/output.txt'))
50
        );
51
52
        foreach ($this->tables as $table) {
53
            $this->assertTableExists($table);
54
        }
55
56
        copy('tests/migrations/12345678901234_change_null.php', vfsStream::url('home/yentu/migrations/12345678901235_change_null.php'));
57
        $migrate = new Migrate($this->yentu, $this->getManipulatorFactory(), $this->io, $this->config);
58
        $this->assertColumnNullable('role_name', 'roles');
59
        $this->assertColumnExists('user_name', 'users');
60
        $migrate->run(array());
61
        $this->assertColumnNotNullable('role_name', 'roles');
62
        $this->assertColumnExists('username', 'users');
63
    }
64
65
    public function testSchemaMigration()
66
    {
67
        $this->skipSchemaTests();
68
        copy('tests/migrations/12345678901234_schema.php', vfsStream::url('home/yentu/migrations/12345678901234_schema.php'));
69
        $migrate = new Migrate($this->yentu, $this->getManipulatorFactory(), $this->io, $this->config);
70
        $migrate->run(array());
71
        $this->assertSchemaExists('schema');
72
73
        foreach ($this->tables as $table) {
74
            if ($table == 'yentu_history')
75
                return;
76
            $schema = array_search($table, array('cities', 'locations', 'countries', 'regions', 'countries_view')) === false ? 'schema' : 'geo';
77
            $this->assertTableExists(array('table' => $table, 'schema' => $schema));
78
        }
79
    }
80
81
    private $tables = array(
82
        'api_keys',
83
        'audit_trail',
84
        'audit_trail_data',
85
        'bank_branches',
86
        'banks',
87
        'binary_objects',
88
        'branches',
89
        'cheque_formats',
90
        'cities',
91
        'client_joint_accounts',
92
        'clients',
93
        'client_users',
94
        'configurations',
95
        'countries',
96
        'departments',
97
        'holidays',
98
        'identification_types',
99
        'locations',
100
        'note_attachments',
101
        'notes',
102
        'notifications',
103
        'permissions',
104
        'regions',
105
        'relationships',
106
        'roles',
107
        'suppliers',
108
        'temporary_roles',
109
        'users',
110
        'yentu_history',
111
        'users_view',
112
        'countries_view'
113
    );
114
115
}
116