Completed
Pull Request — develop (#3582)
by Jonathan
64:18
created

DriverTest::skipWhenNotUsingPhp56AndPdoPgsql()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\DBAL\Driver\PDOPgSql;
6
7
use Doctrine\DBAL\Driver as DriverInterface;
8
use Doctrine\DBAL\Driver\PDOConnection;
9
use Doctrine\DBAL\Driver\PDOPgSql\Driver;
10
use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest;
11
use PDO;
12
use PHPUnit\Framework\SkippedTestError;
13
use function defined;
14
15
class DriverTest extends AbstractPostgreSQLDriverTest
16
{
17
    protected function setUp() : void
18
    {
19
        parent::setUp();
20
21
        if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql') {
22
            return;
23
        }
24
25
        $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml');
26
    }
27
28
    /**
29
     * @group DBAL-920
30
     */
31
    public function testConnectionDisablesPrepares() : void
32
    {
33
        $connection = $this->createDriver()->connect(
34
            [
35
                'host' => $GLOBALS['db_host'],
36
                'port' => $GLOBALS['db_port'],
37
            ],
38
            $GLOBALS['db_username'],
39
            $GLOBALS['db_password']
40
        );
41
42
        self::assertInstanceOf(PDOConnection::class, $connection);
43
        self::assertTrue(
44
            $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...
45
        );
46
    }
47
48
    /**
49
     * @group DBAL-920
50
     */
51
    public function testConnectionDoesNotDisablePreparesWhenAttributeDefined() : void
52
    {
53
        $connection = $this->createDriver()->connect(
54
            [
55
                'host' => $GLOBALS['db_host'],
56
                'port' => $GLOBALS['db_port'],
57
            ],
58
            $GLOBALS['db_username'],
59
            $GLOBALS['db_password'],
60
            [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...
61
        );
62
63
        self::assertInstanceOf(PDOConnection::class, $connection);
64
        self::assertNotTrue(
65
            $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)
66
        );
67
    }
68
69
    /**
70
     * @group DBAL-920
71
     */
72
    public function testConnectionDisablePreparesWhenDisablePreparesIsExplicitlyDefined() : void
73
    {
74
        $connection = $this->createDriver()->connect(
75
            [
76
                'host' => $GLOBALS['db_host'],
77
                'port' => $GLOBALS['db_port'],
78
            ],
79
            $GLOBALS['db_username'],
80
            $GLOBALS['db_password'],
81
            [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...
82
        );
83
84
        self::assertInstanceOf(PDOConnection::class, $connection);
85
        self::assertTrue(
86
            $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)
87
        );
88
    }
89
90
    /**
91
     * {@inheritDoc}
92
     */
93
    protected function createDriver() : DriverInterface
94
    {
95
        return new Driver();
96
    }
97
98
    /**
99
     * @throws SkippedTestError
100
     */
101
    private function skipWhenNotUsingPhp56AndPdoPgsql() : void
0 ignored issues
show
Unused Code introduced by
The method skipWhenNotUsingPhp56AndPdoPgsql() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
102
    {
103
        if (! defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')) {
104
            $this->markTestSkipped('Test requires PHP 5.6+');
105
        }
106
107
        if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql') {
108
            return;
109
        }
110
111
        $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml');
112
    }
113
}
114