Commit 75e0c1ed authored by jwage's avatar jwage

[2.0] More general work on the SchemaManager and Platform classes. Making API...

[2.0] More general work on the SchemaManager and Platform classes. Making API more complete and adding sqlite and mysql test coverage.
parent 746d9bc3
......@@ -192,6 +192,26 @@ class Connection
$this->_platform->setQuoteIdentifiers($this->_quoteIdentifiers);
}
/**
* Get the array of parameters used to instantiated this connection instance
*
* @return array $params
*/
public function getParams()
{
return $this->_params;
}
/**
* Get the name of the database connected to for this Connection instance
*
* @return string $database
*/
public function getDatabase()
{
return $this->_driver->getDatabase($this);
}
/**
* Gets the DBAL driver instance.
*
......@@ -584,7 +604,6 @@ class Connection
*/
public function close()
{
$this->clear();
unset($this->_conn);
$this->_isConnected = false;
}
......
......@@ -33,6 +33,7 @@ interface Driver
* Gets the SchemaManager that can be used to inspect and change the underlying
* database schema of the platform this driver connects to.
*
* @param Doctrine\DBAL\Connection $conn
* @return Doctrine\DBAL\SchemaManager
*/
public function getSchemaManager(Connection $conn);
......@@ -43,4 +44,12 @@ interface Driver
* @return string The name of the driver
*/
public function getName();
/**
* Get the name of the database connected to for this driver instance
*
* @param Doctrine\DBAL\Connection $conn
* @return string $database
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn);
}
\ No newline at end of file
......@@ -62,4 +62,10 @@ class Driver implements \Doctrine\DBAL\Driver
{
return 'pdo_mssql';
}
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
}
\ No newline at end of file
......@@ -87,4 +87,10 @@ class Driver implements \Doctrine\DBAL\Driver
{
return 'pdo_mysql';
}
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
}
\ No newline at end of file
......@@ -79,4 +79,10 @@ class Driver implements \Doctrine\DBAL\Driver
{
return 'pdo_oracle';
}
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
}
\ No newline at end of file
......@@ -56,4 +56,10 @@ class Driver implements \Doctrine\DBAL\Driver
{
return 'pdo_pgsql';
}
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
}
\ No newline at end of file
......@@ -88,4 +88,10 @@ class Driver implements \Doctrine\DBAL\Driver
{
return 'pdo_sqlite';
}
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return isset($params['path']) ? $params['path'] : null;
}
}
\ No newline at end of file
......@@ -662,6 +662,10 @@ abstract class AbstractPlatform
*/
public function getCreateIndexSql($table, $name, array $definition)
{
if ( ! isset($definition['fields'])) {
throw DoctrineException::updateMe('You must specify an array of fields to create the index for');
}
$type = '';
if (isset($definition['type'])) {
switch (strtolower($definition['type'])) {
......@@ -1300,7 +1304,7 @@ abstract class AbstractPlatform
throw DoctrineException::updateMe('List triggers not supported by this driver.');
}
public function getListSequencesSql()
public function getListSequencesSql($database)
{
throw DoctrineException::updateMe('List sequences not supported by this driver.');
}
......@@ -1330,6 +1334,21 @@ abstract class AbstractPlatform
throw DoctrineException::updateMe('List views not supported by this driver.');
}
public function getListTableIndexesSql($table)
{
throw DoctrineException::updateMe('List table indexes not supported by this driver.');
}
public function getCreateViewSql($name, $sql)
{
throw DoctrineException::updateMe('Create view not supported by this driver');
}
public function getDropViewSql($name)
{
throw DoctrineException::updateMe('Drop view not supported by this driver');
}
public function getDropSequenceSql($sequenceName)
{
throw DoctrineException::updateMe('Drop sequence not supported by this driver.');
......
......@@ -146,7 +146,55 @@ class MySqlPlatform extends AbstractPlatform
$args = func_get_args();
return 'CONCAT(' . join(', ', (array) $args) . ')';
}
public function getListDatabasesSql()
{
return 'SHOW DATABASES';
}
public function getListSequencesSql($database)
{
$query = 'SHOW TABLES';
if ( ! is_null($database)) {
$query .= ' FROM ' . $this->quoteIdentifier($database);
}
return $query;
}
public function getListTableConstraintsSql($table)
{
return 'SHOW INDEX FROM ' . $this->quoteIdentifier($table);
}
public function getListTableIndexesSql($table)
{
return 'SHOW INDEX FROM ' . $this->quoteIdentifier($table);
}
public function getListUsersSql()
{
return "SELECT * FROM mysql.user WHERE user != '' GROUP BY user";
}
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'";
}
}
public function getCreateViewSql($name, $sql)
{
return 'CREATE VIEW ' . $name . ' AS ' . $sql;
}
public function getDropViewSql($name)
{
return 'DROP VIEW '. $name;
}
/**
* Gets the SQL snippet used to declare a VARCHAR column on the MySql platform.
*
......@@ -739,7 +787,6 @@ class MySqlPlatform extends AbstractPlatform
*/
public function getIndexDeclarationSql($name, array $definition)
{
$name = $this->formatter->getIndexName($name);
$type = '';
if (isset($definition['type'])) {
switch (strtolower($definition['type'])) {
......
......@@ -520,7 +520,7 @@ class PostgreSqlPlatform extends AbstractPlatform
*
* @override
*/
public function getListSequencesSql()
public function getListSequencesSql($database)
{
return "SELECT
relname
......@@ -599,7 +599,7 @@ class PostgreSqlPlatform extends AbstractPlatform
*
* @override
*/
public function getListTableIndexesSql()
public function getListTableIndexesSql($table)
{
return "SELECT
relname
......@@ -608,7 +608,7 @@ class PostgreSqlPlatform extends AbstractPlatform
WHERE oid IN (
SELECT indexrelid
FROM pg_index, pg_class
WHERE pg_class.relname = %s
WHERE pg_class.relname = '$table'
AND pg_class.oid=pg_index.indrelid
AND indisunique != 't'
AND indisprimary != 't'
......
......@@ -346,14 +346,14 @@ class SqlitePlatform extends AbstractPlatform
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
}
public function getListSequencesSql()
public function getListSequencesSql($database)
{
return "SELECT name FROM sqlite_master WHERE type='table' AND sql NOT NULL ORDER BY name";
}
public function getListTableConstraintsSql($table)
{
return "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = $table AND sql NOT NULL ORDER BY name";
return "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = '$table' AND sql NOT NULL ORDER BY name";
}
public function getListTableColumnsSql($table)
......@@ -383,6 +383,16 @@ class SqlitePlatform extends AbstractPlatform
return "SELECT name, sql FROM sqlite_master WHERE type='view' AND sql NOT NULL";
}
public function getCreateViewSql($name, $sql)
{
return 'CREATE VIEW ' . $name . ' AS ' . $sql;
}
public function getDropViewSql($name)
{
return 'DROP VIEW '. $name;
}
/**
* SQLite does support foreign key constraints, but only in CREATE TABLE statements...
* This really limits their usefulness and requires SQLite specific handling, so
......
......@@ -32,6 +32,66 @@ namespace Doctrine\DBAL\Schema;
*/
class MySqlSchemaManager extends AbstractSchemaManager
{
protected function _getPortableViewDefinition($view)
{
return array(
'name' => $view['table_name'],
'sql' => $view['view_definition']
);
}
protected function _getPortableTableDefinition($table)
{
return end($table);
}
protected function _getPortableUserDefinition($user)
{
return array(
'user' => $user['user'],
'password' => $user['password'],
);
}
protected function _getPortableTableIndexDefinition($tableIndex)
{
$tableIndex = array_change_key_case($tableIndex, CASE_LOWER);
$result = array();
if ($tableIndex['key_name'] != 'PRIMARY' && ($index = $tableIndex['key_name'])) {
$result['name'] = $index;
$result['column'] = $tableIndex['column_name'];
$result['unique'] = $tableIndex['non_unique'] ? false : true;
}
return $result;
}
protected function _getPortableTableConstraintDefinition($tableConstraint)
{
$tableConstraint = array_change_key_case($tableConstraint, CASE_LOWER);
$result = array();
if ( ! $tableConstraint['non_unique']) {
$index = $tableConstraint['key_name'];
if ( ! empty($index)) {
$result[] = $index;
}
}
return $result;
}
protected function _getPortableSequenceDefinition($sequence)
{
return end($sequence);
}
protected function _getPortableDatabaseDefinition($database)
{
return $database['database'];
}
protected function _getPortableTableColumnDefinition($tableColumn)
{
$dbType = strtolower($tableColumn['type']);
......@@ -231,65 +291,6 @@ class MySqlSchemaManager extends AbstractSchemaManager
return $column;
}
/**
* lists all database sequences
*
* @param string|null $database
* @return array
* @override
*/
public function listSequences($database = null)
{
$query = 'SHOW TABLES';
if ( ! is_null($database)) {
$query .= ' FROM ' . $database;
}
$tableNames = $this->_conn->fetchColumn($query);
return array_map(array($this->_conn->formatter, 'fixSequenceName'), $tableNames);
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
* @override
*/
public function listTableConstraints($table)
{
$keyName = 'Key_name';
$nonUnique = 'Non_unique';
if ($this->_conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_FIX_CASE) {
if ($this->_conn->getAttribute(Doctrine::ATTR_FIELD_CASE) == CASE_LOWER) {
$keyName = strtolower($keyName);
$nonUnique = strtolower($nonUnique);
} else {
$keyName = strtoupper($keyName);
$nonUnique = strtoupper($nonUnique);
}
}
$table = $this->_conn->quoteIdentifier($table, true);
$query = 'SHOW INDEX FROM ' . $table;
$indexes = $this->_conn->fetchAssoc($query);
$result = array();
foreach ($indexes as $indexData) {
if ( ! $indexData[$nonUnique]) {
if ($indexData[$keyName] !== 'PRIMARY') {
$index = $this->_conn->formatter->fixIndexName($indexData[$keyName]);
} else {
$index = 'PRIMARY';
}
if ( ! empty($index)) {
$result[] = $index;
}
}
}
return $result;
}
/**
* lists table foreign keys
*
......@@ -317,70 +318,6 @@ class MySqlSchemaManager extends AbstractSchemaManager
return $result;
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
* @override
*/
public function listTableIndexes($table)
{
$keyName = 'Key_name';
$nonUnique = 'Non_unique';
if ($this->_conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_FIX_CASE) {
if ($this->_conn->getAttribute(Doctrine::ATTR_FIELD_CASE) == CASE_LOWER) {
$keyName = strtolower($keyName);
$nonUnique = strtolower($nonUnique);
} else {
$keyName = strtoupper($keyName);
$nonUnique = strtoupper($nonUnique);
}
}
$table = $this->_conn->quoteIdentifier($table, true);
$query = 'SHOW INDEX FROM ' . $table;
$indexes = $this->_conn->fetchAssoc($query);
$result = array();
foreach ($indexes as $indexData) {
if ($indexData[$nonUnique] && ($index = $this->_conn->formatter->fixIndexName($indexData[$keyName]))) {
$result[] = $index;
}
}
return $result;
}
/**
* lists tables
*
* @param string|null $database
* @return array
* @override
*/
public function listTables($database = null)
{
return $this->_conn->fetchColumn($this->_conn->getDatabasePlatform()
->getListTablesSql());
}
/**
* lists database views
*
* @param string|null $database
* @return array
* @override
*/
public function listViews($database = null)
{
if ( ! is_null($database)) {
$query = sprintf($this->sql['listViews'], ' FROM ' . $database);
}
return $this->_conn->fetchColumn($query);
}
/**
* create sequence
*
......
......@@ -33,6 +33,37 @@ namespace Doctrine\DBAL\Schema;
*/
class SqliteSchemaManager extends AbstractSchemaManager
{
public function dropDatabase($database = null)
{
if (is_null($database)) {
$database = $this->_conn->getDriver()->getDatabase($this->_conn);
}
unlink($database);
}
public function createDatabase($database = null)
{
if (is_null($database)) {
$database = $this->_conn->getDriver()->getDatabase($this->_conn);
}
// TODO: Can we do this better?
$this->_conn->close();
$this->_conn->connect();
}
protected function _getPortableTableDefinition($table)
{
return $table['name'];
}
protected function _getPortableTableIndexDefinition($tableIndex)
{
return array(
'name' => $tableIndex['name'],
'unique' => (bool) $tableIndex['unique']
);
}
protected function _getPortableTableColumnDefinition($tableColumn)
{
$e = explode('(', $tableColumn['type']);
......
......@@ -21,8 +21,8 @@ class AllTests
{
$suite = new \Doctrine\Tests\DbalFunctionalTestSuite('Doctrine Dbal Functional');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\SqliteSchemaTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\SqliteSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaManagerTest');
return $suite;
}
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\Tests\TestUtil;
use Doctrine\DBAL\Schema;
require_once __DIR__ . '/../../../TestInit.php';
class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
private $_conn;
protected function setUp()
{
$this->_conn = TestUtil::getConnection();
if ($this->_conn->getDatabasePlatform()->getName() !== 'mysql')
{
$this->markTestSkipped('The MySqlSchemaTest requires the use of mysql');
}
$this->_sm = new Schema\MySqlSchemaManager($this->_conn);
}
public function testListDatabases()
{
try {
$this->_sm->dropDatabase('test_mysql_create_database');
} catch (\Exception $e) {}
$this->_sm->createDatabase('test_mysql_create_database');
$databases = $this->_sm->listDatabases();
$this->assertEquals(in_array('test_mysql_create_database', $databases), true);
}
public function testListFunctions()
{
try {
$this->_sm->listFunctions();
} catch (\Exception $e) {
return;
}
$this->fail('Sqlite listFunctions() should throw an exception because it is not supported');
}
public function testListTriggers()
{
try {
$this->_sm->listTriggers();
} catch (\Exception $e) {
return;
}
$this->fail('Sqlite listTriggers() should throw an exception because it is not supported');
}
public function testListSequences()
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'length' => 255
)
);
$options = array();
try {
$this->_sm->dropTable('list_sequences_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_sequences_test', $columns, $options);
$sequences = $this->_sm->listSequences();
$this->assertEquals(in_array('list_sequences_test', $sequences), true);
}
public function testListTableConstraints()
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'length' => 255
)
);
$options = array();
try {
$this->_sm->dropTable('list_table_constraints_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_table_constraints_test', $columns, $options);
$tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test');
$this->assertEquals($tableConstraints, array(array('PRIMARY')));
}
public function testListTableColumns()
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'length' => 255
)
);
$options = array();
try {
$this->_sm->dropTable('list_tables_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_tables_test', $columns, $options);
$columns = $this->_sm->listTableColumns('list_tables_test');
$this->assertEquals($columns[0]['name'], 'id');
$this->assertEquals($columns[0]['primary'], true);
$this->assertEquals(get_class($columns[0]['type']), 'Doctrine\DBAL\Types\IntegerType');
$this->assertEquals($columns[0]['length'], 4);
$this->assertEquals($columns[0]['unsigned'], false);
$this->assertEquals($columns[0]['fixed'], false);
$this->assertEquals($columns[0]['notnull'], true);
$this->assertEquals($columns[0]['default'], null);
$this->assertEquals($columns[1]['name'], 'test');
$this->assertEquals($columns[1]['primary'], false);
$this->assertEquals(get_class($columns[1]['type']), 'Doctrine\DBAL\Types\StringType');
$this->assertEquals($columns[1]['length'], 255);
$this->assertEquals($columns[1]['unsigned'], false);
$this->assertEquals($columns[1]['fixed'], false);
$this->assertEquals($columns[1]['notnull'], false);
$this->assertEquals($columns[1]['default'], null);
}
public function testListTableIndexes()
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'length' => 255
)
);
$options = array(
'indexes' => array(
'test_index_name' => array(
'fields' => array(
'test' => array()
),
'type' => 'unique'
)
)
);
try {
$this->_sm->dropTable('list_table_indexes_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_table_indexes_test', $columns, $options);
$tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test');
$this->assertEquals($tableIndexes[0]['name'], 'test_index_name');
$this->assertEquals($tableIndexes[0]['column'], 'test');
$this->assertEquals($tableIndexes[0]['unique'], true);
}
public function testListTable()
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'length' => 255
)
);
$options = array();
try {
$this->_sm->dropTable('list_tables_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_tables_test', $columns, $options);
$tables = $this->_sm->listTables();
$this->assertEquals(in_array('list_tables_test', $tables), true);
}
public function testListUsers()
{
$users = $this->_sm->listUsers();
$this->assertEquals(is_array($users), true);
$params = $this->_conn->getParams();
$testUser = $params['user'];
$found = false;
foreach ($users as $user) {
if ($user['user'] == $testUser) {
$found = true;
}
}
$this->assertEquals($found, true);
}
public function testListViews()
{
try {
$this->_sm->dropView('test_create_view');
} catch (\Exception $e) {}
$this->_sm->createView('test_create_view', 'SELECT * from mysql.user');
$views = $this->_sm->listViews();
$this->assertEquals($views[0]['name'], 'test_create_view');
$this->assertEquals($views[0]['sql'], '/* ALGORITHM=UNDEFINED */ select `mysql`.`user`.`Host` AS `Host`,`mysql`.`user`.`User` AS `User`,`mysql`.`user`.`Password` AS `Password`,`mysql`.`user`.`Select_priv` AS `Select_priv`,`mysql`.`user`.`Insert_priv` AS `Insert_priv`,`mysql`.`user`.`Update_priv` AS `Update_priv`,`mysql`.`user`.`Delete_priv` AS `Delete_priv`,`mysql`.`user`.`Create_priv` AS `Create_priv`,`mysql`.`user`.`Drop_priv` AS `Drop_priv`,`mysql`.`user`.`Reload_priv` AS `Reload_priv`,`mysql`.`user`.`Shutdown_priv` AS `Shutdown_priv`,`mysql`.`user`.`Process_priv` AS `Process_priv`,`mysql`.`user`.`File_priv` AS `File_priv`,`mysql`.`user`.`Grant_priv` AS `Grant_priv`,`mysql`.`user`.`References_priv` AS `References_priv`,`mysql`.`user`.`Index_priv` AS `Index_priv`,`mysql`.`user`.`Alter_priv` AS `Alter_priv`,`mysql`.`user`.`Show_db_priv` AS `Show_db_priv`,`mysql`.`user`.`Super_priv` AS `Super_priv`,`mysql`.`user`.`Create_tmp_table_priv` AS `Create_tmp_table_priv`,`mysql`.`user`.`Lock_tables_priv` AS `Lock_tables_priv`,`mysql`.`user`.`Execute_priv` AS `Execute_priv`,`mysql`.`user`.`Repl_slave_priv` AS `Repl_slave_priv`,`mysql`.`user`.`Repl_client_priv` AS `Repl_client_priv`,`mysql`.`user`.`Create_view_priv` AS `Create_view_priv`,`mysql`.`user`.`Show_view_priv` AS `Show_view_priv`,`mysql`.`user`.`Create_routine_priv` AS `Create_routine_priv`,`mysql`.`user`.`Alter_routine_priv` AS `Alter_routine_priv`,`mysql`.`user`.`Create_user_priv` AS `Create_user_priv`,`mysql`.`user`.`ssl_type` AS `ssl_type`,`mysql`.`user`.`ssl_cipher` AS `ssl_cipher`,`mysql`.`user`.`x509_issuer` AS `x509_issuer`,`mysql`.`user`.`x509_subject` AS `x509_subject`,`mysql`.`user`.`max_questions` AS `max_questions`,`mysql`.`user`.`max_updates` AS `max_updates`,`mysql`.`user`.`max_connections` AS `max_connections`,`mysql`.`user`.`max_user_connections` AS `max_user_connections` from `mysql`.`user`');
}
}
\ No newline at end of file
<?php
namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\Tests\TestUtil;
use Doctrine\DBAL\Schema;
require_once __DIR__ . '/../../../TestInit.php';
class MysqlSchemaTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
private $_conn;
protected function setUp()
{
$this->_conn = TestUtil::getConnection();
if ($this->_conn->getDatabasePlatform()->getName() !== 'mysql')
{
$this->markTestSkipped('The MySqlSchemaTest requires the use of mysql');
}
$this->_sm = new Schema\MySqlSchemaManager($this->_conn);
}
public function testListTableColumns()
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'length' => 255
)
);
$options = array();
try {
$this->_sm->dropTable('list_tables_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_tables_test', $columns, $options);
$columns = $this->_sm->listTableColumns('list_tables_test');
$this->assertEquals($columns[0]['name'], 'id');
$this->assertEquals($columns[0]['primary'], true);
$this->assertEquals(get_class($columns[0]['type']), 'Doctrine\DBAL\Types\IntegerType');
$this->assertEquals($columns[0]['length'], 4);
$this->assertEquals($columns[0]['unsigned'], false);
$this->assertEquals($columns[0]['fixed'], false);
$this->assertEquals($columns[0]['notnull'], true);
$this->assertEquals($columns[0]['default'], null);
$this->assertEquals($columns[1]['name'], 'test');
$this->assertEquals($columns[1]['primary'], false);
$this->assertEquals(get_class($columns[1]['type']), 'Doctrine\DBAL\Types\StringType');
$this->assertEquals($columns[1]['length'], 255);
$this->assertEquals($columns[1]['unsigned'], false);
$this->assertEquals($columns[1]['fixed'], false);
$this->assertEquals($columns[1]['notnull'], false);
$this->assertEquals($columns[1]['default'], null);
}
}
\ No newline at end of file
<?php
namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\Tests\TestUtil;
use Doctrine\DBAL\Schema;
require_once __DIR__ . '/../../../TestInit.php';
class SqliteSchemaTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
private $_conn;
protected function setUp()
{
$this->_conn = TestUtil::getConnection();
if ($this->_conn->getDatabasePlatform()->getName() !== 'sqlite')
{
$this->markTestSkipped('The SqliteSchemaTest requires the use of sqlite');
}
$this->_sm = new Schema\SqliteSchemaManager($this->_conn);
}
public function testListTableColumns()
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'length' => 255
)
);
$options = array();
$this->_sm->createTable('list_tables_test', $columns, $options);
$columns = $this->_sm->listTableColumns('list_tables_test');
$this->assertEquals($columns[0]['name'], 'id');
$this->assertEquals($columns[0]['primary'], true);
$this->assertEquals(get_class($columns[0]['type']), 'Doctrine\DBAL\Types\IntegerType');
$this->assertEquals($columns[0]['length'], 4);
$this->assertEquals($columns[0]['unsigned'], false);
$this->assertEquals($columns[0]['fixed'], false);
$this->assertEquals($columns[0]['notnull'], true);
$this->assertEquals($columns[0]['default'], null);
$this->assertEquals($columns[1]['name'], 'test');
$this->assertEquals($columns[1]['primary'], false);
$this->assertEquals(get_class($columns[1]['type']), 'Doctrine\DBAL\Types\StringType');
$this->assertEquals($columns[1]['length'], 255);
$this->assertEquals($columns[1]['unsigned'], false);
$this->assertEquals($columns[1]['fixed'], false);
$this->assertEquals($columns[1]['notnull'], false);
$this->assertEquals($columns[1]['default'], null);
}
}
\ No newline at end of file
......@@ -53,4 +53,9 @@ class DriverMock implements \Doctrine\DBAL\Driver
{
return 'mock';
}
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
return;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment