|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; |
| 13 | + |
| 14 | +use Symfony\Bundle\FrameworkBundle\Command\CachePoolClearCommand; |
| 15 | +use Symfony\Component\Console\Tester\CommandTester; |
| 16 | + |
| 17 | +/** |
| 18 | + * @group functional |
| 19 | + */ |
| 20 | +class CachePoolClearCommandTest extends WebTestCase |
| 21 | +{ |
| 22 | + private $application; |
| 23 | + |
| 24 | + protected function setUp() |
| 25 | + { |
| 26 | + static::bootKernel(array('test_case' => 'CachePoolClear', 'root_config' => 'config.yml')); |
| 27 | + } |
| 28 | + |
| 29 | + public function testClearPrivatePool() |
| 30 | + { |
| 31 | + $tester = $this->createCommandTester(); |
| 32 | + $tester->execute(array('pools' => array('cache.private_pool')), array('decorated' => false)); |
| 33 | + |
| 34 | + $this->assertSame(0, $tester->getStatusCode(), 'cache:pool:clear exits with 0 in case of success'); |
| 35 | + $this->assertContains('Clearing cache pool: cache.private_pool', $tester->getDisplay()); |
| 36 | + $this->assertContains('[OK] Cache was successfully cleared.', $tester->getDisplay()); |
| 37 | + } |
| 38 | + |
| 39 | + public function testClearPublicPool() |
| 40 | + { |
| 41 | + $tester = $this->createCommandTester(); |
| 42 | + $tester->execute(array('pools' => array('cache.public_pool')), array('decorated' => false)); |
| 43 | + |
| 44 | + $this->assertSame(0, $tester->getStatusCode(), 'cache:pool:clear exits with 0 in case of success'); |
| 45 | + $this->assertContains('Clearing cache pool: cache.public_pool', $tester->getDisplay()); |
| 46 | + $this->assertContains('[OK] Cache was successfully cleared.', $tester->getDisplay()); |
| 47 | + } |
| 48 | + |
| 49 | + public function testClearPoolWithCustomClearer() |
| 50 | + { |
| 51 | + $tester = $this->createCommandTester(); |
| 52 | + $tester->execute(array('pools' => array('cache.pool_with_clearer')), array('decorated' => false)); |
| 53 | + |
| 54 | + $this->assertSame(0, $tester->getStatusCode(), 'cache:pool:clear exits with 0 in case of success'); |
| 55 | + $this->assertContains('Clearing cache pool: cache.pool_with_clearer', $tester->getDisplay()); |
| 56 | + $this->assertContains('[OK] Cache was successfully cleared.', $tester->getDisplay()); |
| 57 | + } |
| 58 | + |
| 59 | + public function testCallClearer() |
| 60 | + { |
| 61 | + $tester = $this->createCommandTester(); |
| 62 | + $tester->execute(array('pools' => array('cache.default_clearer')), array('decorated' => false)); |
| 63 | + |
| 64 | + $this->assertSame(0, $tester->getStatusCode(), 'cache:pool:clear exits with 0 in case of success'); |
| 65 | + $this->assertContains('Calling cache clearer: cache.default_clearer', $tester->getDisplay()); |
| 66 | + $this->assertContains('[OK] Cache was successfully cleared.', $tester->getDisplay()); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException |
| 71 | + * @expectedExceptionMessage You have requested a non-existent service "unknown_pool" |
| 72 | + */ |
| 73 | + public function testClearUnexistingPool() |
| 74 | + { |
| 75 | + $this->createCommandTester() |
| 76 | + ->execute(array('pools' => array('unknown_pool')), array('decorated' => false)); |
| 77 | + } |
| 78 | + |
| 79 | + private function createCommandTester() |
| 80 | + { |
| 81 | + $command = new CachePoolClearCommand(); |
| 82 | + $command->setContainer(static::$kernel->getContainer()); |
| 83 | + |
| 84 | + return new CommandTester($command); |
| 85 | + } |
| 86 | +} |
0 commit comments