summaryrefslogtreecommitdiff
path: root/tests/unit/Data/DbCommon
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2016-03-29 09:24:08 +0200
committerFabio Bas <ctrlaltca@gmail.com>2016-03-29 09:24:08 +0200
commit70e305a918fcf193009831d4e89aa8c386df3dc4 (patch)
tree8cc49f253f29636ddd623aa2c2b98835300604f0 /tests/unit/Data/DbCommon
parent55df8dac44f54a305e8bd7e50ef63f76725d2333 (diff)
Ported / fixed most old tests
Diffstat (limited to 'tests/unit/Data/DbCommon')
-rw-r--r--tests/unit/Data/DbCommon/CommandBuilderMssqlTest.php10
-rw-r--r--tests/unit/Data/DbCommon/CommandBuilderMysqlTest.php20
-rw-r--r--tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php23
-rw-r--r--tests/unit/Data/DbCommon/MssqlColumnTest.php9
-rw-r--r--tests/unit/Data/DbCommon/Mysql4ColumnTest.php255
-rw-r--r--tests/unit/Data/DbCommon/MysqlColumnTest.php19
-rw-r--r--tests/unit/Data/DbCommon/PgsqlColumnTest.php21
7 files changed, 59 insertions, 298 deletions
diff --git a/tests/unit/Data/DbCommon/CommandBuilderMssqlTest.php b/tests/unit/Data/DbCommon/CommandBuilderMssqlTest.php
index 893a8ca6..7e2024d5 100644
--- a/tests/unit/Data/DbCommon/CommandBuilderMssqlTest.php
+++ b/tests/unit/Data/DbCommon/CommandBuilderMssqlTest.php
@@ -22,24 +22,24 @@ class CommandBuilderMssqlTest extends PHPUnit_Framework_TestCase
$sql = $builder->applyLimitOffset(self::$sql['simple'], 3);
$expect = 'SELECT TOP 3 username, age FROM accounts';
- $this->assertEqual($expect, $sql);
+ $this->assertEquals($expect, $sql);
$sql = $builder->applyLimitOffset(self::$sql['simple'], 3, 2);
$expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 username, age FROM accounts) as [__inner top table__] ) as [__outer top table__] ';
- $this->assertEqual($expect, $sql);
+ $this->assertEquals($expect, $sql);
$sql = $builder->applyLimitOffset(self::$sql['multiple'], 3, 2);
$expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 a.username, b.name from accounts a, table1 b where a.age = b.id1) as [__inner top table__] ) as [__outer top table__] ';
- $this->assertEqual($sql, $expect);
+ $this->assertEquals($sql, $expect);
$sql = $builder->applyLimitOffset(self::$sql['ordering'], 3, 2);
$expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 a.username, b.name, a.age from accounts a, table1 b where a.age = b.id1 order by age DESC, name) as [__inner top table__] ORDER BY age ASC, name DESC) as [__outer top table__] ORDER BY age DESC, name ASC';
- $this->assertEqual($sql, $expect);
+ $this->assertEquals($sql, $expect);
$sql = $builder->applyLimitOffset(self::$sql['index'], 3, 2);
$expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 a.username, b.name, a.age from accounts a, table1 b where a.age = b.id1 ORDER BY 1 DESC, 2 ASC) as [__inner top table__] ORDER BY 1 ASC, 2 DESC) as [__outer top table__] ORDER BY 1 DESC, 2 ASC';
- $this->assertEqual($expect, $sql);
+ $this->assertEquals($expect, $sql);
// $sql = $builder->applyLimitOffset(self::$sql['compute'], 3, 2);
// var_dump($sql);
diff --git a/tests/unit/Data/DbCommon/CommandBuilderMysqlTest.php b/tests/unit/Data/DbCommon/CommandBuilderMysqlTest.php
deleted file mode 100644
index 77e58019..00000000
--- a/tests/unit/Data/DbCommon/CommandBuilderMysqlTest.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-Prado::using('System.Data.*');
-Prado::using('System.Data.Common.Mysql.TMysqlMetaData');
-
-/**
- * @package System.Data.DbCommon
- */
-class CommandBuilderMysqlTest extends PHPUnit_Framework_TestCase
-{
- function mysql_meta_data()
- {
- $conn = new TDbConnection('mysql:host=localhost;dbname=tests;port=3307', 'test5','test5');
- return new TMysqlMetaData($conn);
- }
-
- function test()
- {
- $this->mysql_meta_data()->getTableInfo("tests.table1");
- }
-}
diff --git a/tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php b/tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php
index 389ad0e1..bb5ebfa8 100644
--- a/tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php
+++ b/tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php
@@ -7,9 +7,18 @@ Prado::using('System.Data.Common.Pgsql.TPgsqlMetaData');
*/
class CommandBuilderPgsqlTest extends PHPUnit_Framework_TestCase
{
+ protected function setUp()
+ {
+ if (!extension_loaded('pgsql')) {
+ $this->markTestSkipped(
+ 'The pgsql extension is not available.'
+ );
+ }
+ }
+
function pgsql_meta_data()
{
- $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest');
return new TPgsqlMetaData($conn);
}
@@ -32,7 +41,7 @@ class CommandBuilderPgsqlTest extends PHPUnit_Framework_TestCase
);
$insert = $builder->createInsertCommand($address);
$sql = 'INSERT INTO public.address("username", "phone", "field1_boolean", "field2_date", "field3_double", "field4_integer", "field6_time", "field7_timestamp", "field8_money", "field9_numeric", "int_fk1", "int_fk2") VALUES (:username, :phone, :field1_boolean, :field2_date, :field3_double, :field4_integer, :field6_time, :field7_timestamp, :field8_money, :field9_numeric, :int_fk1, :int_fk2)';
- $this->assertEqual($sql, $insert->Text);
+ $this->assertEquals($sql, $insert->Text);
}
function test_update_command()
@@ -44,7 +53,7 @@ class CommandBuilderPgsqlTest extends PHPUnit_Framework_TestCase
);
$update = $builder->createUpdateCommand($data, '1');
$sql = 'UPDATE public.address SET "phone" = :phone, "int_fk1" = :int_fk1 WHERE 1';
- $this->assertEqual($sql, $update->Text);
+ $this->assertEquals($sql, $update->Text);
}
function test_delete_command()
@@ -53,7 +62,7 @@ class CommandBuilderPgsqlTest extends PHPUnit_Framework_TestCase
$where = 'phone is NULL';
$delete = $builder->createDeleteCommand($where);
$sql = 'DELETE FROM public.address WHERE phone is NULL';
- $this->assertEqual($sql, $delete->Text);
+ $this->assertEquals($sql, $delete->Text);
}
function test_select_limit()
@@ -64,14 +73,14 @@ class CommandBuilderPgsqlTest extends PHPUnit_Framework_TestCase
$limit = $builder->applyLimitOffset($query, 1);
$expect = $query.' LIMIT 1';
- $this->assertEqual($expect, $limit);
+ $this->assertEquals($expect, $limit);
$limit = $builder->applyLimitOffset($query, -1, 10);
$expect = $query.' OFFSET 10';
- $this->assertEqual($expect, $limit);
+ $this->assertEquals($expect, $limit);
$limit = $builder->applyLimitOffset($query, 2, 3);
$expect = $query.' LIMIT 2 OFFSET 3';
- $this->assertEqual($expect, $limit);
+ $this->assertEquals($expect, $limit);
}
}
diff --git a/tests/unit/Data/DbCommon/MssqlColumnTest.php b/tests/unit/Data/DbCommon/MssqlColumnTest.php
index e4196fcf..2f7119ac 100644
--- a/tests/unit/Data/DbCommon/MssqlColumnTest.php
+++ b/tests/unit/Data/DbCommon/MssqlColumnTest.php
@@ -9,6 +9,15 @@ Prado::using('System.Data.DataGateway.TTableGateway');
*/
class MssqlColumnTest extends PHPUnit_Framework_TestCase
{
+ protected function setUp()
+ {
+ if (!extension_loaded('mssql')) {
+ $this->markTestSkipped(
+ 'The pgsql extension is not available.'
+ );
+ }
+ }
+
function get_conn()
{
return new TDbConnection('mssql:host=localhost\\sqlexpress', 'test', 'test01');
diff --git a/tests/unit/Data/DbCommon/Mysql4ColumnTest.php b/tests/unit/Data/DbCommon/Mysql4ColumnTest.php
deleted file mode 100644
index 74606452..00000000
--- a/tests/unit/Data/DbCommon/Mysql4ColumnTest.php
+++ /dev/null
@@ -1,255 +0,0 @@
-<?php
-Prado::using('System.Data.*');
-Prado::using('System.Data.Common.Mysql.TMysqlMetaData');
-
-/**
- * @package System.Data.DbCommon
- */
-class Mysql4ColumnTest extends PHPUnit_Framework_TestCase
-{
- function create_meta_data()
- {
- $conn = new TDbConnection('mysql:host=localhost;dbname=tests;port=3306', 'test4','test4');
- return new TMysqlMetaData($conn);
- }
-
- function test_columns()
- {
- $table = $this->create_meta_data()->getTableInfo('table1');
- $this->assertEqual(count($table->getColumns()), 18);
-
- $columns['id'] = array(
- 'ColumnName' => '`id`',
- 'ColumnSize' => 10,
- 'ColumnIndex' => 0,
- 'DbType' => 'int unsigned',
- 'AllowNull' => false,
- 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => true,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => true,
- );
-
- $columns['name'] = array(
- 'ColumnName' => '`name`',
- 'ColumnSize' => 45,
- 'ColumnIndex' => 1,
- 'DbType' => 'varchar',
- 'AllowNull' => false,
- 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => true,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field1'] = array(
- 'ColumnName' => '`field1`',
- 'ColumnSize' => 4,
- 'ColumnIndex' => 2,
- 'DbType' => 'tinyint',
- 'AllowNull' => false,
- 'DefaultValue' => '0',
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field2_text'] = array(
- 'ColumnName' => '`field2_text`',
- 'ColumnSize' => null,
- 'ColumnIndex' => 3,
- 'DbType' => 'text',
- 'AllowNull' => true,
- 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field3_date'] = array(
- 'ColumnName' => '`field3_date`',
- 'ColumnSize' => null,
- 'ColumnIndex' => 4,
- 'DbType' => 'date',
- 'AllowNull' => true,
- 'DefaultValue' => '2007-02-25',
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field4_float'] = array(
- 'ColumnName' => '`field4_float`',
- 'ColumnSize' => null,
- 'ColumnIndex' => 5,
- 'DbType' => 'float',
- 'AllowNull' => false,
- 'DefaultValue' => 10,
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field5_float'] = array(
- 'ColumnName' => '`field5_float`',
- 'ColumnSize' => null,
- 'ColumnIndex' => 6,
- 'DbType' => 'float',
- 'AllowNull' => false,
- 'DefaultValue' => '0.0000',
- 'NumericPrecision' => 5,
- 'NumericScale' => 4,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field6_double'] = array(
- 'ColumnName' => '`field6_double`',
- 'ColumnSize' => null,
- 'ColumnIndex' => 7,
- 'DbType' => 'double',
- 'AllowNull' => false,
- 'DefaultValue' => '0',
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field7_datetime'] = array(
- 'ColumnName' => '`field7_datetime`',
- 'ColumnSize' => null,
- 'ColumnIndex' => 8,
- 'DbType' => 'datetime',
- 'AllowNull' => false,
- 'DefaultValue' => '0000-00-00 00:00:00',
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field8_timestamp'] = array(
- 'ColumnName' => '`field8_timestamp`',
- 'ColumnSize' => null,
- 'ColumnIndex' => 9,
- 'DbType' => 'timestamp',
- 'AllowNull' => true,
- 'DefaultValue' => 'CURRENT_TIMESTAMP',
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field9_time'] = array(
- 'ColumnName' => '`field9_time`',
- 'ColumnSize' => null,
- 'ColumnIndex' => 10,
- 'DbType' => 'time',
- 'AllowNull' => false,
- 'DefaultValue' => '00:00:00',
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field10_year'] = array(
- 'ColumnName' => '`field10_year`',
- 'ColumnSize' => 4,
- 'ColumnIndex' => 11,
- 'DbType' => 'year',
- 'AllowNull' => false,
- 'DefaultValue' => '0000',
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- );
-
- $columns['field11_enum'] = array(
- 'ColumnName' => '`field11_enum`',
- 'ColumnSize' => null,
- 'ColumnIndex' => 12,
- 'DbType' => 'enum',
- 'AllowNull' => false,
- 'DefaultValue' => 'one',
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- 'DbTypeValues' => array('one', 'two', 'three'),
- );
-
- $columns['field12_SET'] = array(
- 'ColumnName' => '`field12_SET`',
- 'ColumnSize' => null,
- 'ColumnIndex' => 13,
- 'DbType' => 'set',
- 'AllowNull' => false,
- 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
- 'NumericPrecision' => null,
- 'NumericScale' => null,
- 'IsPrimaryKey' => false,
- 'IsForeignKey' => false,
- 'SequenceName' => null,
- 'AutoIncrement' => false,
- 'DbTypeValues' => array('blue', 'red', 'green'),
- );
-
- $this->assertColumn($columns, $table);
-
- $this->assertNull($table->getSchemaName());
- $this->assertEqual('table1', $table->getTableName());
- $this->assertEqual(array('id', 'name'), $table->getPrimaryKeys());
- }
-
- function assertColumn($columns, $table)
- {
- foreach($columns as $id=>$asserts)
- {
- $column = $table->Columns[$id];
- foreach($asserts as $property=>$assert)
- {
- $ofAssert= var_export($assert,true);
- $value = $column->{$property};
- $ofValue = var_export($value, true);
- $this->assertEqual($value, $assert,
- "Column [{$id}] {$property} value {$ofValue} did not match {$ofAssert}");
- }
- }
- }
-}
diff --git a/tests/unit/Data/DbCommon/MysqlColumnTest.php b/tests/unit/Data/DbCommon/MysqlColumnTest.php
index 3bdfe54f..88b1bb53 100644
--- a/tests/unit/Data/DbCommon/MysqlColumnTest.php
+++ b/tests/unit/Data/DbCommon/MysqlColumnTest.php
@@ -7,16 +7,25 @@ Prado::using('System.Data.Common.Mysql.TMysqlMetaData');
*/
class MysqlColumnTest extends PHPUnit_Framework_TestCase
{
+ protected function setUp()
+ {
+ if (!extension_loaded('mysql')) {
+ $this->markTestSkipped(
+ 'The mysql extension is not available.'
+ );
+ }
+ }
+
function create_meta_data()
{
- $conn = new TDbConnection('mysql:host=localhost;dbname=tests;port=3307', 'test5','test5');
+ $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest');
return new TMysqlMetaData($conn);
}
function test_columns()
{
$table = $this->create_meta_data()->getTableInfo('table1');
- $this->assertEqual(count($table->getColumns()), 18);
+ $this->assertEquals(count($table->getColumns()), 18);
$columns['id'] = array(
'ColumnName' => '`id`',
@@ -233,8 +242,8 @@ class MysqlColumnTest extends PHPUnit_Framework_TestCase
$this->assertColumn($columns, $table);
$this->assertNull($table->getSchemaName());
- $this->assertEqual('table1', $table->getTableName());
- $this->assertEqual(array('id', 'name'), $table->getPrimaryKeys());
+ $this->assertEquals('table1', $table->getTableName());
+ $this->assertEquals(array('id', 'name'), $table->getPrimaryKeys());
}
function assertColumn($columns, $table)
@@ -247,7 +256,7 @@ class MysqlColumnTest extends PHPUnit_Framework_TestCase
$ofAssert= var_export($assert,true);
$value = $column->{$property};
$ofValue = var_export($value, true);
- $this->assertEqual($value, $assert,
+ $this->assertEquals($value, $assert,
"Column [{$id}] {$property} value {$ofValue} did not match {$ofAssert}");
}
}
diff --git a/tests/unit/Data/DbCommon/PgsqlColumnTest.php b/tests/unit/Data/DbCommon/PgsqlColumnTest.php
index 7d7f1177..24e7b49b 100644
--- a/tests/unit/Data/DbCommon/PgsqlColumnTest.php
+++ b/tests/unit/Data/DbCommon/PgsqlColumnTest.php
@@ -8,16 +8,25 @@ Prado::using('System.Data.Common.Pgsql.TPgsqlMetaData');
*/
class PgsqlColumnTest extends PHPUnit_Framework_TestCase
{
+ protected function setUp()
+ {
+ if (!extension_loaded('pgsql')) {
+ $this->markTestSkipped(
+ 'The pgsql extension is not available.'
+ );
+ }
+ }
+
function create_meta_data()
{
- $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest');
return new TPgsqlMetaData($conn);
}
function test_text_column_def()
{
$table = $this->create_meta_data()->getTableInfo('public.address');
- $this->assertEqual(count($table->getColumns()), 14);
+ $this->assertEquals(count($table->getColumns()), 14);
$columns['id'] = array(
'ColumnName' => '"id"',
@@ -118,9 +127,9 @@ class PgsqlColumnTest extends PHPUnit_Framework_TestCase
);
$this->assertColumn($columns, $table);
- $this->assertEqual('public', $table->getSchemaName());
- $this->assertEqual('address', $table->getTableName());
- $this->assertEqual(array('id'), $table->getPrimaryKeys());
+ $this->assertEquals('public', $table->getSchemaName());
+ $this->assertEquals('address', $table->getTableName());
+ $this->assertEquals(array('id'), $table->getPrimaryKeys());
}
function assertColumn($columns, $table)
@@ -133,7 +142,7 @@ class PgsqlColumnTest extends PHPUnit_Framework_TestCase
$ofAssert= var_export($assert,true);
$value = $column->{$property};
$ofValue = var_export($value, true);
- $this->assertEqual($value, $assert,
+ $this->assertEquals($value, $assert,
"Column [{$id}] {$property} value {$ofValue} did not match {$ofAssert}");
}
}