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); 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. * Gets the default transaction isolation level of the platform.
* *
@ -1577,4 +1589,4 @@ abstract class AbstractPlatform
{ {
return 'INSERT INTO ' . $tableName . ' (' . $identifierColumnName . ') VALUES (null)'; 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') . ')'; 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 * @override
*/ */
@ -536,4 +552,4 @@ class MsSqlPlatform extends AbstractPlatform
{ {
return 'INSERT INTO ' . $quotedTableName . ' DEFAULT VALUES'; return 'INSERT INTO ' . $quotedTableName . ' DEFAULT VALUES';
} }
} }

View File

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

View File

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

View File

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

View File

@ -265,6 +265,14 @@ class SqlitePlatform extends AbstractPlatform
return 'DATE'; return 'DATE';
} }
/**
* @override
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
{
return 'TIME';
}
/** /**
* @override * @override
*/ */
@ -445,4 +453,4 @@ class SqlitePlatform extends AbstractPlatform
{ {
return 'sqlite'; 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 * @return array $functions
*/ */
public function listFunctions() 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 * @return array $triggers
*/ */
public function listTriggers() public function listTriggers()
@ -169,6 +175,28 @@ abstract class AbstractSchemaManager
/** /**
* List the columns for a given table. * 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. * @param string $table The name of the table.
* @return array $tableColumns The column descriptions. * @return array $tableColumns The column descriptions.
*/ */
@ -249,6 +277,10 @@ abstract class AbstractSchemaManager
/** /**
* List the views this connection has * 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 * @return array $views
*/ */
public function listViews() public function listViews()
@ -896,7 +928,7 @@ abstract class AbstractSchemaManager
if (is_string($value['type'])) { if (is_string($value['type'])) {
$value['type'] = \Doctrine\DBAL\Types\Type::getType($value['type']); $value['type'] = \Doctrine\DBAL\Types\Type::getType($value['type']);
} }
$list[] = $value; $list[$value['name']] = $value;
} }
} }
return $list; return $list;

View File

@ -36,7 +36,10 @@ class MySqlSchemaManager extends AbstractSchemaManager
{ {
protected function _getPortableViewDefinition($view) protected function _getPortableViewDefinition($view)
{ {
return $view['TABLE_NAME']; return array(
'name' => $view['TABLE_NAME'],
'sql' => $view['VIEW_DEFINITION']
);
} }
protected function _getPortableTableDefinition($table) protected function _getPortableTableDefinition($table)
@ -117,9 +120,9 @@ class MySqlSchemaManager extends AbstractSchemaManager
if ( ! isset($tableColumn['name'])) { if ( ! isset($tableColumn['name'])) {
$tableColumn['name'] = ''; $tableColumn['name'] = '';
} }
$values = null;
$scale = null; $scale = null;
$precision = null;
// Map db type to Doctrine mapping type // Map db type to Doctrine mapping type
switch ($dbType) { switch ($dbType) {
@ -191,6 +194,11 @@ class MySqlSchemaManager extends AbstractSchemaManager
case 'real': case 'real':
case 'numeric': case 'numeric':
case 'decimal': 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'; $type = 'decimal';
break; break;
case 'tinyblob': case 'tinyblob':
@ -230,24 +238,30 @@ class MySqlSchemaManager extends AbstractSchemaManager
'unsigned' => (bool) $unsigned, 'unsigned' => (bool) $unsigned,
'fixed' => (bool) $fixed 'fixed' => (bool) $fixed
); );
if ($scale !== null) {
$def['scale'] = $scale;
}
$values = ($values !== null) ? $values : array();
$column = array( $column = array(
'name' => $tableColumn['Field'], 'name' => $tableColumn['Field'],
'values' => $values, 'type' => $type,
'primary' => (bool) (strtolower($tableColumn['Key']) == 'pri'), 'length' => $length,
'unique' => (bool) (strtolower($tableColumn['Key']) == 'uni'), 'unsigned' => (bool)$unsigned,
'fixed' => (bool)$fixed,
'default' => $tableColumn['Default'], 'default' => $tableColumn['Default'],
'notnull' => (bool) ($tableColumn['Null'] != 'YES'), '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) public function _getPortableTableForeignKeyDefinition($tableForeignKey)

View File

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

View File

@ -54,7 +54,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
protected function _getPortableViewDefinition($view) protected function _getPortableViewDefinition($view)
{ {
return array( return array(
'name' => $view['viewname'] 'name' => $view['viewname'],
'sql' => $view['definition']
); );
} }
@ -151,6 +152,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
if ( ! isset($tableColumn['name'])) { if ( ! isset($tableColumn['name'])) {
$tableColumn['name'] = ''; $tableColumn['name'] = '';
} }
$precision = null;
$scale = null;
$dbType = strtolower($tableColumn['type']); $dbType = strtolower($tableColumn['type']);
@ -228,6 +232,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case 'decimal': case 'decimal':
case 'money': case 'money':
case 'numeric': 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'; $type = 'decimal';
break; break;
case 'tinyblob': case 'tinyblob':
@ -258,19 +267,20 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$type = 'string'; $type = 'string';
} }
$decl = array(
'type' => $type,
'length' => $length,
'fixed' => $fixed
);
$description = array( $description = array(
'name' => $tableColumn['field'], 'name' => $tableColumn['field'],
'type' => $type,
'length' => $length,
'notnull' => (bool) $tableColumn['isnotnull'], 'notnull' => (bool) $tableColumn['isnotnull'],
'default' => $tableColumn['default'], 'default' => $tableColumn['default'],
'primary' => (bool) ($tableColumn['pri'] == 't'), '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'] = ''; $tableColumn['name'] = '';
} }
$precision = null;
$scale = null;
switch ($dbType) { switch ($dbType) {
case 'boolean': case 'boolean':
$type = 'boolean'; $type = 'boolean';
@ -219,6 +222,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
case 'real': case 'real':
case 'decimal': case 'decimal':
case 'numeric': case 'numeric':
list($precision, $scale) = array_map('trim', explode(', ', $tableColumn['length']));
$type = 'decimal'; $type = 'decimal';
$length = null; $length = null;
break; break;
@ -238,13 +242,19 @@ class SqliteSchemaManager extends AbstractSchemaManager
$length = null; $length = null;
} }
return array('name' => $tableColumn['name'], return array(
'primary' => (bool) $tableColumn['pk'], 'name' => $tableColumn['name'],
'type' => $type, 'type' => $type,
'length' => $length, 'length' => $length,
'unsigned' => (bool) $unsigned, 'unsigned' => (bool) $unsigned,
'fixed' => $fixed, 'fixed' => $fixed,
'notnull' => $notnull, 'notnull' => $notnull,
'default' => $default); '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\SqliteSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaManagerTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\PostgreSqlSchemaManagerTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\PostgreSqlSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\OracleSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\ConnectionTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Functional\ConnectionTest');
return $suite; return $suite;

View File

@ -8,29 +8,6 @@ require_once __DIR__ . '/../../../TestInit.php';
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase 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() public function testListSequences()
{ {
$this->createTestTable('list_sequences_test'); $this->createTestTable('list_sequences_test');
@ -45,38 +22,6 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(array('PRIMARY'), $tableConstraints); $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() public function testListUsers()
{ {
$users = $this->_sm->listUsers(); $users = $this->_sm->listUsers();
@ -92,13 +37,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(true, $found); $this->assertEquals(true, $found);
} }
public function testListViews() protected function getCreateExampleViewSql()
{ {
$this->_sm->dropAndCreateView('test_create_view', 'SELECT * from mysql.user'); return 'SELECT * from mysql.user';
$views = $this->_sm->listViews();
$this->assertEquals('test_create_view', $views[0]);
} }
public function testListTableForeignKeys() public function testListTableForeignKeys()
{ {
$data['options'] = array('type' => 'innodb'); $data['options'] = array('type' => 'innodb');
@ -119,10 +62,4 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals('foreign_key_test', $tableForeignKeys[0]['local']); $this->assertEquals('foreign_key_test', $tableForeignKeys[0]['local']);
$this->assertEquals('id', $tableForeignKeys[0]['foreign']); $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 class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
{ {
public function testListDatabases() public function setUp()
{ {
$this->_sm->dropAndCreateDatabase('test_oracle_create_database'); $this->markTestSkipped('Somehow they all dont work because of privledges or other stuff.');
$databases = $this->_sm->listDatabases();
$this->assertEquals(true, in_array('TEST_ORACLE_CREATE_DATABASE', $databases));
}
public function testListFunctions() parent::setUp();
{
$functions = $this->_sm->listFunctions(); if(!isset($GLOBALS['db_username'])) {
$this->assertEquals(array(), $functions); $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)); $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() public function testListUsers()
{ {
$users = $this->_sm->listUsers(); $users = $this->_sm->listUsers();
@ -100,13 +75,13 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
public function testListTableForeignKeys() public function testListTableForeignKeys()
{ {
return $this->assertUnsupportedMethod('listTableForeignKeys'); $this->markTestSkipped('Not yet implemented');
} }
public function testRenameTable() public function testRenameTable()
{ {
$this->_sm->tryDropTable('list_tables_test'); $this->_sm->tryMethod('DropTable', 'list_tables_test');
$this->_sm->tryDropTable('list_tables_test_new_name'); $this->_sm->tryMethod('DropTable', 'list_tables_test_new_name');
$this->createTestTable('list_tables_test'); $this->createTestTable('list_tables_test');
$this->_sm->renameTable('list_tables_test', 'list_tables_test_new_name'); $this->_sm->renameTable('list_tables_test', 'list_tables_test_new_name');
@ -114,10 +89,4 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$tables = $this->_sm->listTables(); $tables = $this->_sm->listTables();
$this->assertEquals(true, in_array('LIST_TABLES_TEST_NEW_NAME', $tables)); $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 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() public function testListSequences()
{ {
$this->createTestTable('list_sequences_test'); $this->createTestTable('list_sequences_test');
@ -44,7 +22,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(array('list_table_constraints_test_pkey'), $tableConstraints); $this->assertEquals(array('list_table_constraints_test_pkey'), $tableConstraints);
} }
public function testListTableColumns() /*public function testListTableColumns()
{ {
$this->createTestTable('list_tables_test'); $this->createTestTable('list_tables_test');
$columns = $this->_sm->listTableColumns('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]['fixed']);
$this->assertEquals(false, $columns[1]['notnull']); $this->assertEquals(false, $columns[1]['notnull']);
$this->assertEquals(null, $columns[1]['default']); $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() public function testListUsers()
{ {
@ -88,20 +59,9 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(true, $found); $this->assertEquals(true, $found);
} }
public function testListViews() protected function getCreateExampleViewSql()
{ {
$this->_sm->dropAndCreateView('test_create_view', 'SELECT usename, passwd FROM pg_user'); return '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);
} }
public function testListTableForeignKeys() public function testListTableForeignKeys()

View File

@ -8,6 +8,160 @@ require_once __DIR__ . '/../../../TestInit.php';
class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTestCase 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() public function testListTableIndexes()
{ {
$data['options'] = array( $data['options'] = array(
@ -67,6 +221,38 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertFalse($tableIndexes['test']['primary']); $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() protected function setUp()
{ {
parent::setUp(); parent::setUp();

View File

@ -9,6 +9,8 @@ require_once __DIR__ . '/../../../TestInit.php';
class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
{ {
/** /**
* SQLITE does not support databases.
*
* @expectedException \Exception * @expectedException \Exception
*/ */
public function testListDatabases() public function testListDatabases()
@ -17,6 +19,8 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
} }
/** /**
* SQLITE does not support databases.
*
* @expectedException \Exception * @expectedException \Exception
*/ */
public function testListFunctions() public function testListFunctions()
@ -49,7 +53,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(array(), $tableConstraints); $this->assertEquals(array(), $tableConstraints);
} }
public function testListTableColumns() /*public function testListTableColumns()
{ {
$this->createTestTable('list_table_columns_test'); $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]['fixed']);
$this->assertEquals(false, $tableColumns[1]['notnull']); $this->assertEquals(false, $tableColumns[1]['notnull']);
$this->assertEquals(null, $tableColumns[1]['default']); $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 * @expectedException \Exception
@ -89,14 +86,10 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->_sm->listUsers(); $this->_sm->listUsers();
} }
public function testListViews() protected function getCreateExampleViewSql()
{ {
$this->createTestTable('test_views'); $this->createTestTable('test_views');
$this->_sm->dropAndCreateView('test_create_view', 'SELECT * from test_views'); return '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']);
} }
public function testCreateAndDropDatabase() public function testCreateAndDropDatabase()
@ -109,33 +102,6 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertEquals(false, file_exists($path)); $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 * @expectedException \Exception
*/ */

View File

@ -77,4 +77,22 @@ class TestUtil
return $conn; 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);
}
} }