File: DriverTest.php

package info (click to toggle)
php-doctrine-dbal 3.6.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,500 kB
  • sloc: php: 54,704; xml: 485; makefile: 42; sh: 24
file content (78 lines) | stat: -rw-r--r-- 2,314 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
75
76
77
78
<?php

namespace Doctrine\DBAL\Tests\Functional\Driver\SQLite3;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\SQLite3\Driver;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest;
use Doctrine\DBAL\Tests\TestUtil;

/** @requires extension sqlite3 */
class DriverTest extends AbstractDriverTest
{
    protected function setUp(): void
    {
        parent::setUp();

        if (TestUtil::isDriverOneOf('sqlite3')) {
            return;
        }

        self::markTestSkipped('This test requires the sqlite3 driver.');
    }

    protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter(): ?string
    {
        return 'main';
    }

    protected function createDriver(): DriverInterface
    {
        return new Driver();
    }

    public function testMissingMandatoryParams(): void
    {
        $params = $this->connection->getParams();
        unset($params['path'], $params['memory']);

        $this->expectException(DriverException::class);
        $this->expectExceptionMessage(
            'An exception occurred in the driver: '
                . 'Invalid connection settings: specify either the "path" or the "memory" parameter for SQLite3.',
        );

        $connection = new Connection(
            $params,
            $this->connection->getDriver(),
            $this->connection->getConfiguration(),
            $this->connection->getEventManager(),
        );

        $connection->fetchOne('SELECT 1');
    }

    public function testAmbiguousParams(): void
    {
        $params           = $this->connection->getParams();
        $params['path']   = __DIR__ . '/dont-create-me.db';
        $params['memory'] = true;

        $this->expectException(DriverException::class);
        $this->expectExceptionMessage(
            'An exception occurred in the driver: '
                . 'Invalid connection settings: specifying both parameters "path" and "memory" is ambiguous.',
        );

        $connection = new Connection(
            $params,
            $this->connection->getDriver(),
            $this->connection->getConfiguration(),
            $this->connection->getEventManager(),
        );

        $connection->fetchOne('SELECT 1');
    }
}