2009-05-28 06:04:51 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\DBAL\Functional\Schema;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Schema;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../../TestInit.php';
|
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
2009-05-28 06:04:51 +04:00
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testListDatabases()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->listDatabases();
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testListFunctions()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->listFunctions();
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testListTriggers()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->listTriggers();
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testListSequences()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('list_sequences_test');
|
2009-05-28 06:04:51 +04:00
|
|
|
$sequences = $this->_sm->listSequences();
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals('list_sequences_test', $sequences[0]['name']);
|
|
|
|
$this->assertEquals('sqlite_sequence', $sequences[1]['name']);
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testListTableConstraints()
|
|
|
|
{
|
|
|
|
// TODO: Implement support for constraints/foreign keys to be specified
|
|
|
|
// when creating tables. Sqlite does not support adding them after
|
|
|
|
// the table has already been created
|
|
|
|
$tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test');
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals(array(), $tableConstraints);
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testListTableColumns()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('list_table_columns_test');
|
2009-05-28 06:04:51 +04:00
|
|
|
|
|
|
|
$tableColumns = $this->_sm->listTableColumns('list_table_columns_test');
|
|
|
|
|
2009-05-29 01:34:35 +04:00
|
|
|
$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(4, $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']);
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testListTableIndexes()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$data['options'] = array(
|
2009-05-28 06:04:51 +04:00
|
|
|
'indexes' => array(
|
|
|
|
'test' => array(
|
|
|
|
'fields' => array(
|
|
|
|
'test' => array()
|
|
|
|
),
|
|
|
|
'type' => 'unique'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('list_table_indexes_test', $data);
|
2009-05-28 06:04:51 +04:00
|
|
|
|
|
|
|
$tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test');
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals('test', $tableIndexes[0]['name']);
|
|
|
|
$this->assertEquals(true, $tableIndexes[0]['unique']);
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-05-29 01:34:35 +04:00
|
|
|
public function testListTables()
|
2009-05-28 06:04:51 +04:00
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('list_tables_test');
|
2009-05-28 06:04:51 +04:00
|
|
|
$tables = $this->_sm->listTables();
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals(true, in_array('list_tables_test', $tables));
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testListUsers()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->listUsers();
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testListViews()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('test_views');
|
|
|
|
$this->_sm->dropAndCreateView('test_create_view', 'SELECT * from test_views');
|
2009-05-28 06:04:51 +04:00
|
|
|
$views = $this->_sm->listViews();
|
|
|
|
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals('test_create_view', $views[0]['name']);
|
|
|
|
$this->assertEquals('CREATE VIEW test_create_view AS SELECT * from test_views', $views[0]['sql']);
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-05-30 13:37:56 +04:00
|
|
|
/* FIXME: Using ORM in DBAL test suite. Not OK!!
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testCreateAndDropDatabase()
|
|
|
|
{
|
|
|
|
$path = dirname(__FILE__).'/test_create_and_drop_sqlite_database.sqlite';
|
|
|
|
$config = new \Doctrine\ORM\Configuration();
|
|
|
|
$eventManager = new \Doctrine\Common\EventManager();
|
|
|
|
$connectionOptions = array(
|
|
|
|
'driver' => 'pdo_sqlite',
|
|
|
|
'path' => $path
|
|
|
|
);
|
|
|
|
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config, $eventManager);
|
|
|
|
$conn = $em->getConnection();
|
|
|
|
$sm = $conn->getSchemaManager();
|
|
|
|
|
|
|
|
$sm->createDatabase();
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals(true, file_exists($path));
|
2009-05-28 06:04:51 +04:00
|
|
|
$sm->dropDatabase();
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals(false, file_exists($path));
|
2009-05-28 06:04:51 +04:00
|
|
|
$sm->createDatabase();
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals(true, file_exists($path));
|
2009-05-28 06:04:51 +04:00
|
|
|
$sm->dropDatabase();
|
2009-05-30 13:37:56 +04:00
|
|
|
}*/
|
2009-05-28 06:04:51 +04:00
|
|
|
|
|
|
|
public function testCreateTable()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('test_create_table');
|
2009-05-28 06:04:51 +04:00
|
|
|
$tables = $this->_sm->listTables();
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals(true, in_array('test_create_table', $tables));
|
2009-05-28 06:04:51 +04:00
|
|
|
|
|
|
|
$tableColumns = $this->_sm->listTableColumns('test_create_table');
|
|
|
|
|
2009-05-29 01:34:35 +04:00
|
|
|
$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(4, $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']);
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testCreateSequence()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->createSequence('seqname', 1, 1);
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
2009-05-30 13:37:56 +04:00
|
|
|
|
|
|
|
/* FIXME: See comment in AbstractSchemaManager#dropIndex($table, $name)
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testCreateIndex()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('test_create_index');
|
2009-05-28 06:04:51 +04:00
|
|
|
|
|
|
|
$index = array(
|
|
|
|
'fields' => array(
|
|
|
|
'test' => array()
|
|
|
|
),
|
|
|
|
'type' => 'unique'
|
|
|
|
);
|
2009-05-30 13:37:56 +04:00
|
|
|
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->_sm->dropAndCreateIndex('test_create_index', 'test', $index);
|
2009-05-28 06:04:51 +04:00
|
|
|
$tableIndexes = $this->_sm->listTableIndexes('test_create_index');
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals('test', $tableIndexes[0]['name']);
|
|
|
|
$this->assertEquals(true, $tableIndexes[0]['unique']);
|
2009-05-30 13:37:56 +04:00
|
|
|
}*/
|
2009-05-28 06:04:51 +04:00
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testCreateForeignKey()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->createForeignKey('table', array());
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testRenameTable()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->renameTable('oldname', 'newname');
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testAddTableColumn()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
return $this->_sm->addTableColumn('table', 'column', array());
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testRemoveTableColumn()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->removeTableColumn('table', 'column');
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testChangeTableColumn()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->changeTableColumn('name', 'type', null, array());
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
2009-06-15 22:25:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-28 06:04:51 +04:00
|
|
|
public function testRenameTableColumn()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->renameTableColumn('table', 'old', 'new', array());
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
}
|