|
2 | 2 |
|
3 | 3 | namespace edgardmessias\unit\db\firebird; |
4 | 4 |
|
| 5 | +use edgardmessias\db\firebird\Schema; |
5 | 6 | use yii\db\Expression; |
6 | 7 |
|
7 | 8 | /** |
@@ -151,6 +152,60 @@ public function testInsertExpression() |
151 | 152 | ], $record); |
152 | 153 | } |
153 | 154 |
|
| 155 | + public function testCreateTable() |
| 156 | + { |
| 157 | + $db = $this->getConnection(); |
| 158 | + |
| 159 | + if($db->getSchema()->getTableSchema('testCreateTable') !== null){ |
| 160 | + $db->createCommand()->dropTable('testCreateTable')->execute(); |
| 161 | + //Update metadata in connection |
| 162 | + $db->close(); |
| 163 | + $db->open(); |
| 164 | + } |
| 165 | + |
| 166 | + $db->createCommand()->createTable('testCreateTable', ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER])->execute(); |
| 167 | + //Update metadata in connection |
| 168 | + $db->close(); |
| 169 | + $db->open(); |
| 170 | + |
| 171 | + $db->createCommand()->insert('testCreateTable', ['bar' => 1])->execute(); |
| 172 | + $records = $db->createCommand('SELECT [[id]], [[bar]] FROM {{testCreateTable}};')->queryAll(); |
| 173 | + $this->assertEquals([ |
| 174 | + ['id' => 1, 'bar' => 1], |
| 175 | + ], $records); |
| 176 | + } |
| 177 | + |
| 178 | + public function testAlterTable() |
| 179 | + { |
| 180 | + $db = $this->getConnection(); |
| 181 | + |
| 182 | + if($db->getSchema()->getTableSchema('testAlterTable') !== null){ |
| 183 | + $db->createCommand()->dropTable('testAlterTable')->execute(); |
| 184 | + //Update metadata in connection |
| 185 | + $db->close(); |
| 186 | + $db->open(); |
| 187 | + } |
| 188 | + |
| 189 | + $db->createCommand()->createTable('testAlterTable', ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER])->execute(); |
| 190 | + //Update metadata in connection |
| 191 | + $db->close(); |
| 192 | + $db->open(); |
| 193 | + |
| 194 | + $db->createCommand()->insert('testAlterTable', ['bar' => 1])->execute(); |
| 195 | + |
| 196 | + $db->createCommand()->alterColumn('testAlterTable', 'bar', Schema::TYPE_STRING)->execute(); |
| 197 | + //Update metadata in connection |
| 198 | + $db->close(); |
| 199 | + $db->open(); |
| 200 | + |
| 201 | + $db->createCommand()->insert('testAlterTable', ['bar' => 'hello'])->execute(); |
| 202 | + $records = $db->createCommand('SELECT [[id]], [[bar]] FROM {{testAlterTable}};')->queryAll(); |
| 203 | + $this->assertEquals([ |
| 204 | + ['id' => 1, 'bar' => 1], |
| 205 | + ['id' => 2, 'bar' => 'hello'], |
| 206 | + ], $records); |
| 207 | + } |
| 208 | + |
154 | 209 | public function testRenameTable() |
155 | 210 | { |
156 | 211 | $this->markTestSkipped('firebird does not support rename table'); |
|
0 commit comments