ConnectionTest.php 1.55 KB
Newer Older
till's avatar
till committed
1
<?php
2
namespace Doctrine\Tests\DBAL\Functional\Driver\Mysqli;
till's avatar
till committed
3 4 5

class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
6
    protected function setUp()
till's avatar
till committed
7 8 9 10 11 12
    {
        if (!extension_loaded('mysqli')) {
            $this->markTestSkipped('mysqli is not installed.');
        }

        parent::setUp();
13 14 15 16

        if ( !($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\Mysqli\Driver)) {
            $this->markTestSkipped('MySQLi only test.');
        }
till's avatar
till committed
17 18
    }

19
    protected function tearDown()
till's avatar
till committed
20 21 22 23 24 25 26 27 28 29 30
    {
        parent::tearDown();
    }

    public function testDriverOptions()
    {
        $driverOptions = array(
            \MYSQLI_OPT_CONNECT_TIMEOUT => 1,
        );

        $connection = $this->getConnection($driverOptions);
31
        self::assertInstanceOf("\Doctrine\DBAL\Driver\Mysqli\MysqliConnection", $connection);
till's avatar
till committed
32 33 34 35 36 37 38 39 40 41
    }

    /**
     * @expectedException \Doctrine\DBAL\Driver\Mysqli\MysqliException
     */
    public function testUnsupportedDriverOption()
    {
        $this->getConnection(array('hello' => 'world')); // use local infile
    }

42 43 44
    public function testPing()
    {
        $conn = $this->getConnection(array());
45
        self::assertTrue($conn->ping());
46 47
    }

till's avatar
till committed
48 49 50 51 52 53 54 55 56 57 58 59
    private function getConnection(array $driverOptions)
    {
        return new \Doctrine\DBAL\Driver\Mysqli\MysqliConnection(
            array(
                 'host' => $GLOBALS['db_host'],
                 'dbname' => $GLOBALS['db_name'],
            ),
            $GLOBALS['db_username'],
            $GLOBALS['db_password'],
            $driverOptions
        );
    }
60
}