ConnectionTest.php 1.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<?php

namespace yiiunit\extensions\sphinx;

use yii\sphinx\Connection;

/**
 * @group sphinx
 */
class ConnectionTest extends SphinxTestCase
{
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    public function testConstruct()
    {
        $connection = $this->getConnection(false);
        $params = $this->sphinxConfig;

        $this->assertEquals($params['dsn'], $connection->dsn);
        $this->assertEquals($params['username'], $connection->username);
        $this->assertEquals($params['password'], $connection->password);
    }

    public function testOpenClose()
    {
        $connection = $this->getConnection(false, false);

        $this->assertFalse($connection->isActive);
        $this->assertEquals(null, $connection->pdo);

        $connection->open();
        $this->assertTrue($connection->isActive);
        $this->assertTrue($connection->pdo instanceof \PDO);

        $connection->close();
        $this->assertFalse($connection->isActive);
        $this->assertEquals(null, $connection->pdo);

        $connection = new Connection;
        $connection->dsn = 'unknown::memory:';
        $this->setExpectedException('yii\db\Exception');
        $connection->open();
    }
AlexGx committed
42
}