CacheTest.php 809 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 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 42 43 44
<?php

namespace yiiunit\extensions\mongodb;

use Yii;
use yii\mongodb\Cache;

class CacheTest extends MongoDbTestCase
{
	/**
	 * @var string test cache collection name.
	 */
	protected static $cacheCollection = '_test_cache';

	protected function tearDown()
	{
		$this->dropCollection(static::$cacheCollection);
		parent::tearDown();
	}

	/**
	 * Creates test cache instance.
	 * @return Cache cache instance.
	 */
	protected function createCache()
	{
		return Yii::createObject([
			'class' => Cache::className(),
			'db' => $this->getConnection(),
			'cacheCollection' => static::$cacheCollection,
		]);
	}

	// Tests:

	public function testSet()
	{
		$cache = $this->createCache();

		$key = 'test_key';
		$value = 'test_value';
		$this->assertTrue($cache->set($key, $value), 'Unable to set value!');
	}
}