2009-05-29 01:34:35 +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 PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
2009-05-29 01:34:35 +04:00
|
|
|
{
|
|
|
|
public function testListDatabases()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->_sm->dropAndCreateDatabase('test_create_database');
|
2009-05-29 01:34:35 +04:00
|
|
|
$databases = $this->_sm->listDatabases();
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->assertEquals(true, in_array('test_create_database', $databases));
|
2009-05-29 01:34:35 +04:00
|
|
|
}
|
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
2009-05-29 01:34:35 +04:00
|
|
|
public function testListFunctions()
|
|
|
|
{
|
2009-06-15 22:25:47 +04:00
|
|
|
$this->_sm->listFunctions();
|
2009-05-29 01:34:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testListTriggers()
|
|
|
|
{
|
|
|
|
$triggers = $this->_sm->listTriggers();
|
|
|
|
$this->assertEquals(true, is_array($triggers));
|
|
|
|
$this->assertEquals(true, count($triggers) > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testListSequences()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('list_sequences_test');
|
2009-05-29 01:34:35 +04:00
|
|
|
$sequences = $this->_sm->listSequences();
|
|
|
|
$this->assertEquals(true, in_array('list_sequences_test_id_seq', $sequences));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testListTableConstraints()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('list_table_constraints_test');
|
2009-05-29 01:34:35 +04:00
|
|
|
$tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test');
|
|
|
|
$this->assertEquals(array('list_table_constraints_test_pkey'), $tableConstraints);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testListTableColumns()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('list_tables_test');
|
2009-05-29 01:34:35 +04:00
|
|
|
$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']));
|
2009-10-15 00:18:36 +04:00
|
|
|
$this->assertEquals(null, $columns[0]['length']);
|
2009-05-29 01:34:35 +04:00
|
|
|
$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]['fixed']);
|
|
|
|
$this->assertEquals(false, $columns[1]['notnull']);
|
|
|
|
$this->assertEquals(null, $columns[1]['default']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testListTableIndexes()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$data['options'] = array(
|
2009-05-29 01:34:35 +04:00
|
|
|
'indexes' => array(
|
|
|
|
'test' => array(
|
2009-10-07 02:38:34 +04:00
|
|
|
'columns' => array(
|
2009-05-29 01:34:35 +04:00
|
|
|
'test' => array()
|
|
|
|
),
|
|
|
|
'type' => 'unique'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('list_table_indexes_test', $data);
|
2009-05-29 01:34:35 +04:00
|
|
|
$tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test');
|
|
|
|
$this->assertEquals('test', $tableIndexes[0]['name']);
|
|
|
|
$this->assertEquals(true, $tableIndexes[0]['unique']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testListTables()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->createTestTable('list_tables_test');
|
2009-05-29 01:34:35 +04:00
|
|
|
$tables = $this->_sm->listTables();
|
|
|
|
$this->assertEquals(true, in_array('list_tables_test', $tables));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testListUsers()
|
|
|
|
{
|
|
|
|
$users = $this->_sm->listUsers();
|
|
|
|
$this->assertEquals(true, is_array($users));
|
|
|
|
$params = $this->_conn->getParams();
|
|
|
|
$testUser = $params['user'];
|
|
|
|
$found = false;
|
|
|
|
foreach ($users as $user) {
|
|
|
|
if ($user['user'] == $testUser) {
|
|
|
|
$found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->assertEquals(true, $found);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testListViews()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->_sm->dropAndCreateView('test_create_view', 'SELECT usename, passwd FROM pg_user');
|
2009-05-29 01:34:35 +04:00
|
|
|
$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()
|
|
|
|
{
|
2009-05-30 06:27:50 +04:00
|
|
|
$data['options'] = array('type' => 'innodb');
|
|
|
|
$this->createTestTable('list_table_foreign_keys_test1', $data);
|
|
|
|
$this->createTestTable('list_table_foreign_keys_test2', $data);
|
2009-05-29 01:34:35 +04:00
|
|
|
|
|
|
|
$definition = array(
|
|
|
|
'name' => 'testing',
|
2009-05-30 06:27:50 +04:00
|
|
|
'local' => 'foreign_key_test',
|
2009-05-29 01:34:35 +04:00
|
|
|
'foreign' => 'id',
|
2009-05-30 06:27:50 +04:00
|
|
|
'foreignTable' => 'list_table_foreign_keys_test2'
|
2009-05-29 01:34:35 +04:00
|
|
|
);
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->_sm->createForeignKey('list_table_foreign_keys_test1', $definition);
|
2009-05-29 01:34:35 +04:00
|
|
|
|
2009-05-30 06:27:50 +04:00
|
|
|
$tableForeignKeys = $this->_sm->listTableForeignKeys('list_table_foreign_keys_test1');
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals(1, count($tableForeignKeys));
|
2009-05-30 06:27:50 +04:00
|
|
|
$this->assertEquals('list_table_foreign_keys_test2', $tableForeignKeys[0]['table']);
|
|
|
|
$this->assertEquals('foreign_key_test', $tableForeignKeys[0]['local']);
|
2009-05-29 01:34:35 +04:00
|
|
|
$this->assertEquals('id', $tableForeignKeys[0]['foreign']);
|
|
|
|
}
|
|
|
|
}
|