123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Component\Cache\Tests\Simple;
- use Psr\SimpleCache\CacheInterface;
- use Symfony\Component\Cache\PruneableInterface;
- use Symfony\Component\Cache\Simple\ArrayCache;
- use Symfony\Component\Cache\Simple\ChainCache;
- use Symfony\Component\Cache\Simple\FilesystemCache;
- /**
- * @group time-sensitive
- */
- class ChainCacheTest extends CacheTestCase
- {
- public function createSimpleCache($defaultLifetime = 0)
- {
- return new ChainCache([new ArrayCache($defaultLifetime), new FilesystemCache('', $defaultLifetime)], $defaultLifetime);
- }
- /**
- * @expectedException \Symfony\Component\Cache\Exception\InvalidArgumentException
- * @expectedExceptionMessage At least one cache must be specified.
- */
- public function testEmptyCachesException()
- {
- new ChainCache([]);
- }
- /**
- * @expectedException \Symfony\Component\Cache\Exception\InvalidArgumentException
- * @expectedExceptionMessage The class "stdClass" does not implement
- */
- public function testInvalidCacheException()
- {
- new ChainCache([new \stdClass()]);
- }
- public function testPrune()
- {
- if (isset($this->skippedTests[__FUNCTION__])) {
- $this->markTestSkipped($this->skippedTests[__FUNCTION__]);
- }
- $cache = new ChainCache([
- $this->getPruneableMock(),
- $this->getNonPruneableMock(),
- $this->getPruneableMock(),
- ]);
- $this->assertTrue($cache->prune());
- $cache = new ChainCache([
- $this->getPruneableMock(),
- $this->getFailingPruneableMock(),
- $this->getPruneableMock(),
- ]);
- $this->assertFalse($cache->prune());
- }
- /**
- * @return \PHPUnit_Framework_MockObject_MockObject|PruneableCacheInterface
- */
- private function getPruneableMock()
- {
- $pruneable = $this
- ->getMockBuilder(PruneableCacheInterface::class)
- ->getMock();
- $pruneable
- ->expects($this->atLeastOnce())
- ->method('prune')
- ->will($this->returnValue(true));
- return $pruneable;
- }
- /**
- * @return \PHPUnit_Framework_MockObject_MockObject|PruneableCacheInterface
- */
- private function getFailingPruneableMock()
- {
- $pruneable = $this
- ->getMockBuilder(PruneableCacheInterface::class)
- ->getMock();
- $pruneable
- ->expects($this->atLeastOnce())
- ->method('prune')
- ->will($this->returnValue(false));
- return $pruneable;
- }
- /**
- * @return \PHPUnit_Framework_MockObject_MockObject|CacheInterface
- */
- private function getNonPruneableMock()
- {
- return $this
- ->getMockBuilder(CacheInterface::class)
- ->getMock();
- }
- }
- interface PruneableCacheInterface extends PruneableInterface, CacheInterface
- {
- }
|