Completed
Pull Request — master (#3794)
by Benjamin
64:44
created

testReturnsDatabaseNameWithoutDatabaseNameParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlite;
6
7
use Doctrine\DBAL\Driver as DriverInterface;
8
use Doctrine\DBAL\Driver\PDOSqlite\Driver;
9
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
10
use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest;
11
use function extension_loaded;
12
13
class DriverTest extends AbstractDriverTest
14
{
15
    protected function setUp() : void
16
    {
17
        if (! extension_loaded('pdo_sqlite')) {
18
            $this->markTestSkipped('pdo_sqlite is not installed.');
19
        }
20
21
        parent::setUp();
22
23
        if ($this->connection->getDriver() instanceof Driver) {
24
            return;
25
        }
26
27
        $this->markTestSkipped('pdo_sqlite only test.');
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void
34
    {
35
        $this->markTestSkipped('SQLite does not support the concept of a database.');
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function createDriver() : DriverInterface
42
    {
43
        return new Driver();
44
    }
45
46
    protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
47
    {
48
        return '';
49
    }
50
51
    public function testForeignKeyConstraintViolationException() : void
52
    {
53
        $this->connection->exec('PRAGMA foreign_keys = ON');
54
55
        $this->connection->exec('
56
            CREATE TABLE parent (
57
                id INTEGER PRIMARY KEY
58
            )
59
        ');
60
61
        $this->connection->exec('
62
            CREATE TABLE child ( 
63
                id INTEGER PRIMARY KEY, 
64
                parent_id INTEGER,
65
                FOREIGN KEY (parent_id) REFERENCES parent(id)
66
            );
67
        ');
68
69
        $this->connection->exec('INSERT INTO parent (id) VALUES (1)');
70
        $this->connection->exec('INSERT INTO child (id, parent_id) VALUES (1, 1)');
71
        $this->connection->exec('INSERT INTO child (id, parent_id) VALUES (2, 1)');
72
73
        $this->expectException(ForeignKeyConstraintViolationException::class);
74
75
        $this->connection->exec('INSERT INTO child (id, parent_id) VALUES (3, 2)');
76
    }
77
}
78