AbstractMigrationTest.php
7.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
namespace Test\Phinx\Migration;
use Phinx\Db\Table;
use Phinx\Db\Adapter\AdapterInterface;
class AbstractMigrationTest extends \PHPUnit_Framework_TestCase
{
public function testUp()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
$this->assertNull($migrationStub->up());
}
public function testDown()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
$this->assertNull($migrationStub->down());
}
public function testAdapterMethods()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub adapter
$adapterStub = $this->getMock('\Phinx\Db\Adapter\PdoAdapter', array(), array(array()));
// test methods
$this->assertNull($migrationStub->getAdapter());
$migrationStub->setAdapter($adapterStub);
$this->assertTrue($migrationStub->getAdapter() instanceof AdapterInterface);
}
public function testSetOutputMethods()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub output
$outputStub = $this->getMock('\Symfony\Component\Console\Output\OutputInterface', array(), array(array()));
// test methods
$this->assertNull($migrationStub->getOutput());
$migrationStub->setOutput($outputStub);
$this->assertInstanceOf('\Symfony\Component\Console\Output\OutputInterface', $migrationStub->getOutput());
}
public function testGetName()
{
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
$this->assertFalse(!(strpos($migrationStub->getName(), 'AbstractMigration')));
}
public function testVersionMethods()
{
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(20120103080000));
$this->assertEquals(20120103080000, $migrationStub->getVersion());
$migrationStub->setVersion(20120915093312);
$this->assertEquals(20120915093312, $migrationStub->getVersion());
}
public function testExecute()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub adapter
$adapterStub = $this->getMock('\Phinx\Db\Adapter\PdoAdapter', array(), array(array()));
$adapterStub->expects($this->once())
->method('execute')
->will($this->returnValue(2));
$migrationStub->setAdapter($adapterStub);
$this->assertEquals(2, $migrationStub->execute('SELECT FOO FROM BAR'));
}
public function testQuery()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub adapter
$adapterStub = $this->getMock('\Phinx\Db\Adapter\PdoAdapter', array(), array(array()));
$adapterStub->expects($this->once())
->method('query')
->will($this->returnValue(array(array('0' => 'bar', 'foo' => 'bar'))));
$migrationStub->setAdapter($adapterStub);
$this->assertEquals(array(array('0' => 'bar', 'foo' => 'bar')), $migrationStub->query('SELECT FOO FROM BAR'));
}
public function testFetchRow()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub adapter
$adapterStub = $this->getMock('\Phinx\Db\Adapter\PdoAdapter', array(), array(array()));
$adapterStub->expects($this->once())
->method('fetchRow')
->will($this->returnValue(array('0' => 'bar', 'foo' => 'bar')));
$migrationStub->setAdapter($adapterStub);
$this->assertEquals(array('0' => 'bar', 'foo' => 'bar'), $migrationStub->fetchRow('SELECT FOO FROM BAR'));
}
public function testFetchAll()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub adapter
$adapterStub = $this->getMock('\Phinx\Db\Adapter\PdoAdapter', array(), array(array()));
$adapterStub->expects($this->once())
->method('fetchAll')
->will($this->returnValue(array(array('0' => 'bar', 'foo' => 'bar'))));
$migrationStub->setAdapter($adapterStub);
$this->assertEquals(array(array('0' => 'bar', 'foo' => 'bar')), $migrationStub->fetchAll('SELECT FOO FROM BAR'));
}
public function testCreateDatabase()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub adapter
$adapterStub = $this->getMock('\Phinx\Db\Adapter\PdoAdapter', array(), array(array()));
$adapterStub->expects($this->once())
->method('createDatabase')
->will($this->returnValue(array(array('0' => 'bar', 'foo' => 'bar'))));
$migrationStub->setAdapter($adapterStub);
$migrationStub->createDatabase('testdb', array());
}
public function testDropDatabase()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub adapter
$adapterStub = $this->getMock('\Phinx\Db\Adapter\PdoAdapter', array(), array(array()));
$adapterStub->expects($this->once())
->method('dropDatabase')
->will($this->returnValue(array(array('0' => 'bar', 'foo' => 'bar'))));
$migrationStub->setAdapter($adapterStub);
$migrationStub->dropDatabase('testdb');
}
public function testHasTable()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub adapter
$adapterStub = $this->getMock('\Phinx\Db\Adapter\PdoAdapter', array(), array(array()));
$adapterStub->expects($this->once())
->method('hasTable')
->will($this->returnValue(true));
$migrationStub->setAdapter($adapterStub);
$this->assertTrue($migrationStub->hasTable('test_table'));
}
public function testTableMethod()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub adapter
$adapterStub = $this->getMock('\Phinx\Db\Adapter\PdoAdapter', array(), array(array()));
$migrationStub->setAdapter($adapterStub);
$this->assertTrue($migrationStub->table('test_table') instanceof Table);
}
public function testDropTableMethod()
{
// stub migration
$migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', array(0));
// stub adapter
$adapterStub = $this->getMock('\Phinx\Db\Adapter\PdoAdapter', array(), array(array()));
$adapterStub->expects($this->once())
->method('dropTable');
$migrationStub->setAdapter($adapterStub);
$migrationStub->dropTable('test_table');
}
}