Skip to content

Commit 7c4defe

Browse files
committed
Fixed create and alter table tests;
1 parent 82a88e8 commit 7c4defe

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/CommandTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace edgardmessias\unit\db\firebird;
44

5+
use edgardmessias\db\firebird\Schema;
56
use yii\db\Expression;
67

78
/**
@@ -151,6 +152,60 @@ public function testInsertExpression()
151152
], $record);
152153
}
153154

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+
154209
public function testRenameTable()
155210
{
156211
$this->markTestSkipped('firebird does not support rename table');

0 commit comments

Comments
 (0)