From 802d5cf7d3f91ae2b3af39e5159bf21608c0ffe9 Mon Sep 17 00:00:00 2001 From: Szijarto Tamas Date: Tue, 12 May 2015 23:23:04 +0200 Subject: [PATCH] Test of APC cache --- tests/Xamin/Cache/APCTest.php | 100 ++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tests/Xamin/Cache/APCTest.php diff --git a/tests/Xamin/Cache/APCTest.php b/tests/Xamin/Cache/APCTest.php new file mode 100644 index 0000000..a215678 --- /dev/null +++ b/tests/Xamin/Cache/APCTest.php @@ -0,0 +1,100 @@ + + * @author Dmitriy Simushev + * @copyright 2013 (c) f0ruD A + * @license MIT + * @version GIT: $Id$ + * @link http://xamin.ir + */ + +/** + * Test of APC cache driver + * + * Run without sikp: + * php -d apc.enable_cli=1 ./vendor/bin/phpunit + * + * @category Xamin + * @package Handlebars + * @subpackage Test + * @author Tamás Szijártó + * @license MIT + * @version Release: @package_version@ + * @link http://xamin.ir + */ +class APCTest extends \PHPUnit_Framework_TestCase +{ + /** + * {@inheritdoc} + * + * @return void + */ + public function setUp() + { + if ( ! extension_loaded('apc') || false === @apc_cache_info()) { + $this->markTestSkipped('The ' . __CLASS__ .' requires the use of APC'); + } + } + + /** + * Return the new driver + * + * @param null|string $prefix optional key prefix, defaults to null + * + * @return \Handlebars\Cache\APC + */ + private function _getCacheDriver( $prefix = null ) + { + return new \Handlebars\Cache\APC($prefix); + } + + /** + * Test with cache prefix + * + * @return void + */ + public function testWithPrefix() + { + $prefix = __CLASS__; + $driver = $this->_getCacheDriver($prefix); + + $this->assertEquals(false, $driver->get('foo')); + + $driver->set('foo', 10); + $this->assertEquals(10, $driver->get('foo')); + + $driver->set('foo', array(12)); + $this->assertEquals(array(12), $driver->get('foo')); + + $driver->remove('foo'); + $this->assertEquals(false, $driver->get('foo')); + } + + /** + * Test without cache prefix + * + * @return void + */ + public function testWithoutPrefix() + { + $driver = $this->_getCacheDriver(); + + $this->assertEquals(false, $driver->get('foo')); + + $driver->set('foo', 20); + $this->assertEquals(20, $driver->get('foo')); + + $driver->set('foo', array(22)); + $this->assertEquals(array(22), $driver->get('foo')); + + $driver->remove('foo'); + $this->assertEquals(false, $driver->get('foo')); + } +} \ No newline at end of file