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

namespace yiiunit\extensions\sphinx;

use yii\caching\FileCache;

/**
 * @group sphinx
 */
class SchemaTest extends SphinxTestCase
{
12 13 14
    public function testFindIndexNames()
    {
        $schema = $this->getConnection()->schema;
15

16 17 18 19 20
        $indexes = $schema->getIndexNames();
        $this->assertContains('yii2_test_article_index', $indexes);
        $this->assertContains('yii2_test_item_index', $indexes);
        $this->assertContains('yii2_test_rt_index', $indexes);
    }
21

22 23 24
    public function testGetIndexSchemas()
    {
        $schema = $this->getConnection()->schema;
25

26 27 28 29 30 31
        $indexes = $schema->getIndexSchemas();
        $this->assertEquals(count($schema->getIndexNames()), count($indexes));
        foreach ($indexes as $index) {
            $this->assertInstanceOf('yii\sphinx\IndexSchema', $index);
        }
    }
32

33 34 35 36
    public function testGetNonExistingIndexSchema()
    {
        $this->assertNull($this->getConnection()->schema->getIndexSchema('non_existing_index'));
    }
37

38 39 40
    public function testSchemaRefresh()
    {
        $schema = $this->getConnection()->schema;
41

42 43 44 45 46 47
        $schema->db->enableSchemaCache = true;
        $schema->db->schemaCache = new FileCache();
        $noCacheIndex = $schema->getIndexSchema('yii2_test_rt_index', true);
        $cachedIndex = $schema->getIndexSchema('yii2_test_rt_index', true);
        $this->assertEquals($noCacheIndex, $cachedIndex);
    }
48

49 50 51 52 53 54 55 56 57 58 59 60 61
    public function testGetPDOType()
    {
        $values = [
            [null, \PDO::PARAM_NULL],
            ['', \PDO::PARAM_STR],
            ['hello', \PDO::PARAM_STR],
            [0, \PDO::PARAM_INT],
            [1, \PDO::PARAM_INT],
            [1337, \PDO::PARAM_INT],
            [true, \PDO::PARAM_BOOL],
            [false, \PDO::PARAM_BOOL],
            [$fp = fopen(__FILE__, 'rb'), \PDO::PARAM_LOB],
        ];
62

63
        $schema = $this->getConnection()->schema;
64

65 66 67 68 69
        foreach ($values as $value) {
            $this->assertEquals($value[1], $schema->getPdoType($value[0]));
        }
        fclose($fp);
    }
70

71 72 73
    public function testIndexType()
    {
        $schema = $this->getConnection()->schema;
74

75 76 77
        $index = $schema->getIndexSchema('yii2_test_article_index');
        $this->assertEquals('local', $index->type);
        $this->assertFalse($index->isRuntime);
78

79 80 81 82
        $index = $schema->getIndexSchema('yii2_test_rt_index');
        $this->assertEquals('rt', $index->type);
        $this->assertTrue($index->isRuntime);
    }
Luciano Baraglia committed
83
}