Yii2 framework backup
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

<?php
namespace yiiunit\framework\web;
use Yii;
use yii\caching\FileCache;
use yii\web\CacheSession;
/**
* @group web
*/
class CacheSessionTest extends \yiiunit\TestCase
{
protected function setUp()
{
parent::setUp();
$this->mockApplication();
Yii::$app->set('cache', new FileCache());
}
public function testCacheSession()
{
$session = new CacheSession();
$session->writeSession('test', 'sessionData');
$this->assertEquals('sessionData', $session->readSession('test'));
$session->destroySession('test');
$this->assertEquals('', $session->readSession('test'));
}
public function testInvalidCache()
{
11 years ago
$this->setExpectedException('\Exception');
new CacheSession(['cache' => 'invalid']);
}
/**
* @see https://github.com/yiisoft/yii2/issues/13537
*/
public function testNotWrittenSessionDestroying()
{
$session = new CacheSession();
$session->set('foo', 'bar');
$this->assertEquals('bar', $session->get('foo'));
$this->assertTrue($session->destroySession($session->getId()));
}
}