|
13 | 13 |
|
14 | 14 | use Symfony\Bundle\FrameworkBundle\Command\CachePoolClearCommand;
|
15 | 15 | use Symfony\Bundle\FrameworkBundle\Console\Application;
|
| 16 | +use Symfony\Component\Cache\Adapter\FilesystemAdapter; |
16 | 17 | use Symfony\Component\Console\Tester\CommandTester;
|
| 18 | +use Symfony\Component\Finder\SplFileInfo; |
17 | 19 |
|
18 | 20 | /**
|
19 | 21 | * @group functional
|
@@ -73,6 +75,35 @@ public function testClearUnexistingPool()
|
73 | 75 | ->execute(['pools' => ['unknown_pool']], ['decorated' => false]);
|
74 | 76 | }
|
75 | 77 |
|
| 78 | + public function testClearFailed() |
| 79 | + { |
| 80 | + $tester = $this->createCommandTester(); |
| 81 | + /** @var FilesystemAdapter $pool */ |
| 82 | + $pool = static::$container->get('cache.public_pool'); |
| 83 | + $item = $pool->getItem('foo'); |
| 84 | + $item->set('baz'); |
| 85 | + $pool->save($item); |
| 86 | + $r = new \ReflectionObject($pool); |
| 87 | + $p = $r->getProperty('directory'); |
| 88 | + $p->setAccessible(true); |
| 89 | + $poolDir = $p->getValue($pool); |
| 90 | + |
| 91 | + /** @var SplFileInfo $entry */ |
| 92 | + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($poolDir)) as $entry) { |
| 93 | + // converts files into dir to make adapter fail |
| 94 | + if ($entry->isFile()) { |
| 95 | + unlink($entry->getPathname()); |
| 96 | + mkdir($entry->getPathname()); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + $tester->execute(['pools' => ['cache.public_pool']]); |
| 101 | + |
| 102 | + $this->assertSame(1, $tester->getStatusCode(), 'cache:pool:clear exits with 1 in case of error'); |
| 103 | + $this->assertStringNotContainsString('[OK] Cache was successfully cleared.', $tester->getDisplay()); |
| 104 | + $this->assertStringContainsString('[WARNING] Cache pool "cache.public_pool" could not be cleared.', $tester->getDisplay()); |
| 105 | + } |
| 106 | + |
76 | 107 | private function createCommandTester()
|
77 | 108 | {
|
78 | 109 | $application = new Application(static::$kernel);
|
|
0 commit comments