Browse Source

Fixed testCreateTable and testAlterTable in CommandTest for MSSQL and OCI

tags/3.0.0-alpha1
Edgard Lorraine Messias 9 years ago committed by Alexander Makarov
parent
commit
2d8106a39c
  1. 46
      tests/framework/db/mssql/MssqlCommandTest.php
  2. 46
      tests/framework/db/oci/OracleCommandTest.php

46
tests/framework/db/mssql/MssqlCommandTest.php

@ -2,6 +2,7 @@
namespace yiiunit\framework\db\mssql;
use yii\db\Schema;
use yiiunit\framework\db\CommandTest;
/**
@ -81,4 +82,49 @@ class MssqlCommandTest extends CommandTest
$command->bindValue(':name', 'user5');
$this->assertEquals('user5@example.com', $command->queryScalar());
}
public function testCreateTable()
{
$db = $this->getConnection();
// on the first run the 'testCreateTable' table does not exist
try {
$db->createCommand()->dropTable('testCreateTable')->execute();
} catch (\Exception $ex) {
// 'testCreateTable' table does not exist
}
$db->createCommand()->createTable('testCreateTable', ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER])->execute();
$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()
{
if ($this->driverName === 'sqlite'){
$this->markTestSkipped('Sqlite does not support alterTable');
}
$db = $this->getConnection();
// on the first run the 'testAlterTable' table does not exist
try {
$db->createCommand()->dropTable('testAlterTable')->execute();
} catch (\Exception $ex) {
// 'testAlterTable' table does not exist
}
$db->createCommand()->createTable('testAlterTable', ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER])->execute();
$db->createCommand()->insert('testAlterTable', ['bar' => 1])->execute();
$db->createCommand()->alterColumn('testAlterTable', 'bar', Schema::TYPE_STRING)->execute();
$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);
}
}

46
tests/framework/db/oci/OracleCommandTest.php

@ -1,6 +1,7 @@
<?php
namespace yiiunit\framework\db\oci;
use yii\db\Schema;
use yiiunit\framework\db\CommandTest;
/**
@ -29,4 +30,49 @@ class OracleCommandTest extends CommandTest
$command->execute();
$this->assertEquals(3, $db->getSchema()->getLastInsertID('profile_SEQ'));
}
public function testCreateTable()
{
$db = $this->getConnection();
// on the first run the 'testCreateTable' table does not exist
try {
$db->createCommand()->dropTable('testCreateTable')->execute();
} catch (\Exception $ex) {
// 'testCreateTable' table does not exist
}
$db->createCommand()->createTable('testCreateTable', ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER])->execute();
$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()
{
if ($this->driverName === 'sqlite'){
$this->markTestSkipped('Sqlite does not support alterTable');
}
$db = $this->getConnection();
// on the first run the 'testAlterTable' table does not exist
try {
$db->createCommand()->dropTable('testAlterTable')->execute();
} catch (\Exception $ex) {
// 'testAlterTable' table does not exist
}
$db->createCommand()->createTable('testAlterTable', ['id' => Schema::TYPE_PK, 'bar' => Schema::TYPE_INTEGER])->execute();
$db->createCommand()->insert('testAlterTable', ['bar' => 1])->execute();
$db->createCommand()->alterColumn('testAlterTable', 'bar', Schema::TYPE_STRING)->execute();
$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);
}
}

Loading…
Cancel
Save