Skip to content

Commit

Permalink
Fixed create and alter table tests;
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Mar 29, 2016
1 parent 82a88e8 commit 7c4defe
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace edgardmessias\unit\db\firebird;

use edgardmessias\db\firebird\Schema;
use yii\db\Expression;

/**
Expand Down Expand Up @@ -151,6 +152,60 @@ public function testInsertExpression()
], $record);
}

public function testCreateTable()
{
$db = $this->getConnection();

if($db->getSchema()->getTableSchema('testCreateTable') !== null){
$db->createCommand()->dropTable('testCreateTable')->execute();
//Update metadata in connection
$db->close();
$db->open();
}

$db->createCommand()->createTable('testCreateTable', ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER])->execute();
//Update metadata in connection
$db->close();
$db->open();

$db->createCommand()->insert('testCreateTable', ['bar' => 1])->execute();
$records = $db->createCommand('SELECT [[id]], [[bar]] FROM {{testCreateTable}};')->queryAll();
$this->assertEquals([
['id' => 1, 'bar' => 1],
], $records);
}

public function testAlterTable()
{
$db = $this->getConnection();

if($db->getSchema()->getTableSchema('testAlterTable') !== null){
$db->createCommand()->dropTable('testAlterTable')->execute();
//Update metadata in connection
$db->close();
$db->open();
}

$db->createCommand()->createTable('testAlterTable', ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER])->execute();
//Update metadata in connection
$db->close();
$db->open();

$db->createCommand()->insert('testAlterTable', ['bar' => 1])->execute();

$db->createCommand()->alterColumn('testAlterTable', 'bar', Schema::TYPE_STRING)->execute();
//Update metadata in connection
$db->close();
$db->open();

$db->createCommand()->insert('testAlterTable', ['bar' => 'hello'])->execute();
$records = $db->createCommand('SELECT [[id]], [[bar]] FROM {{testAlterTable}};')->queryAll();
$this->assertEquals([
['id' => 1, 'bar' => 1],
['id' => 2, 'bar' => 'hello'],
], $records);
}

public function testRenameTable()
{
$this->markTestSkipped('firebird does not support rename table');
Expand Down

0 comments on commit 7c4defe

Please sign in to comment.