|
14 | 14 | use Symfony\Bundle\FrameworkBundle\Command\CachePoolClearCommand;
|
15 | 15 | use Symfony\Bundle\FrameworkBundle\Console\Application;
|
16 | 16 | use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
| 17 | +use Symfony\Component\Console\Exception\InvalidArgumentException; |
17 | 18 | use Symfony\Component\Console\Tester\CommandTester;
|
18 | 19 | use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
19 | 20 | use Symfony\Component\Finder\SplFileInfo;
|
@@ -76,6 +77,33 @@ public function testClearUnexistingPool()
|
76 | 77 | ->execute(['pools' => ['unknown_pool']], ['decorated' => false]);
|
77 | 78 | }
|
78 | 79 |
|
| 80 | + public function testClearAll() |
| 81 | + { |
| 82 | + $tester = $this->createCommandTester(['cache.app_clearer']); |
| 83 | + $tester->execute(['--all' => true], ['decorated' => false]); |
| 84 | + |
| 85 | + $tester->assertCommandIsSuccessful('cache:pool:clear exits with 0 in case of success'); |
| 86 | + $this->assertStringContainsString('Clearing all cache pools...', $tester->getDisplay()); |
| 87 | + $this->assertStringContainsString('Calling cache clearer: cache.app_clearer', $tester->getDisplay()); |
| 88 | + $this->assertStringContainsString('[OK] Cache was successfully cleared.', $tester->getDisplay()); |
| 89 | + } |
| 90 | + |
| 91 | + public function testClearWithoutPoolNames() |
| 92 | + { |
| 93 | + $this->expectException(InvalidArgumentException::class); |
| 94 | + $this->expectExceptionMessage('Could not clear all cache pools, try specifying a specific pool or cache clearer.'); |
| 95 | + |
| 96 | + $this->createCommandTester()->execute(['--all' => true], ['decorated' => false]); |
| 97 | + } |
| 98 | + |
| 99 | + public function testClearNoOptions() |
| 100 | + { |
| 101 | + $this->expectException(InvalidArgumentException::class); |
| 102 | + $this->expectExceptionMessage('Either specify at least one pool name, or provide the --all option to clear all pools.'); |
| 103 | + |
| 104 | + $this->createCommandTester()->execute([], ['decorated' => false]); |
| 105 | + } |
| 106 | + |
79 | 107 | public function testClearFailed()
|
80 | 108 | {
|
81 | 109 | $tester = $this->createCommandTester();
|
@@ -104,10 +132,10 @@ public function testClearFailed()
|
104 | 132 | $this->assertStringContainsString('[WARNING] Cache pool "cache.public_pool" could not be cleared.', $tester->getDisplay());
|
105 | 133 | }
|
106 | 134 |
|
107 |
| - private function createCommandTester() |
| 135 | + private function createCommandTester(array $poolNames = null) |
108 | 136 | {
|
109 | 137 | $application = new Application(static::$kernel);
|
110 |
| - $application->add(new CachePoolClearCommand(static::getContainer()->get('cache.global_clearer'))); |
| 138 | + $application->add(new CachePoolClearCommand(static::getContainer()->get('cache.global_clearer'), $poolNames)); |
111 | 139 |
|
112 | 140 | return new CommandTester($application->find('cache:pool:clear'));
|
113 | 141 | }
|
|
0 commit comments