Skip to content

Commit

Permalink
Merge pull request yiisoft#8441 from nineinchnick/oracle_unit_tests
Browse files Browse the repository at this point in the history
Oracle unit tests
  • Loading branch information
samdark committed May 16, 2015
2 parents 7a89457 + 94acb2e commit ea560cb
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/framework/db/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ public function testIntegrityViolation()
$command->execute();
}

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

$sql = 'INSERT INTO {{profile}}([[description]]) VALUES (\'non duplicate\')';
$command = $db->createCommand($sql);
$command->execute();
$this->assertEquals(3, $db->getSchema()->getLastInsertID());
}

public function testQueryCache()
{
$db = $this->getConnection();
Expand Down
5 changes: 4 additions & 1 deletion tests/framework/db/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use yii\db\mssql\QueryBuilder as MssqlQueryBuilder;
use yii\db\pgsql\QueryBuilder as PgsqlQueryBuilder;
use yii\db\cubrid\QueryBuilder as CubridQueryBuilder;
use yii\db\oci\QueryBuilder as OracleQueryBuilder;

/**
* @group db
Expand All @@ -35,6 +36,8 @@ protected function getQueryBuilder()
return new PgsqlQueryBuilder($this->getConnection(true, false));
case 'cubrid':
return new CubridQueryBuilder($this->getConnection(true, false));
case 'oci':
return new OracleQueryBuilder($this->getConnection(true, false));
}
throw new \Exception('Test is not implemented for ' . $this->driverName);
}
Expand Down Expand Up @@ -144,7 +147,7 @@ public function testCreateTableColumnTypes()
foreach ($this->columnTypes() as $item) {
list ($column, $expected) = $item;
if (strncmp($column, 'pk', 2) !== 0) {
$columns['col' . ++$i] = str_replace('CHECK (value', 'CHECK (col' . $i, $column);
$columns['col' . ++$i] = str_replace('CHECK (value', 'CHECK ([[col' . $i . ']]', $column);
}
}
$this->getConnection(false)->createCommand($qb->createTable('column_type_table', $columns))->execute();
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/db/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function testCount()
$count = (new Query)->from('customer')->where(['status' => 2])->count('*', $db);
$this->assertEquals(1, $count);

$count = (new Query)->select('status, COUNT(id)')->from('customer')->groupBy('status')->count('*', $db);
$count = (new Query)->select('[[status]], COUNT([[id]])')->from('customer')->groupBy('status')->count('*', $db);
$this->assertEquals(2, $count);
}

Expand Down
10 changes: 10 additions & 0 deletions tests/framework/db/oci/OracleCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ public function testAutoQuoting()
$command = $db->createCommand($sql);
$this->assertEquals('SELECT "id", "t"."name" FROM "customer" t', $command->sql);
}

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

$sql = 'INSERT INTO {{profile}}([[description]]) VALUES (\'non duplicate\')';
$command = $db->createCommand($sql);
$command->execute();
$this->assertEquals(3, $db->getSchema()->getLastInsertID('profile_SEQ'));
}
}
87 changes: 87 additions & 0 deletions tests/framework/db/oci/OracleQueryBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace yiiunit\framework\db\oci;

use yii\db\oci\Schema;
use yiiunit\framework\db\QueryBuilderTest;

/**
* @group db
* @group oci
*/
class OracleQueryBuilderTest extends QueryBuilderTest
{
public $driverName = 'oci';

/**
* this is not used as a dataprovider for testGetColumnType to speed up the test
* when used as dataprovider every single line will cause a reconnect with the database which is not needed here
*/
public function columnTypes()
{
return [
[Schema::TYPE_PK, 'NUMBER(10) NOT NULL PRIMARY KEY'],
[Schema::TYPE_PK . '(8)', 'NUMBER(8) NOT NULL PRIMARY KEY'],
[Schema::TYPE_PK . ' CHECK (value > 5)', 'NUMBER(10) NOT NULL PRIMARY KEY CHECK (value > 5)'],
[Schema::TYPE_PK . '(8) CHECK (value > 5)', 'NUMBER(8) NOT NULL PRIMARY KEY CHECK (value > 5)'],
[Schema::TYPE_STRING, 'VARCHAR2(255)'],
[Schema::TYPE_STRING . '(32)', 'VARCHAR2(32)'],
[Schema::TYPE_STRING . ' CHECK (value LIKE \'test%\')', 'VARCHAR2(255) CHECK (value LIKE \'test%\')'],
[Schema::TYPE_STRING . '(32) CHECK (value LIKE \'test%\')', 'VARCHAR2(32) CHECK (value LIKE \'test%\')'],
[Schema::TYPE_STRING . ' NOT NULL', 'VARCHAR2(255) NOT NULL'],
[Schema::TYPE_TEXT, 'CLOB'],
[Schema::TYPE_TEXT . '(255)', 'CLOB'],
[Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')', 'CLOB CHECK (value LIKE \'test%\')'],
[Schema::TYPE_TEXT . '(255) CHECK (value LIKE \'test%\')', 'CLOB CHECK (value LIKE \'test%\')'],
[Schema::TYPE_TEXT . ' NOT NULL', 'CLOB NOT NULL'],
[Schema::TYPE_TEXT . '(255) NOT NULL', 'CLOB NOT NULL'],
[Schema::TYPE_SMALLINT, 'NUMBER(5)'],
[Schema::TYPE_SMALLINT . '(8)', 'NUMBER(8)'],
[Schema::TYPE_INTEGER, 'NUMBER(10)'],
[Schema::TYPE_INTEGER . '(8)', 'NUMBER(8)'],
[Schema::TYPE_INTEGER . ' CHECK (value > 5)', 'NUMBER(10) CHECK (value > 5)'],
[Schema::TYPE_INTEGER . '(8) CHECK (value > 5)', 'NUMBER(8) CHECK (value > 5)'],
[Schema::TYPE_INTEGER . ' NOT NULL', 'NUMBER(10) NOT NULL'],
[Schema::TYPE_BIGINT, 'NUMBER(20)'],
[Schema::TYPE_BIGINT . '(8)', 'NUMBER(8)'],
[Schema::TYPE_BIGINT . ' CHECK (value > 5)', 'NUMBER(20) CHECK (value > 5)'],
[Schema::TYPE_BIGINT . '(8) CHECK (value > 5)', 'NUMBER(8) CHECK (value > 5)'],
[Schema::TYPE_BIGINT . ' NOT NULL', 'NUMBER(20) NOT NULL'],
[Schema::TYPE_FLOAT, 'NUMBER'],
[Schema::TYPE_FLOAT . '(16,5)', 'NUMBER'],
[Schema::TYPE_FLOAT . ' CHECK (value > 5.6)', 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_FLOAT . '(16,5) CHECK (value > 5.6)', 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_FLOAT . ' NOT NULL', 'NUMBER NOT NULL'],
[Schema::TYPE_DOUBLE, 'NUMBER'],
[Schema::TYPE_DOUBLE . '(16,5)', 'NUMBER'],
[Schema::TYPE_DOUBLE . ' CHECK (value > 5.6)', 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . '(16,5) CHECK (value > 5.6)', 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . ' NOT NULL', 'NUMBER NOT NULL'],
[Schema::TYPE_DECIMAL, 'NUMBER'],
[Schema::TYPE_DECIMAL . '(12,4)', 'NUMBER'],
[Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)', 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)', 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . ' NOT NULL', 'NUMBER NOT NULL'],
[Schema::TYPE_DATETIME, 'TIMESTAMP'],
//[Schema::TYPE_DATETIME . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", "TIMESTAMP CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATETIME . ' NOT NULL', 'TIMESTAMP NOT NULL'],
[Schema::TYPE_TIMESTAMP, 'TIMESTAMP'],
//[Schema::TYPE_TIMESTAMP . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", "TIMESTAMP CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_TIMESTAMP . ' NOT NULL', 'TIMESTAMP NOT NULL'],
[Schema::TYPE_TIME, 'TIMESTAMP'],
//[Schema::TYPE_TIME . " CHECK (value BETWEEN '12:00:00' AND '13:01:01')", "TIMESTAMP CHECK (value BETWEEN '12:00:00' AND '13:01:01')"],
[Schema::TYPE_TIME . ' NOT NULL', 'TIMESTAMP NOT NULL'],
[Schema::TYPE_DATE, 'DATE'],
//[Schema::TYPE_DATE . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", "DATE CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATE . ' NOT NULL', 'DATE NOT NULL'],
[Schema::TYPE_BINARY, 'BLOB'],
[Schema::TYPE_BOOLEAN, 'NUMBER(1)'],
[Schema::TYPE_BOOLEAN . ' DEFAULT 1 NOT NULL', 'NUMBER(1) DEFAULT 1 NOT NULL'],
[Schema::TYPE_MONEY, 'NUMBER(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', 'NUMBER(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', 'NUMBER(19,4) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', 'NUMBER(16,2) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . ' NOT NULL', 'NUMBER(19,4) NOT NULL'],
];
}
}
10 changes: 10 additions & 0 deletions tests/framework/db/pgsql/PostgreSQLCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ public function testBooleanValuesBatchInsert()
$command = $db->createCommand('SELECT COUNT(*) FROM "bool_values" WHERE bool_col = FALSE;');
$this->assertEquals(1, $command->queryScalar());
}

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

$sql = 'INSERT INTO {{profile}}([[description]]) VALUES (\'non duplicate\')';
$command = $db->createCommand($sql);
$command->execute();
$this->assertEquals(3, $db->getSchema()->getLastInsertID('profile_id_seq'));
}
}

0 comments on commit ea560cb

Please sign in to comment.