AbstractSQLiteDriverTest.php 2.66 KB
Newer Older
1 2
<?php

3
namespace Doctrine\DBAL\Tests\Driver;
4 5

use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Driver;
Sergei Morozov's avatar
Sergei Morozov committed
7
use Doctrine\DBAL\Driver\AbstractSQLiteDriver;
8
use Doctrine\DBAL\Platforms\AbstractPlatform;
9
use Doctrine\DBAL\Platforms\SqlitePlatform;
10
use Doctrine\DBAL\Schema\AbstractSchemaManager;
11 12 13 14
use Doctrine\DBAL\Schema\SqliteSchemaManager;

class AbstractSQLiteDriverTest extends AbstractDriverTest
{
15
    public function testReturnsDatabaseName() : void
16
    {
Sergei Morozov's avatar
Sergei Morozov committed
17
        $params = [
18 19 20 21
            'user'     => 'foo',
            'password' => 'bar',
            'dbname'   => 'baz',
            'path'     => 'bloo',
Sergei Morozov's avatar
Sergei Morozov committed
22
        ];
23 24 25

        $connection = $this->getConnectionMock();

26
        $connection->expects(self::once())
27
            ->method('getParams')
28
            ->will(self::returnValue($params));
29

30
        self::assertSame($params['path'], $this->driver->getDatabase($connection));
31 32
    }

33
    protected function createDriver() : Driver
34
    {
Sergei Morozov's avatar
Sergei Morozov committed
35
        return $this->getMockForAbstractClass(AbstractSQLiteDriver::class);
36 37
    }

38
    protected function createPlatform() : AbstractPlatform
39 40 41 42
    {
        return new SqlitePlatform();
    }

43
    protected function createSchemaManager(Connection $connection) : AbstractSchemaManager
44 45 46 47
    {
        return new SqliteSchemaManager($connection);
    }

48 49 50 51
    /**
     * {@inheritDoc}
     */
    protected static function getExceptionConversionData() : array
52
    {
Sergei Morozov's avatar
Sergei Morozov committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
        return [
            self::EXCEPTION_CONNECTION => [
                [null, null, 'unable to open database file'],
            ],
            self::EXCEPTION_INVALID_FIELD_NAME => [
                [null, null, 'has no column named'],
            ],
            self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [
                [null, null, 'ambiguous column name'],
            ],
            self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [
                [null, null, 'may not be NULL'],
            ],
            self::EXCEPTION_READ_ONLY => [
                [null, null, 'attempt to write a readonly database'],
            ],
            self::EXCEPTION_SYNTAX_ERROR => [
                [null, null, 'syntax error'],
            ],
            self::EXCEPTION_TABLE_EXISTS => [
                [null, null, 'already exists'],
            ],
            self::EXCEPTION_TABLE_NOT_FOUND => [
                [null, null, 'no such table:'],
            ],
            self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [
                [null, null, 'must be unique'],
                [null, null, 'is not unique'],
                [null, null, 'are not unique'],
            ],
            self::EXCEPTION_LOCK_WAIT_TIMEOUT => [
                [null, null, 'database is locked'],
            ],
        ];
87 88
    }
}