CacheSessionTest.php 812 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php

namespace yiiunit\framework\web;

use Yii;
use yii\caching\FileCache;
use yii\web\CacheSession;

/**
 * @group web
 */
class CacheSessionTest extends \yiiunit\TestCase
{
14 15 16 17
    protected function setUp()
    {
        parent::setUp();
        $this->mockApplication();
18
        Yii::$app->set('cache', new FileCache());
19
    }
20

21 22 23
    public function testCacheSession()
    {
        $session = new CacheSession();
24

25 26 27 28 29
        $session->writeSession('test', 'sessionData');
        $this->assertEquals('sessionData', $session->readSession('test'));
        $session->destroySession('test');
        $this->assertEquals('', $session->readSession('test'));
    }
30

31 32
    public function testInvalidCache()
    {
Qiang Xue committed
33
        $this->setExpectedException('\Exception');
34 35
        new CacheSession(['cache' => 'invalid']);
    }
36
}