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