ConnectionTest.php 1.31 KB
Newer Older
1 2
<?php

3
namespace Doctrine\DBAL\Tests\Functional\Driver\IBMDB2;
4

5 6
use Doctrine\DBAL\Driver\IBMDB2\Connection;
use Doctrine\DBAL\Driver\IBMDB2\Driver;
7 8
use Doctrine\DBAL\Driver\IBMDB2\Exception\ConnectionFailed;
use Doctrine\DBAL\Driver\IBMDB2\Exception\PrepareFailed;
9
use Doctrine\DBAL\Tests\FunctionalTestCase;
10 11 12 13
use ReflectionProperty;

use function db2_close;

14 15 16
/**
 * @require extension ibm_db2
 */
17
class ConnectionTest extends FunctionalTestCase
18 19 20 21 22
{
    protected function setUp(): void
    {
        parent::setUp();

23
        if ($this->connection->getDriver() instanceof Driver) {
24 25 26 27 28 29 30 31 32 33 34 35 36 37
            return;
        }

        $this->markTestSkipped('ibm_db2 only test.');
    }

    protected function tearDown(): void
    {
        $this->resetSharedConn();
    }

    public function testConnectionFailure(): void
    {
        $this->expectException(ConnectionFailed::class);
38
        new Connection('garbage', false, '', '');
39 40 41 42 43 44
    }

    public function testPrepareFailure(): void
    {
        $driverConnection = $this->connection->getWrappedConnection();

45
        $re = new ReflectionProperty($driverConnection, 'conn');
46 47 48 49 50 51 52 53
        $re->setAccessible(true);
        $conn = $re->getValue($driverConnection);
        db2_close($conn);

        $this->expectException(PrepareFailed::class);
        $driverConnection->prepare('SELECT 1');
    }
}