RedisConnectionTest.php 1.16 KB
Newer Older
1 2
<?php

3
namespace yiiunit\extensions\redis;
4

5 6 7
/**
 * @group redis
 */
Carsten Brandt committed
8
class RedisConnectionTest extends RedisTestCase
9
{
10 11 12 13 14 15 16 17 18 19
    /**
     * test connection to redis and selection of db
     */
    public function testConnect()
    {
        $db = $this->getConnection(false);
        $db->open();
        $this->assertTrue($db->ping());
        $db->set('YIITESTKEY', 'YIITESTVALUE');
        $db->close();
20

21 22 23 24 25
        $db = $this->getConnection(false);
        $db->database = 0;
        $db->open();
        $this->assertEquals('YIITESTVALUE', $db->get('YIITESTKEY'));
        $db->close();
26

27 28 29 30 31 32
        $db = $this->getConnection(false);
        $db->database = 1;
        $db->open();
        $this->assertNull($db->get('YIITESTKEY'));
        $db->close();
    }
33

34 35 36 37 38 39 40 41 42 43 44
    public function keyValueData()
    {
        return [
            [123],
            [-123],
            [0],
            ['test'],
            ["test\r\ntest"],
            [''],
        ];
    }
45

46 47 48 49 50 51
    /**
     * @dataProvider keyValueData
     */
    public function testStoreGet($data)
    {
        $db = $this->getConnection(true);
52

53 54 55
        $db->set('hi', $data);
        $this->assertEquals($data, $db->get('hi'));
    }
Luciano Baraglia committed
56
}