Failed Conditions
Pull Request — develop (#3553)
by Sergei
100:55 queued 35:51
created

DriverTest::testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplicitlyDefined()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 21
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A DriverTest::createDriver() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\DBAL\Driver\PDOPgSql;
6
7
use Doctrine\DBAL\Driver\PDOConnection;
8
use Doctrine\DBAL\Driver\PDOPgSql\Driver;
9
use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest;
10
use PDO;
11
12
class DriverTest extends AbstractPostgreSQLDriverTest
13
{
14
    protected function setUp() : void
15
    {
16
        parent::setUp();
17
18
        if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql') {
19
            return;
20
        }
21
22
        $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml');
23
    }
24
25
    /**
26
     * @group DBAL-920
27
     */
28
    public function testConnectionDisablesPrepares()
29
    {
30
        $connection = $this->createDriver()->connect(
31
            [
32
                'host' => $GLOBALS['db_host'],
33
                'port' => $GLOBALS['db_port'],
34
            ],
35
            $GLOBALS['db_username'],
36
            $GLOBALS['db_password']
37
        );
38
39
        self::assertInstanceOf(PDOConnection::class, $connection);
40
        self::assertTrue(
41
            $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)
0 ignored issues
show
Bug introduced by
The constant PDO::PGSQL_ATTR_DISABLE_PREPARES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
42
        );
43
    }
44
45
    /**
46
     * @group DBAL-920
47
     */
48
    public function testConnectionDoesNotDisablePreparesWhenAttributeDefined()
49
    {
50
        $connection = $this->createDriver()->connect(
51
            [
52
                'host' => $GLOBALS['db_host'],
53
                'port' => $GLOBALS['db_port'],
54
            ],
55
            $GLOBALS['db_username'],
56
            $GLOBALS['db_password'],
57
            [PDO::PGSQL_ATTR_DISABLE_PREPARES => false]
0 ignored issues
show
Bug introduced by
The constant PDO::PGSQL_ATTR_DISABLE_PREPARES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
58
        );
59
60
        self::assertInstanceOf(PDOConnection::class, $connection);
61
        self::assertNotTrue(
62
            $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)
63
        );
64
    }
65
66
    /**
67
     * @group DBAL-920
68
     */
69
    public function testConnectionDisablePreparesWhenDisablePreparesIsExplicitlyDefined()
70
    {
71
        $connection = $this->createDriver()->connect(
72
            [
73
                'host' => $GLOBALS['db_host'],
74
                'port' => $GLOBALS['db_port'],
75
            ],
76
            $GLOBALS['db_username'],
77
            $GLOBALS['db_password'],
78
            [PDO::PGSQL_ATTR_DISABLE_PREPARES => true]
0 ignored issues
show
Bug introduced by
The constant PDO::PGSQL_ATTR_DISABLE_PREPARES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
79
        );
80
81
        self::assertInstanceOf(PDOConnection::class, $connection);
82
        self::assertTrue(
83
            $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)
84
        );
85
    }
86
87
    /**
88
     * {@inheritDoc}
89
     */
90
    protected function createDriver()
91
    {
92
        return new Driver();
93
    }
94
}
95