SqliteSchemaManagerTest.php 2.41 KB
Newer Older
1 2 3 4
<?php

namespace Doctrine\Tests\DBAL\Functional\Schema;

5 6
use Doctrine\DBAL\Schema\ForeignKeyConstraint;

7 8 9
use Doctrine\DBAL\Schema;

require_once __DIR__ . '/../../../TestInit.php';
10

romanb's avatar
romanb committed
11
class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
12
{
romanb's avatar
romanb committed
13
    /**
14
     * SQLITE does not support databases.
15 16
     *
     * @expectedException \Doctrine\DBAL\DBALException
romanb's avatar
romanb committed
17
     */
18 19
    public function testListDatabases()
    {
romanb's avatar
romanb committed
20
        $this->_sm->listDatabases();
21 22 23 24 25 26
    }

    public function testCreateAndDropDatabase()
    {
        $path = dirname(__FILE__).'/test_create_and_drop_sqlite_database.sqlite';

jwage's avatar
jwage committed
27
        $this->_sm->createDatabase($path);
28
        $this->assertEquals(true, file_exists($path));
jwage's avatar
jwage committed
29
        $this->_sm->dropDatabase($path);
30
        $this->assertEquals(false, file_exists($path));
jwage's avatar
jwage committed
31
    }
32 33 34

    public function testRenameTable()
    {
35
        $this->createTestTable('oldname');
romanb's avatar
romanb committed
36
        $this->_sm->renameTable('oldname', 'newname');
37 38 39 40

        $tables = $this->_sm->listTableNames();
        $this->assertContains('newname', $tables);
        $this->assertNotContains('oldname', $tables);
41
    }
42

43
    public function createListTableColumns()
44
    {
45 46 47 48
        $table = parent::createListTableColumns();
        $table->getColumn('id')->setAutoincrement(true);

        return $table;
49
    }
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

    public function testListForeignKeysFromExistingDatabase()
    {
        $this->_conn->executeQuery(<<<EOS
CREATE TABLE user (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    page INTEGER CONSTRAINT FK_1 REFERENCES page (key) DEFERRABLE INITIALLY DEFERRED,
    parent INTEGER REFERENCES user(id) ON DELETE CASCADE,
    log INTEGER,
    CONSTRAINT FK_3 FOREIGN KEY (log) REFERENCES log ON UPDATE SET NULL NOT DEFERRABLE
)
EOS
        );

        $expected = array(
            new ForeignKeyConstraint(array('log'), 'log', array(null), 'FK_3',
                array('onUpdate' => 'SET NULL', 'onDelete' => 'NO ACTION', 'deferrable' => false, 'deferred' => false)),
            new ForeignKeyConstraint(array('parent'), 'user', array('id'), '1',
                array('onUpdate' => 'NO ACTION', 'onDelete' => 'CASCADE', 'deferrable' => false, 'deferred' => false)),
            new ForeignKeyConstraint(array('page'), 'page', array('key'), 'FK_1',
                array('onUpdate' => 'NO ACTION', 'onDelete' => 'NO ACTION', 'deferrable' => true, 'deferred' => true)),
        );

        $this->assertEquals($expected, $this->_sm->listTableForeignKeys('user'));
    }
75
}