From 8abeed03bd827a3684350f4775a23f5e92e7c317 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 6 Sep 2013 15:03:57 +0200 Subject: [PATCH] added SchemaTest --- framework/yii/db/cubrid/Schema.php | 2 +- tests/unit/framework/db/SchemaTest.php | 70 ++++++++++++++++++++++ .../unit/framework/db/cubrid/CubridSchemaTest.php | 31 ++++++++++ .../unit/framework/db/sqlite/SqliteSchemaTest.php | 9 +++ 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 tests/unit/framework/db/SchemaTest.php create mode 100644 tests/unit/framework/db/cubrid/CubridSchemaTest.php create mode 100644 tests/unit/framework/db/sqlite/SqliteSchemaTest.php diff --git a/framework/yii/db/cubrid/Schema.php b/framework/yii/db/cubrid/Schema.php index d1fdc10..d221073 100644 --- a/framework/yii/db/cubrid/Schema.php +++ b/framework/yii/db/cubrid/Schema.php @@ -227,7 +227,7 @@ class Schema extends \yii\db\Schema $tableNames = array(); foreach($tables as $table) { // do not list system tables - if ($table['TYPE'] !== 0) { + if ($table['TYPE'] != 0) { $tableNames[] = $table['NAME']; } } diff --git a/tests/unit/framework/db/SchemaTest.php b/tests/unit/framework/db/SchemaTest.php new file mode 100644 index 0000000..66aa410 --- /dev/null +++ b/tests/unit/framework/db/SchemaTest.php @@ -0,0 +1,70 @@ +getConnection()->schema; + + foreach($values as $value) { + $this->assertEquals($value[1], $schema->getPdoType($value[0])); + } + fclose($fp); + } + + public function testFindTableNames() + { + /** @var Schema $schema */ + $schema = $this->getConnection()->schema; + + $tables = $schema->getTableNames(); + $this->assertTrue(in_array('tbl_customer', $tables)); + $this->assertTrue(in_array('tbl_category', $tables)); + $this->assertTrue(in_array('tbl_item', $tables)); + $this->assertTrue(in_array('tbl_order', $tables)); + $this->assertTrue(in_array('tbl_order_item', $tables)); + $this->assertTrue(in_array('tbl_type', $tables)); + } + + public function testGetTableSchemas() + { + /** @var Schema $schema */ + $schema = $this->getConnection()->schema; + + $tables = $schema->getTableSchemas(); + $this->assertEquals(count($schema->getTableNames()), count($tables)); + foreach($tables as $table) { + $this->assertInstanceOf('yii\db\TableSchema', $table); + } + } + + public function testSchemaCache() + { + /** @var Schema $schema */ + $schema = $this->getConnection()->schema; + + $schema->db->enableSchemaCache = true; + $schema->db->schemaCache = new FileCache(); + $noCacheTable = $schema->getTableSchema('tbl_type', true); + $cachedTable = $schema->getTableSchema('tbl_type', true); + $this->assertEquals($noCacheTable, $cachedTable); + } +} diff --git a/tests/unit/framework/db/cubrid/CubridSchemaTest.php b/tests/unit/framework/db/cubrid/CubridSchemaTest.php new file mode 100644 index 0000000..d235b40 --- /dev/null +++ b/tests/unit/framework/db/cubrid/CubridSchemaTest.php @@ -0,0 +1,31 @@ + \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, // CUBRID PDO does not support PARAM_BOOL + false => \PDO::PARAM_INT, // CUBRID PDO does not support PARAM_BOOL + ); + + $schema = $this->getConnection()->schema; + + foreach($values as $value => $type) { + $this->assertEquals($type, $schema->getPdoType($value)); + } + $this->assertEquals(\PDO::PARAM_LOB, $schema->getPdoType($fp=fopen(__FILE__, 'rb'))); + fclose($fp); + } +} diff --git a/tests/unit/framework/db/sqlite/SqliteSchemaTest.php b/tests/unit/framework/db/sqlite/SqliteSchemaTest.php new file mode 100644 index 0000000..f3f6b60 --- /dev/null +++ b/tests/unit/framework/db/sqlite/SqliteSchemaTest.php @@ -0,0 +1,9 @@ +