diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/InMemoryPoolCacheTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/InMemoryPoolCacheTest.php | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/InMemoryPoolCacheTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/InMemoryPoolCacheTest.php new file mode 100644 index 00000000..ea11cd54 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/InMemoryPoolCacheTest.php @@ -0,0 +1,87 @@ +<?php + +namespace SMW\Tests; + +use SMW\InMemoryPoolCache; + +/** + * @covers \SMW\InMemoryPoolCache + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.3 + * + * @author mwjames + */ +class InMemoryPoolCacheTest extends \PHPUnit_Framework_TestCase { + + protected function tearDown() { + InMemoryPoolCache::getInstance()->clear(); + parent::tearDown(); + } + + public function testCanConstruct() { + + $cacheFactory = $this->getMockBuilder( '\SMW\CacheFactory' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->assertInstanceOf( + '\SMW\InMemoryPoolCache', + new InMemoryPoolCache( $cacheFactory ) + ); + + $this->assertInstanceOf( + '\SMW\InMemoryPoolCache', + InMemoryPoolCache::getInstance() + ); + } + + public function testPoolCache() { + + $instance = InMemoryPoolCache::getInstance(); + + $this->assertInstanceOf( + '\Onoi\Cache\Cache', + $instance->getPoolCacheById( 'Foo' ) + ); + + $instance->getPoolCacheById( 'Foo' )->save( 'Bar', 42 ); + + $this->assertEquals( + 42, + $instance->getPoolCacheById( 'Foo' )->fetch( 'Bar' ) + ); + + $instance->resetPoolCacheById( 'Foo' ); + } + + public function testGetStats() { + + $instance = InMemoryPoolCache::getInstance(); + + $instance->getPoolCacheById( 'Foo' )->save( 'Bar', 42 ); + + $this->assertNotEmpty( + $instance->getStats() + ); + + $this->assertInternalType( + 'string', + $instance->getStats( InMemoryPoolCache::FORMAT_PLAIN ) + ); + + $this->assertContains( + 'ul', + $instance->getStats( InMemoryPoolCache::FORMAT_HTML ) + ); + + $this->assertInternalType( + 'string', + $instance->getStats( InMemoryPoolCache::FORMAT_JSON ) + ); + + $instance->resetPoolCacheById( 'Foo' ); + } + +} |