DriverTest.php 3.53 KB
Newer Older
1 2 3 4 5 6
<?php

namespace Doctrine\Tests\DBAL\Driver\PDOPgSql;

use Doctrine\DBAL\Driver\PDOPgSql\Driver;
use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest;
7
use PDO;
8
use PDOException;
9
use function defined;
10 11 12 13 14

class DriverTest extends AbstractPostgreSQLDriverTest
{
    public function testReturnsName()
    {
15
        self::assertSame('pdo_pgsql', $this->driver->getName());
16 17
    }

18 19 20
    /**
     * @group DBAL-920
     */
21 22
    public function testConnectionDisablesPreparesOnPhp56()
    {
23
        $this->skipWhenNotUsingPhp56AndPdoPgsql();
24

25
        $connection = $this->createDriver()->connect(
26
            array(
27 28
                'host' => $GLOBALS['db_host'],
                'port' => $GLOBALS['db_port']
29 30 31 32 33
            ),
            $GLOBALS['db_username'],
            $GLOBALS['db_password']
        );

34
        self::assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection);
35 36

        try {
37
            self::assertTrue($connection->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES));
38 39
        } catch (PDOException $ignored) {
            /** @link https://bugs.php.net/bug.php?id=68371 */
40
            $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371');
41
        }
42 43
    }

44 45 46
    /**
     * @group DBAL-920
     */
47 48 49 50 51 52
    public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined()
    {
        $this->skipWhenNotUsingPhp56AndPdoPgsql();

        $connection = $this->createDriver()->connect(
            array(
53 54
                'host' => $GLOBALS['db_host'],
                'port' => $GLOBALS['db_port']
55 56 57 58 59 60
            ),
            $GLOBALS['db_username'],
            $GLOBALS['db_password'],
            array(PDO::PGSQL_ATTR_DISABLE_PREPARES => false)
        );

61
        self::assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection);
62 63

        try {
64
            self::assertNotSame(true, $connection->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES));
65 66
        } catch (PDOException $ignored) {
            /** @link https://bugs.php.net/bug.php?id=68371 */
67
            $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371');
68
        }
69 70
    }

71 72 73
    /**
     * @group DBAL-920
     */
74 75 76 77 78 79
    public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplicitlyDefined()
    {
        $this->skipWhenNotUsingPhp56AndPdoPgsql();

        $connection = $this->createDriver()->connect(
            array(
80 81
                'host' => $GLOBALS['db_host'],
                'port' => $GLOBALS['db_port']
82 83 84 85 86 87
            ),
            $GLOBALS['db_username'],
            $GLOBALS['db_password'],
            array(PDO::PGSQL_ATTR_DISABLE_PREPARES => true)
        );

88
        self::assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection);
89 90

        try {
91
            self::assertTrue($connection->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES));
92 93
        } catch (PDOException $ignored) {
            /** @link https://bugs.php.net/bug.php?id=68371 */
94
            $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371');
95
        }
96 97
    }

98 99 100
    /**
     * {@inheritDoc}
     */
101 102 103 104
    protected function createDriver()
    {
        return new Driver();
    }
105 106 107 108 109 110

    /**
     * @throws \PHPUnit_Framework_SkippedTestError
     */
    private function skipWhenNotUsingPhp56AndPdoPgsql()
    {
111
        if (! defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')) {
112 113 114
            $this->markTestSkipped('Test requires PHP 5.6+');
        }

115
        if (! (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql')) {
116 117 118
            $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml');
        }
    }
119
}