Commit cd5bdd90 by Carsten Brandt

fixed postgres tests

parent c6f711cc
......@@ -4,6 +4,7 @@
* and create an account 'postgres/postgres' which owns this test database.
*/
DROP TABLE IF EXISTS "composite_fk" CASCADE;
DROP TABLE IF EXISTS "order_item" CASCADE;
DROP TABLE IF EXISTS "item" CASCADE;
DROP TABLE IF EXISTS "order_item_with_null_fk" CASCADE;
......@@ -78,6 +79,14 @@ CREATE TABLE "order_item_with_null_fk" (
subtotal decimal(10,0) NOT NULL
);
CREATE TABLE "composite_fk" (
id integer NOT NULL,
order_id integer NOT NULL,
item_id integer NOT NULL,
PRIMARY KEY (id),
CONSTRAINT FK_composite_fk_order_item FOREIGN KEY (order_id, item_id) REFERENCES "order_item" (order_id, item_id) ON DELETE CASCADE
);
CREATE TABLE "null_values" (
id INT NOT NULL,
var1 INT NULL,
......@@ -101,7 +110,7 @@ CREATE TABLE "type" (
bool_col smallint NOT NULL,
bool_col2 smallint DEFAULT '1',
ts_default TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
bit_col BIT NOT NULL DEFAULT B'10000010'
bit_col BIT(8) NOT NULL DEFAULT B'10000010'
);
INSERT INTO "profile" (description) VALUES ('profile customer 1');
......
......@@ -14,8 +14,8 @@ use yii\db\BatchQueryResult;
use yiiunit\data\ar\Customer;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @group db
* @group mysql
*/
class BatchQueryResultTest extends DatabaseTestCase
{
......
......@@ -159,7 +159,7 @@ class CommandTest extends DatabaseTestCase
$sql = 'INSERT INTO type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, :blob_col, :numeric_col, :bool_col)';
$command = $db->createCommand($sql);
$intCol = 123;
$charCol = 'abc';
$charCol = str_repeat('abc', 33) . 'x'; // a 100 char string
$floatCol = 1.23;
$blobCol = "\x10\x11\x12";
$numericCol = '1.23';
......@@ -172,13 +172,21 @@ class CommandTest extends DatabaseTestCase
$command->bindParam(':bool_col', $boolCol);
$this->assertEquals(1, $command->execute());
$sql = 'SELECT * FROM type';
$row = $db->createCommand($sql)->queryOne();
$command = $db->createCommand('SELECT int_col, char_col, float_col, blob_col, numeric_col, bool_col FROM type');
// $command->prepare();
// $command->pdoStatement->bindColumn('blob_col', $bc, \PDO::PARAM_LOB);
$row = $command->queryOne();
$this->assertEquals($intCol, $row['int_col']);
$this->assertEquals($charCol, $row['char_col']);
$this->assertEquals($floatCol, $row['float_col']);
$this->assertEquals($blobCol, $row['blob_col']);
if ($this->driverName === 'mysql' || $this->driverName === 'sqlite') {
$this->assertEquals($blobCol, $row['blob_col']);
} else {
$this->assertTrue(is_resource($row['blob_col']));
$this->assertEquals($blobCol, stream_get_contents($row['blob_col']));
}
$this->assertEquals($numericCol, $row['numeric_col']);
$this->assertEquals($boolCol, $row['bool_col']);
// bindValue
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')';
......
......@@ -87,7 +87,7 @@ class SchemaTest extends DatabaseTestCase
$schema = $this->getConnection()->schema;
foreach ($values as $value) {
$this->assertEquals($value[1], $schema->getPdoType($value[0]));
$this->assertEquals($value[1], $schema->getPdoType($value[0]), 'type for value ' . print_r($value[0], true) . ' does not match.');
}
fclose($fp);
}
......
......@@ -3,6 +3,10 @@ namespace yii\tests\unit\framework\db\pgsql;
use yiiunit\framework\db\CommandTest;
/**
* @group db
* @group pgsql
*/
class PostgreSQLCommandTest extends CommandTest
{
public $driverName = 'pgsql';
......@@ -15,9 +19,4 @@ class PostgreSQLCommandTest extends CommandTest
$command = $db->createCommand($sql);
$this->assertEquals('SELECT "id", "t"."name" FROM "customer" t', $command->sql);
}
public function testBindParamValue()
{
$this->markTestIncomplete('TODO: impement it');
}
}
\ No newline at end of file
}
\ No newline at end of file
......@@ -53,8 +53,31 @@ class PostgreSQLSchemaTest extends SchemaTest
$columns['bool_col2']['scale'] = 0;
$columns['ts_default']['defaultValue'] = new Expression('now()');
$columns['bit_col']['dbType'] = 'bit';
$columns['bit_col']['size'] = 1; // TODO should be 8???
$columns['bit_col']['size'] = 8;
$columns['bit_col']['precision'] = null;
return $columns;
}
public function testGetPDOType()
{
$values = [
[null, \PDO::PARAM_NULL],
['', \PDO::PARAM_STR],
['hello', \PDO::PARAM_STR],
[0, \PDO::PARAM_INT],
[1, \PDO::PARAM_INT],
[1337, \PDO::PARAM_INT],
[true, \PDO::PARAM_INT],
[false, \PDO::PARAM_INT],
[$fp = fopen(__FILE__, 'rb'), \PDO::PARAM_LOB],
];
/* @var $schema Schema */
$schema = $this->getConnection()->schema;
foreach ($values as $value) {
$this->assertEquals($value[1], $schema->getPdoType($value[0]));
}
fclose($fp);
}
}
......@@ -84,6 +84,9 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
public function testBatchInsert()
{
if (version_compare(\SQLite3::version()['versionString'], '3.7.11', '>=')) {
$this->markTestSkipped('This test is only relevant for SQLite < 3.7.11');
}
$sql = $this->getQueryBuilder()->batchInsert('{{customer}} t', ['t.id', 't.name'], [[1, 'a'], [2, 'b']]);
$this->assertEquals("INSERT INTO {{customer}} t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION SELECT 2, 'b'", $sql);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment