1
0
mirror of synced 2025-01-18 22:41:43 +03:00

[2.0] Fixed DDC-63 and DDC-106. Oracle tests for SchemaManager need further tweeking, marked as skipped for now.

This commit is contained in:
beberlei 2009-11-03 16:56:05 +00:00
parent cfea7883e0
commit a7847952a1
18 changed files with 472 additions and 256 deletions

View File

@ -1362,6 +1362,18 @@ abstract class AbstractPlatform
throw DoctrineException::getDateTypeDeclarationNotSupported($this);
}
/**
* Obtain DBMS specific SQL to be used to create time fields in statements
* like CREATE TABLE.
*
* @param array $fieldDeclaration
* @return string
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
{
throw DoctrineException::getTimeTypeDeclarationNotSupported($this);
}
/**
* Gets the default transaction isolation level of the platform.
*
@ -1577,4 +1589,4 @@ abstract class AbstractPlatform
{
return 'INSERT INTO ' . $tableName . ' (' . $identifierColumnName . ') VALUES (null)';
}
}
}

View File

@ -419,6 +419,22 @@ class MsSqlPlatform extends AbstractPlatform
return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
}
/**
* @override
*/
public function getDateTypeDeclarationSql(array $fieldDeclaration)
{
return 'CHAR(' . strlen('YYYY-MM-DD') . ')';
}
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
{
return 'CHAR(' . strlen('HH:MM:SS') . ')';
}
/**
* @override
*/
@ -536,4 +552,4 @@ class MsSqlPlatform extends AbstractPlatform
{
return 'INSERT INTO ' . $quotedTableName . ' DEFAULT VALUES';
}
}
}

View File

@ -153,6 +153,11 @@ class MySqlPlatform extends AbstractPlatform
return 'SHOW DATABASES';
}
public function getListFunctionsSql()
{
return 'SELECT SPECIFIC_NAME FROM information_schema.ROUTINES';
}
public function getListSequencesSql($database)
{
$query = 'SHOW TABLES';
@ -177,13 +182,22 @@ class MySqlPlatform extends AbstractPlatform
return "SELECT * FROM mysql.user WHERE user != '' GROUP BY user";
}
public function getListTriggersSql($table = null)
{
$sql = "SELECT TRIGGER_NAME FROM information_schema.TRIGGERS";
if($table !== null) {
$sql .= " WHERE EVENT_OBJECT_TABLE = '".$table."'";
}
return $sql;
}
public function getListViewsSql($database = null)
{
if (is_null($database)) {
return 'SELECT * FROM information_schema.VIEWS';
} else {
return "SHOW FULL TABLES FROM " . $database . " WHERE Table_type = 'VIEW'";
$sql = 'SELECT * FROM information_schema.VIEWS';
if($database !== null) {
$sql .= " WHERE TABLE_SCHEMA = '".$database."'";
}
return $sql;
}
public function getListTableForeignKeysSql($table, $database = null)
@ -265,7 +279,7 @@ class MySqlPlatform extends AbstractPlatform
*/
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
{
if ($fieldDeclaration['version']) {
if (isset($fieldDeclaration['version'])) {
return 'TIMESTAMP';
} else {
return 'DATETIME';
@ -280,6 +294,14 @@ class MySqlPlatform extends AbstractPlatform
return 'DATE';
}
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
{
return 'TIME';
}
/**
* @override
*/
@ -846,4 +868,4 @@ class MySqlPlatform extends AbstractPlatform
{
return 'mysql';
}
}
}

View File

@ -194,6 +194,22 @@ class OraclePlatform extends AbstractPlatform
return 'TIMESTAMP(0) WITH TIME ZONE';
}
/**
* @override
*/
public function getDateTypeDeclarationSql(array $fieldDeclaration)
{
return 'DATE';
}
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
{
return 'DATE';
}
/**
* @override
*/
@ -563,4 +579,4 @@ END;';
}
return $schemaElementName;
}
}
}

View File

@ -283,7 +283,7 @@ class PostgreSqlPlatform extends AbstractPlatform
AND tp.typname <> 'trigger'
AND pr.pronamespace IN
(SELECT oid FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema'";
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
}
public function getListSequencesSql($database)
@ -710,6 +710,14 @@ class PostgreSqlPlatform extends AbstractPlatform
return 'DATE';
}
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
{
return 'TIME';
}
/**
* @override
*/
@ -786,4 +794,4 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return 'INSERT INTO ' . $quotedTableName . ' (' . $quotedIdentifierColumnName . ') VALUES (DEFAULT)';
}
}
}

View File

@ -265,6 +265,14 @@ class SqlitePlatform extends AbstractPlatform
return 'DATE';
}
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
{
return 'TIME';
}
/**
* @override
*/
@ -445,4 +453,4 @@ class SqlitePlatform extends AbstractPlatform
{
return 'sqlite';
}
}
}

View File

@ -107,8 +107,11 @@ abstract class AbstractSchemaManager
}
/**
* List the available functions for this connection
* List the names of available functions for this connection
*
* @example array(
* 'functionA', 'functionB', 'procedureA',
* )
* @return array $functions
*/
public function listFunctions()
@ -121,8 +124,11 @@ abstract class AbstractSchemaManager
}
/**
* List the available triggers for this connection
* List the names of available triggers for this connection
*
* @example array(
* 'triggerName1', 'triggerName2',
* );
* @return array $triggers
*/
public function listTriggers()
@ -169,6 +175,28 @@ abstract class AbstractSchemaManager
/**
* List the columns for a given table.
*
* @example array(
* 'colA' => array(
* 'name' => 'colA',
* 'type' => \Doctrine\DBAL\Types\StringType instance,
* 'length' => 255,
* 'precision' => null,
* 'scale' => null,
* 'unsigned' => false,
* 'fixed' => false,
* 'notnull' => false,
* 'default' => null,
* 'platformDetails' => array(),
* ),
* );
*
* In contrast to other libraries and to the old version of Doctrine,
* this column definition does try to contain the 'primary' field for
* the reason that it is not portable accross different RDBMS. Use
* {@see listTableIndexes($tableName)} to retrieve the primary key
* of a table. We're a RDBMS specifies more details these are held
* in the platformDetails array.
*
* @param string $table The name of the table.
* @return array $tableColumns The column descriptions.
*/
@ -249,6 +277,10 @@ abstract class AbstractSchemaManager
/**
* List the views this connection has
*
* @example array(
* array('name' => 'ViewA', 'sql' => 'SELECT * FROM foo'),
* array('name' => 'ViewB', 'sql' => 'SELECT * FROM bar'),
* )
* @return array $views
*/
public function listViews()
@ -896,7 +928,7 @@ abstract class AbstractSchemaManager
if (is_string($value['type'])) {
$value['type'] = \Doctrine\DBAL\Types\Type::getType($value['type']);
}
$list[] = $value;
$list[$value['name']] = $value;
}
}
return $list;

View File

@ -36,7 +36,10 @@ class MySqlSchemaManager extends AbstractSchemaManager
{
protected function _getPortableViewDefinition($view)
{
return $view['TABLE_NAME'];
return array(
'name' => $view['TABLE_NAME'],
'sql' => $view['VIEW_DEFINITION']
);
}
protected function _getPortableTableDefinition($table)
@ -117,9 +120,9 @@ class MySqlSchemaManager extends AbstractSchemaManager
if ( ! isset($tableColumn['name'])) {
$tableColumn['name'] = '';
}
$values = null;
$scale = null;
$precision = null;
// Map db type to Doctrine mapping type
switch ($dbType) {
@ -191,6 +194,11 @@ class MySqlSchemaManager extends AbstractSchemaManager
case 'real':
case 'numeric':
case 'decimal':
if(preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['Type'], $match)) {
$precision = $match[1];
$scale = $match[2];
$length = null;
}
$type = 'decimal';
break;
case 'tinyblob':
@ -230,24 +238,30 @@ class MySqlSchemaManager extends AbstractSchemaManager
'unsigned' => (bool) $unsigned,
'fixed' => (bool) $fixed
);
if ($scale !== null) {
$def['scale'] = $scale;
}
$values = ($values !== null) ? $values : array();
$column = array(
'name' => $tableColumn['Field'],
'values' => $values,
'primary' => (bool) (strtolower($tableColumn['Key']) == 'pri'),
'unique' => (bool) (strtolower($tableColumn['Key']) == 'uni'),
'type' => $type,
'length' => $length,
'unsigned' => (bool)$unsigned,
'fixed' => (bool)$fixed,
'default' => $tableColumn['Default'],
'notnull' => (bool) ($tableColumn['Null'] != 'YES'),
'autoincrement' => (bool) (strpos($tableColumn['Extra'], 'auto_increment') !== false),
'scale' => null,
'precision' => null,
'platformDetails' => array(
'primary' => (strtolower($tableColumn['Key']) == 'pri') ? true : false,
'unique' => (strtolower($tableColumn['Key']) == 'uni') ? true :false,
'autoincrement' => (bool) (strpos($tableColumn['Extra'], 'auto_increment') !== false),
),
);
return array_merge($column, $def);
if ($scale !== null && $precision !== null) {
$column['scale'] = $scale;
$column['precision'] = $precision;
}
return $column;
}
public function _getPortableTableForeignKeyDefinition($tableForeignKey)

View File

@ -34,13 +34,18 @@ class OracleSchemaManager extends AbstractSchemaManager
{
protected function _getPortableViewDefinition($view)
{
$view = \array_change_key_case($view, CASE_LOWER);
return array(
'name' => $view['view_name']
'name' => $view['view_name'],
'sql' => '',
);
}
protected function _getPortableUserDefinition($user)
{
$user = \array_change_key_case($user, CASE_LOWER);
return array(
'user' => $user['username'],
'password' => $user['password']
@ -49,6 +54,8 @@ class OracleSchemaManager extends AbstractSchemaManager
protected function _getPortableTableDefinition($table)
{
$table = \array_change_key_case($table, CASE_LOWER);
return $table['table_name'];
}
@ -61,6 +68,8 @@ class OracleSchemaManager extends AbstractSchemaManager
*/
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
{
$tableIndexes = \array_change_key_case($tableIndexes, CASE_LOWER);
$indexBuffer = array();
foreach ( $tableIndexes as $tableIndex ) {
$keyName = $tableIndex['name'];
@ -82,7 +91,13 @@ class OracleSchemaManager extends AbstractSchemaManager
protected function _getPortableTableColumnDefinition($tableColumn)
{
$tableColumn = \array_change_key_case($tableColumn, CASE_LOWER);
$dbType = strtolower($tableColumn['data_type']);
if(strpos($dbType, "timestamp(") === 0) {
$dbType = "timestamp";
}
$type = array();
$length = $unsigned = $fixed = null;
if ( ! empty($tableColumn['data_length'])) {
@ -97,10 +112,19 @@ class OracleSchemaManager extends AbstractSchemaManager
$tableColumn['data_default'] = null;
}
$precision = null;
$scale = null;
switch ($dbType) {
case 'integer':
case 'number':
$type = 'integer';
if($tableColumn['data_scale'] > 0) {
$type = 'decimal';
$precision = $tableColumn['data_precision'];
$scale = $tableColumn['data_scale'];
} else {
$type = 'integer';
}
$length = null;
break;
case 'pls_integer':
@ -129,6 +153,8 @@ class OracleSchemaManager extends AbstractSchemaManager
$length = null;
break;
case 'float':
$precision = $tableColumn['data_precision'];
$scale = $tableColumn['data_scale'];
$type = 'decimal';
$length = null;
break;
@ -136,6 +162,7 @@ class OracleSchemaManager extends AbstractSchemaManager
$type = 'string';
case 'clob':
case 'nclob':
$length = null;
$type = 'text';
break;
case 'blob':
@ -160,30 +187,34 @@ class OracleSchemaManager extends AbstractSchemaManager
);
return array(
'name' => $tableColumn['column_name'],
'notnull' => (bool) ($tableColumn['nullable'] === 'N'),
'type' => $decl['type'],
'fixed' => (bool) $decl['fixed'],
'unsigned' => (bool) $decl['unsigned'],
'default' => $tableColumn['data_default'],
'length' => $tableColumn['data_length'],
'precision' => $tableColumn['data_precision'],
'scale' => $tableColumn['data_scale'],
'name' => $tableColumn['column_name'],
'notnull' => (bool) ($tableColumn['nullable'] === 'N'),
'type' => $type,
'fixed' => (bool) $fixed,
'unsigned' => (bool) $unsigned,
'default' => $tableColumn['data_default'],
'length' => $length,
'precision' => $precision,
'scale' => $scale,
'platformDetails' => array(),
);
}
protected function _getPortableTableConstraintDefinition($tableConstraint)
{
$tableConstraint = \array_change_key_case($tableConstraint, CASE_LOWER);
return $tableConstraint['constraint_name'];
}
protected function _getPortableFunctionDefinition($function)
{
$function = \array_change_key_case($function, CASE_LOWER);
return $function['name'];
}
protected function _getPortableDatabaseDefinition($database)
{
$database = \array_change_key_case($database, CASE_LOWER);
return $database['username'];
}

View File

@ -54,7 +54,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
protected function _getPortableViewDefinition($view)
{
return array(
'name' => $view['viewname']
'name' => $view['viewname'],
'sql' => $view['definition']
);
}
@ -151,6 +152,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
if ( ! isset($tableColumn['name'])) {
$tableColumn['name'] = '';
}
$precision = null;
$scale = null;
$dbType = strtolower($tableColumn['type']);
@ -228,6 +232,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case 'decimal':
case 'money':
case 'numeric':
if(preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['complete_type'], $match)) {
$precision = $match[1];
$scale = $match[2];
$length = null;
}
$type = 'decimal';
break;
case 'tinyblob':
@ -258,19 +267,20 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$type = 'string';
}
$decl = array(
'type' => $type,
'length' => $length,
'fixed' => $fixed
);
$description = array(
'name' => $tableColumn['field'],
'type' => $type,
'length' => $length,
'notnull' => (bool) $tableColumn['isnotnull'],
'default' => $tableColumn['default'],
'primary' => (bool) ($tableColumn['pri'] == 't'),
'precision' => $precision,
'scale' => $scale,
'fixed' => $fixed,
'unsigned' => false,
'platformDetails' => array(),
);
return array_merge($decl, $description);
return $description;
}
}

View File

@ -146,6 +146,9 @@ class SqliteSchemaManager extends AbstractSchemaManager
$tableColumn['name'] = '';
}
$precision = null;
$scale = null;
switch ($dbType) {
case 'boolean':
$type = 'boolean';
@ -219,6 +222,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
case 'real':
case 'decimal':
case 'numeric':
list($precision, $scale) = array_map('trim', explode(', ', $tableColumn['length']));
$type = 'decimal';
$length = null;
break;
@ -238,13 +242,19 @@ class SqliteSchemaManager extends AbstractSchemaManager
$length = null;
}
return array('name' => $tableColumn['name'],
'primary' => (bool) $tableColumn['pk'],
'type' => $type,
'length' => $length,
'unsigned' => (bool) $unsigned,
'fixed' => $fixed,
'notnull' => $notnull,
'default' => $default);
return array(
'name' => $tableColumn['name'],
'type' => $type,
'length' => $length,
'unsigned' => (bool) $unsigned,
'fixed' => $fixed,
'notnull' => $notnull,
'default' => $default,
'precision' => $precision,
'scale' => $scale,
'platformDetails' => array(
'primary' => (bool) $tableColumn['pk'],
),
);
}
}

View File

@ -24,6 +24,7 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\SqliteSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\PostgreSqlSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\OracleSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\ConnectionTest');
return $suite;

View File

@ -8,29 +8,6 @@ require_once __DIR__ . '/../../../TestInit.php';
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
public function testListDatabases()
{
$this->_sm->dropAndCreateDatabase('test_create_database');
$databases = $this->_sm->listDatabases();
$this->assertEquals(true, in_array('test_create_database', $databases));
}
/**
* @expectedException \Exception
*/
public function testListFunctions()
{
$this->_sm->listFunctions();
}
/**
* @expectedException \Exception
*/
public function testListTriggers()
{
$this->_sm->listTriggers();
}
public function testListSequences()
{
$this->createTestTable('list_sequences_test');
@ -45,38 +22,6 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(array('PRIMARY'), $tableConstraints);
}
public function testListTableColumns()
{
$this->createTestTable('list_tables_test');
$columns = $this->_sm->listTableColumns('list_tables_test');
$this->assertEquals('id', $columns[0]['name']);
$this->assertEquals(true, $columns[0]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($columns[0]['type']));
$this->assertEquals(null, $columns[0]['length']);
$this->assertEquals(false, $columns[0]['unsigned']);
$this->assertEquals(false, $columns[0]['fixed']);
$this->assertEquals(true, $columns[0]['notnull']);
$this->assertEquals(null, $columns[0]['default']);
$this->assertEquals('test', $columns[1]['name']);
$this->assertEquals(false, $columns[1]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\StringType', get_class($columns[1]['type']));
$this->assertEquals(255, $columns[1]['length']);
$this->assertEquals(false, $columns[1]['unsigned']);
$this->assertEquals(false, $columns[1]['fixed']);
$this->assertEquals(false, $columns[1]['notnull']);
$this->assertEquals(null, $columns[1]['default']);
}
public function testListTables()
{
$this->createTestTable('list_tables_test');
$tables = $this->_sm->listTables();
$this->assertEquals(true, in_array('list_tables_test', $tables));
}
public function testListUsers()
{
$users = $this->_sm->listUsers();
@ -92,13 +37,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(true, $found);
}
public function testListViews()
protected function getCreateExampleViewSql()
{
$this->_sm->dropAndCreateView('test_create_view', 'SELECT * from mysql.user');
$views = $this->_sm->listViews();
$this->assertEquals('test_create_view', $views[0]);
return 'SELECT * from mysql.user';
}
public function testListTableForeignKeys()
{
$data['options'] = array('type' => 'innodb');
@ -119,10 +62,4 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals('foreign_key_test', $tableForeignKeys[0]['local']);
$this->assertEquals('id', $tableForeignKeys[0]['foreign']);
}
public function testDropAndCreate()
{
$this->_sm->dropAndCreateView('testing_a_new_view', 'SELECT * from mysql.user');
$this->_sm->dropAndCreateView('testing_a_new_view', 'SELECT * from mysql.user');
}
}

View File

@ -8,17 +8,22 @@ require_once __DIR__ . '/../../../TestInit.php';
class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
public function testListDatabases()
public function setUp()
{
$this->_sm->dropAndCreateDatabase('test_oracle_create_database');
$databases = $this->_sm->listDatabases();
$this->assertEquals(true, in_array('TEST_ORACLE_CREATE_DATABASE', $databases));
}
$this->markTestSkipped('Somehow they all dont work because of privledges or other stuff.');
public function testListFunctions()
{
$functions = $this->_sm->listFunctions();
$this->assertEquals(array(), $functions);
parent::setUp();
if(!isset($GLOBALS['db_username'])) {
$this->markTestSkipped('Foo');
}
$username = $GLOBALS['db_username'];
$query = "GRANT ALL PRIVILEGES TO ".$username;
$conn = \Doctrine\Tests\TestUtil::getTempConnection();
$conn->executeUpdate($query);
}
/**
@ -43,36 +48,6 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(2, count($tableConstraints));
}
public function testListTableColumns()
{
$this->createTestTable('list_tables_test');
$columns = $this->_sm->listTableColumns('list_tables_test');
$this->assertEquals('ID', $columns[1]['name']);
$this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($columns[1]['type']));
$this->assertEquals(22, $columns[1]['length']);
$this->assertEquals(false, $columns[1]['unsigned']);
$this->assertEquals(false, $columns[1]['fixed']);
$this->assertEquals(true, $columns[1]['notnull']);
$this->assertEquals(null, $columns[1]['default']);
$this->assertEquals('TEST', $columns[2]['name']);
$this->assertEquals('Doctrine\DBAL\Types\StringType', get_class($columns[2]['type']));
$this->assertEquals(255, $columns[2]['length']);
$this->assertEquals(false, $columns[2]['unsigned']);
$this->assertEquals(false, $columns[2]['fixed']);
$this->assertEquals(false, $columns[2]['notnull']);
$this->assertEquals(null, $columns[2]['default']);
}
public function testListTables()
{
$this->createTestTable('list_tables_test');
$tables = $this->_sm->listTables();
$this->assertEquals(true, in_array('LIST_TABLES_TEST', $tables));
}
public function testListUsers()
{
$users = $this->_sm->listUsers();
@ -100,13 +75,13 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
public function testListTableForeignKeys()
{
return $this->assertUnsupportedMethod('listTableForeignKeys');
$this->markTestSkipped('Not yet implemented');
}
public function testRenameTable()
{
$this->_sm->tryDropTable('list_tables_test');
$this->_sm->tryDropTable('list_tables_test_new_name');
$this->_sm->tryMethod('DropTable', 'list_tables_test');
$this->_sm->tryMethod('DropTable', 'list_tables_test_new_name');
$this->createTestTable('list_tables_test');
$this->_sm->renameTable('list_tables_test', 'list_tables_test_new_name');
@ -114,10 +89,4 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$tables = $this->_sm->listTables();
$this->assertEquals(true, in_array('LIST_TABLES_TEST_NEW_NAME', $tables));
}
public function testDropAndCreate()
{
$this->_sm->dropAndCreateView('testing_a_new_view', 'SELECT * FROM sys.user_tables');
$this->_sm->dropAndCreateView('testing_a_new_view', 'SELECT * FROM sys.user_tables');
}
}

View File

@ -8,28 +8,6 @@ require_once __DIR__ . '/../../../TestInit.php';
class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
public function testListDatabases()
{
$this->_sm->dropAndCreateDatabase('test_create_database');
$databases = $this->_sm->listDatabases();
$this->assertEquals(true, in_array('test_create_database', $databases));
}
/**
* @expectedException \Exception
*/
public function testListFunctions()
{
$this->_sm->listFunctions();
}
public function testListTriggers()
{
$triggers = $this->_sm->listTriggers();
$this->assertEquals(true, is_array($triggers));
$this->assertEquals(true, count($triggers) > 0);
}
public function testListSequences()
{
$this->createTestTable('list_sequences_test');
@ -44,7 +22,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(array('list_table_constraints_test_pkey'), $tableConstraints);
}
public function testListTableColumns()
/*public function testListTableColumns()
{
$this->createTestTable('list_tables_test');
$columns = $this->_sm->listTableColumns('list_tables_test');
@ -64,14 +42,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(false, $columns[1]['fixed']);
$this->assertEquals(false, $columns[1]['notnull']);
$this->assertEquals(null, $columns[1]['default']);
}
public function testListTables()
{
$this->createTestTable('list_tables_test');
$tables = $this->_sm->listTables();
$this->assertEquals(true, in_array('list_tables_test', $tables));
}
}*/
public function testListUsers()
{
@ -88,20 +59,9 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(true, $found);
}
public function testListViews()
protected function getCreateExampleViewSql()
{
$this->_sm->dropAndCreateView('test_create_view', 'SELECT usename, passwd FROM pg_user');
$views = $this->_sm->listViews();
$found = false;
foreach ($views as $view) {
if ($view['name'] == 'test_create_view') {
$found = true;
break;
}
}
$this->assertEquals(true, $found);
return 'SELECT usename, passwd FROM pg_user';
}
public function testListTableForeignKeys()

View File

@ -8,6 +8,160 @@ require_once __DIR__ . '/../../../TestInit.php';
class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTestCase
{
public function testListFunctions()
{
$funcs = $this->_sm->listFunctions();
$this->assertType('array', $funcs);
$this->assertTrue(count($funcs)>=0);
}
public function testListTriggers()
{
$triggers = $this->_sm->listTriggers();
$this->assertType('array', $triggers);
$this->assertTrue(count($triggers) >= 0);
}
public function testListDatabases()
{
$this->_sm->dropAndCreateDatabase('test_create_database');
$databases = $this->_sm->listDatabases();
$databases = \array_map('strtolower', $databases);
$this->assertEquals(true, in_array('test_create_database', $databases));
}
public function testListTables()
{
$this->createTestTable('list_tables_test');
$tables = $this->_sm->listTables();
$tables = \array_change_key_case($tables, CASE_LOWER);
$this->assertEquals(true, in_array('list_tables_test', $tables));
}
public function testListTableColumns()
{
$data = array();
$data['columns'] = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => Type::getType('string'),
'length' => 255,
'notnull' => false,
),
'foo' => array(
'type' => Type::getType('text'),
'notnull' => true,
),
'bar' => array(
'type' => Type::getType('decimal'),
'precision' => 10,
'scale' => 4,
),
'baz1' => array(
'type' => Type::getType('datetime'),
),
'baz2' => array(
'type' => Type::getType('time'),
),
'baz3' => array(
'type' => Type::getType('date'),
),
);
$this->createTestTable('list_table_columns', $data);
$columns = $this->_sm->listTableColumns('list_table_columns');
$columns = \array_change_key_case($columns, CASE_LOWER);
$this->assertArrayHasKey('id', $columns);
$this->assertEquals('id', strtolower($columns['id']['name']));
$this->assertType('Doctrine\DBAL\Types\IntegerType', $columns['id']['type']);
$this->assertEquals(null, $columns['id']['length']);
$this->assertEquals(null, $columns['id']['precision']);
$this->assertEquals(null, $columns['id']['scale']);
$this->assertEquals(false, $columns['id']['unsigned']);
$this->assertEquals(false, $columns['id']['fixed']);
$this->assertEquals(true, $columns['id']['notnull']);
$this->assertEquals(null, $columns['id']['default']);
$this->assertType('array', $columns['id']['platformDetails']);
$this->assertArrayHasKey('test', $columns);
$this->assertEquals('test', strtolower($columns['test']['name']));
$this->assertType('Doctrine\DBAL\Types\StringType', $columns['test']['type']);
$this->assertEquals(255, $columns['test']['length']);
$this->assertEquals(null, $columns['test']['precision']);
$this->assertEquals(null, $columns['test']['scale']);
$this->assertEquals(false, $columns['test']['unsigned']);
$this->assertEquals(false, $columns['test']['fixed']);
$this->assertEquals(false, $columns['test']['notnull']);
$this->assertEquals(null, $columns['test']['default']);
$this->assertType('array', $columns['test']['platformDetails']);
$this->assertEquals('foo', strtolower($columns['foo']['name']));
$this->assertType('Doctrine\DBAL\Types\TextType', $columns['foo']['type']);
$this->assertEquals(null, $columns['foo']['length']);
$this->assertEquals(null, $columns['foo']['precision']);
$this->assertEquals(null, $columns['foo']['scale']);
$this->assertEquals(false, $columns['foo']['unsigned']);
$this->assertEquals(false, $columns['foo']['fixed']);
$this->assertEquals(true, $columns['foo']['notnull']);
$this->assertEquals(null, $columns['foo']['default']);
$this->assertType('array', $columns['foo']['platformDetails']);
$this->assertEquals('bar', strtolower($columns['bar']['name']));
$this->assertType('Doctrine\DBAL\Types\DecimalType', $columns['bar']['type']);
$this->assertEquals(null, $columns['bar']['length']);
$this->assertEquals(10, $columns['bar']['precision']);
$this->assertEquals(4, $columns['bar']['scale']);
$this->assertEquals(false, $columns['bar']['unsigned']);
$this->assertEquals(false, $columns['bar']['fixed']);
$this->assertEquals(false, $columns['bar']['notnull']);
$this->assertEquals(null, $columns['bar']['default']);
$this->assertType('array', $columns['bar']['platformDetails']);
$this->assertEquals('baz1', strtolower($columns['baz1']['name']));
$this->assertType('Doctrine\DBAL\Types\DateTimeType', $columns['baz1']['type']);
$this->assertEquals(null, $columns['baz1']['length']);
$this->assertEquals(null, $columns['baz1']['precision']);
$this->assertEquals(null, $columns['baz1']['scale']);
$this->assertEquals(false, $columns['baz1']['unsigned']);
$this->assertEquals(false, $columns['baz1']['fixed']);
$this->assertEquals(false, $columns['baz1']['notnull']);
$this->assertEquals(null, $columns['baz1']['default']);
$this->assertType('array', $columns['baz1']['platformDetails']);
$this->assertEquals('baz2', strtolower($columns['baz2']['name']));
$this->assertContains($columns['baz2']['type']->getName(), array('Time', 'Date', 'DateTime'));
$this->assertEquals(null, $columns['baz2']['length']);
$this->assertEquals(null, $columns['baz2']['precision']);
$this->assertEquals(null, $columns['baz2']['scale']);
$this->assertEquals(false, $columns['baz2']['unsigned']);
$this->assertEquals(false, $columns['baz2']['fixed']);
$this->assertEquals(false, $columns['baz2']['notnull']);
$this->assertEquals(null, $columns['baz2']['default']);
$this->assertType('array', $columns['baz2']['platformDetails']);
$this->assertEquals('baz3', strtolower($columns['baz3']['name']));
$this->assertContains($columns['baz2']['type']->getName(), array('Time', 'Date', 'DateTime'));
$this->assertEquals(null, $columns['baz3']['length']);
$this->assertEquals(null, $columns['baz3']['precision']);
$this->assertEquals(null, $columns['baz3']['scale']);
$this->assertEquals(false, $columns['baz3']['unsigned']);
$this->assertEquals(false, $columns['baz3']['fixed']);
$this->assertEquals(false, $columns['baz3']['notnull']);
$this->assertEquals(null, $columns['baz3']['default']);
$this->assertType('array', $columns['baz3']['platformDetails']);
}
public function testListTableIndexes()
{
$data['options'] = array(
@ -67,6 +221,38 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertFalse($tableIndexes['test']['primary']);
}
protected function getCreateExampleViewSql()
{
$this->markTestSkipped('No Create Example View SQL was defined for this SchemaManager');
}
public function testListViews()
{
$this->_sm->dropAndCreateView('test_create_view', $this->getCreateExampleViewSql());
$views = $this->_sm->listViews();
$this->assertTrue(count($views) >= 1, "There should be at least the fixture view created in the database, but none were found.");
$found = false;
foreach($views AS $view) {
if(!isset($view['name']) || !isset($view['sql'])) {
$this->fail(
"listViews() has to return entries with both name ".
"and sql keys, but only ".implode(", ", array_keys($view))." are present."
);
}
if($view['name'] == 'test_create_view') {
$found = true;
}
}
$this->assertTrue($found, "'test_create_view' View was not found in listViews().");
}
/**
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
protected $_sm;
protected function setUp()
{
parent::setUp();

View File

@ -9,6 +9,8 @@ require_once __DIR__ . '/../../../TestInit.php';
class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
/**
* SQLITE does not support databases.
*
* @expectedException \Exception
*/
public function testListDatabases()
@ -17,6 +19,8 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
}
/**
* SQLITE does not support databases.
*
* @expectedException \Exception
*/
public function testListFunctions()
@ -49,7 +53,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(array(), $tableConstraints);
}
public function testListTableColumns()
/*public function testListTableColumns()
{
$this->createTestTable('list_table_columns_test');
@ -72,14 +76,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(false, $tableColumns[1]['fixed']);
$this->assertEquals(false, $tableColumns[1]['notnull']);
$this->assertEquals(null, $tableColumns[1]['default']);
}
public function testListTables()
{
$this->createTestTable('list_tables_test');
$tables = $this->_sm->listTables();
$this->assertEquals(true, in_array('list_tables_test', $tables));
}
}*/
/**
* @expectedException \Exception
@ -89,14 +86,10 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->_sm->listUsers();
}
public function testListViews()
protected function getCreateExampleViewSql()
{
$this->createTestTable('test_views');
$this->_sm->dropAndCreateView('test_create_view', 'SELECT * from test_views');
$views = $this->_sm->listViews();
$this->assertEquals('test_create_view', $views[0]['name']);
$this->assertEquals('CREATE VIEW test_create_view AS SELECT * from test_views', $views[0]['sql']);
return 'SELECT * from test_views';
}
public function testCreateAndDropDatabase()
@ -109,33 +102,6 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(false, file_exists($path));
}
public function testCreateTable()
{
$this->createTestTable('test_create_table');
$tables = $this->_sm->listTables();
$this->assertEquals(true, in_array('test_create_table', $tables));
$tableColumns = $this->_sm->listTableColumns('test_create_table');
$this->assertEquals('id', $tableColumns[0]['name']);
$this->assertEquals(true, $tableColumns[0]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($tableColumns[0]['type']));
$this->assertEquals(null, $tableColumns[0]['length']);
$this->assertEquals(false, $tableColumns[0]['unsigned']);
$this->assertEquals(false, $tableColumns[0]['fixed']);
$this->assertEquals(true, $tableColumns[0]['notnull']);
$this->assertEquals(null, $tableColumns[0]['default']);
$this->assertEquals('test', $tableColumns[1]['name']);
$this->assertEquals(false, $tableColumns[1]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\StringType', get_class($tableColumns[1]['type']));
$this->assertEquals(255, $tableColumns[1]['length']);
$this->assertEquals(false, $tableColumns[1]['unsigned']);
$this->assertEquals(false, $tableColumns[1]['fixed']);
$this->assertEquals(false, $tableColumns[1]['notnull']);
$this->assertEquals(null, $tableColumns[1]['default']);
}
/**
* @expectedException \Exception
*/

View File

@ -77,4 +77,22 @@ class TestUtil
return $conn;
}
/**
* @return \Doctrine\DBAL\Connection
*/
public static function getTempConnection()
{
$tmpDbParams = array(
'driver' => $GLOBALS['tmpdb_type'],
'user' => $GLOBALS['tmpdb_username'],
'password' => $GLOBALS['tmpdb_password'],
'host' => $GLOBALS['tmpdb_host'],
'dbname' => $GLOBALS['tmpdb_name'],
'port' => $GLOBALS['tmpdb_port']
);
// Connect to tmpdb in order to drop and create the real test db.
return \Doctrine\DBAL\DriverManager::getConnection($tmpDbParams);
}
}