|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Cache\Tests\Simple;
|
13 | 13 |
|
| 14 | +use Psr\SimpleCache\CacheInterface; |
| 15 | +use Symfony\Component\Cache\PruneableInterface; |
14 | 16 | use Symfony\Component\Cache\Simple\ArrayCache;
|
15 | 17 | use Symfony\Component\Cache\Simple\ChainCache;
|
16 | 18 | use Symfony\Component\Cache\Simple\FilesystemCache;
|
@@ -40,6 +42,75 @@ public function testEmptyCachesException()
|
40 | 42 | */
|
41 | 43 | public function testInvalidCacheException()
|
42 | 44 | {
|
43 |
| - new Chaincache(array(new \stdClass())); |
| 45 | + new ChainCache(array(new \stdClass())); |
44 | 46 | }
|
| 47 | + |
| 48 | + public function testPrune() |
| 49 | + { |
| 50 | + if (isset($this->skippedTests[__FUNCTION__])) { |
| 51 | + $this->markTestSkipped($this->skippedTests[__FUNCTION__]); |
| 52 | + } |
| 53 | + |
| 54 | + $cache = new ChainCache(array( |
| 55 | + $this->getPruneableMock(), |
| 56 | + $this->getNonPruneableMock(), |
| 57 | + $this->getPruneableMock(), |
| 58 | + )); |
| 59 | + $this->assertTrue($cache->prune()); |
| 60 | + |
| 61 | + $cache = new ChainCache(array( |
| 62 | + $this->getPruneableMock(), |
| 63 | + $this->getFailingPruneableMock(), |
| 64 | + $this->getPruneableMock(), |
| 65 | + )); |
| 66 | + $this->assertFalse($cache->prune()); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @return \PHPUnit_Framework_MockObject_MockObject|PruneableCacheInterface |
| 71 | + */ |
| 72 | + private function getPruneableMock() |
| 73 | + { |
| 74 | + $pruneable = $this |
| 75 | + ->getMockBuilder(PruneableCacheInterface::class) |
| 76 | + ->getMock(); |
| 77 | + |
| 78 | + $pruneable |
| 79 | + ->expects($this->atLeastOnce()) |
| 80 | + ->method('prune') |
| 81 | + ->will($this->returnValue(true)); |
| 82 | + |
| 83 | + return $pruneable; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @return \PHPUnit_Framework_MockObject_MockObject|PruneableCacheInterface |
| 88 | + */ |
| 89 | + private function getFailingPruneableMock() |
| 90 | + { |
| 91 | + $pruneable = $this |
| 92 | + ->getMockBuilder(PruneableCacheInterface::class) |
| 93 | + ->getMock(); |
| 94 | + |
| 95 | + $pruneable |
| 96 | + ->expects($this->atLeastOnce()) |
| 97 | + ->method('prune') |
| 98 | + ->will($this->returnValue(false)); |
| 99 | + |
| 100 | + return $pruneable; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * @return \PHPUnit_Framework_MockObject_MockObject|CacheInterface |
| 105 | + */ |
| 106 | + private function getNonPruneableMock() |
| 107 | + { |
| 108 | + return $this |
| 109 | + ->getMockBuilder(CacheInterface::class) |
| 110 | + ->getMock(); |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +interface PruneableCacheInterface extends PruneableInterface, CacheInterface |
| 115 | +{ |
45 | 116 | }
|
0 commit comments