- Notifications
You must be signed in to change notification settings - Fork 84
Add invalidate all command #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dbu merged 9 commits into FriendsOfSymfony:master from alexander-schranz:feature/add-invalidate-domain-command Aug 20, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits Select commit Hold shift + click to select a range
6f2e13c Add invalidate domain command
alexander-schranz affce3f Adjust from invalidateDomain to clearCache and invalidate
alexander-schranz 810e185 Apply suggestions from code review
alexander-schranz b922df8 Increase minimum friendsofsymfony/http-cache to ^2.6
alexander-schranz af391d6 Fix styleci already enabled short_array_syntax error
alexander-schranz f3fdf13 Fix tests
alexander-schranz 83760b0 Adjust review
alexander-schranz 84c097d Remove 2.8 bc layer for commands
alexander-schranz b10a7f3 Update changelog
alexander-schranz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| <?php | ||
| | ||
| /* | ||
| * This file is part of the FOSHttpCacheBundle package. | ||
| * | ||
| * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| | ||
| namespace FOS\HttpCacheBundle\Command; | ||
| | ||
| use FOS\HttpCache\CacheInvalidator; | ||
| use FOS\HttpCacheBundle\CacheManager; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| | ||
| /** | ||
| * A command to clear the whole cache from the command line. | ||
| * | ||
| * @author Alexander Schranz <alexander@sulu.io> | ||
| */ | ||
| class ClearCommand extends BaseInvalidateCommand | ||
| { | ||
| use PathSanityCheck; | ||
| | ||
| protected static $defaultName = 'fos:httpcache:clear'; | ||
| | ||
| /** | ||
| * If no cache manager is specified explicitly, fos_http_cache.cache_manager | ||
| * is automatically loaded. | ||
| * | ||
| * @param CacheManager|null $cacheManager The cache manager to talk to | ||
| */ | ||
| public function __construct(CacheManager $cacheManager = null) | ||
| { | ||
| parent::__construct($cacheManager); | ||
| } | ||
| | ||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| protected function configure() | ||
| { | ||
| $this | ||
| ->setDescription('Clear the HTTP cache.') | ||
| ->setHelp( | ||
| <<<'EOF' | ||
| The <info>%command.name%</info> command clears the whole cache or, if that is not supported, invalidates all cache entries in the configured caching proxies. | ||
| | ||
| Example: | ||
| | ||
| <info>php %command.full_name%</info> | ||
| EOF | ||
| ) | ||
| ; | ||
| } | ||
| | ||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| protected function execute(InputInterface $input, OutputInterface $output): int | ||
| { | ||
| $cacheManager = $this->getCacheManager(); | ||
| | ||
| if ($cacheManager->supports(CacheInvalidator::CLEAR)) { | ||
| $this->getCacheManager()->clearCache(); | ||
| | ||
| return 0; | ||
| } | ||
| | ||
| if ($cacheManager->supports(CacheInvalidator::INVALIDATE)) { | ||
| $this->getCacheManager()->invalidateRegex('.*'); | ||
| | ||
| return 0; | ||
| } | ||
| | ||
| $output->writeln( | ||
| '<error>The configured HTTP cache does not support "clear" or "invalidate".</error>' | ||
| ); | ||
| | ||
| return 1; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?php | ||
| | ||
| /* | ||
| * This file is part of the FOSHttpCacheBundle package. | ||
| * | ||
| * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| | ||
| namespace FOS\HttpCacheBundle\Tests\Functional\Command; | ||
| | ||
| use FOS\HttpCache\CacheInvalidator; | ||
| use FOS\HttpCacheBundle\CacheManager; | ||
| | ||
| class ClearCommandTest extends CommandTestCase | ||
| { | ||
| public function testExecuteClearVerbose() | ||
| { | ||
| $client = self::createClient(); | ||
| | ||
| $mock = \Mockery::mock(CacheManager::class); | ||
| $mock->shouldReceive('supports') | ||
| ->with(CacheInvalidator::CLEAR) | ||
| ->andReturnTrue(); | ||
| | ||
| $mock->shouldReceive('clearCache') | ||
| ->once() | ||
| ; | ||
| $mock->shouldReceive('flush') | ||
| ->once() | ||
| ->andReturn(1) | ||
| ; | ||
| $client->getContainer()->set('fos_http_cache.cache_manager', $mock); | ||
| | ||
| $output = $this->runCommand($client, 'fos:httpcache:clear'); | ||
| | ||
| $this->assertEquals("Sent 1 invalidation request(s)\n", $output); | ||
| } | ||
| | ||
| public function testExecuteBanVerbose() | ||
| { | ||
| $client = self::createClient(); | ||
| | ||
| $mock = \Mockery::mock(CacheManager::class); | ||
| $mock->shouldReceive('supports') | ||
| ->with(CacheInvalidator::CLEAR) | ||
| ->andReturnFalse(); | ||
| $mock->shouldReceive('supports') | ||
| ->with(CacheInvalidator::INVALIDATE) | ||
| ->andReturnTrue(); | ||
| | ||
| $mock->shouldReceive('invalidateRegex') | ||
| ->with('.*') | ||
| ->once() | ||
| ; | ||
| $mock->shouldReceive('flush') | ||
| ->once() | ||
| ->andReturn(1) | ||
| ; | ||
| $client->getContainer()->set('fos_http_cache.cache_manager', $mock); | ||
| | ||
| $output = $this->runCommand($client, 'fos:httpcache:clear'); | ||
| | ||
| $this->assertEquals("Sent 1 invalidation request(s)\n", $output); | ||
| } | ||
| | ||
| public function testExecuteErrorVerbose() | ||
| { | ||
| $client = self::createClient(); | ||
| | ||
| $mock = \Mockery::mock(CacheManager::class); | ||
| $mock->shouldReceive('supports') | ||
| ->with(CacheInvalidator::CLEAR) | ||
| ->andReturnFalse(); | ||
| $mock->shouldReceive('supports') | ||
| ->with(CacheInvalidator::INVALIDATE) | ||
| ->andReturnFalse(); | ||
| | ||
| $mock->shouldReceive('flush') | ||
| ->once() | ||
| ->andReturn(0) | ||
| ; | ||
| $client->getContainer()->set('fos_http_cache.cache_manager', $mock); | ||
| | ||
| $output = $this->runCommand($client, 'fos:httpcache:clear', 1); | ||
| | ||
| $this->assertStringContainsString('The configured HTTP cache does not support "clear" or "invalidate".', $output); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?php | ||
| | ||
| /* | ||
| * This file is part of the FOSHttpCacheBundle package. | ||
| * | ||
| * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| | ||
| namespace FOS\HttpCacheBundle\Tests\Unit\Command; | ||
| | ||
| use FOS\HttpCache\CacheInvalidator; | ||
| use FOS\HttpCacheBundle\CacheManager; | ||
| use FOS\HttpCacheBundle\Command\ClearCommand; | ||
| use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Symfony\Component\Console\Application; | ||
| use Symfony\Component\Console\Tester\CommandTester; | ||
| | ||
| class ClearCommandTest extends TestCase | ||
| { | ||
| use MockeryPHPUnitIntegration; | ||
| | ||
| public function testExecuteClear() | ||
| { | ||
| $invalidator = \Mockery::mock(CacheManager::class) | ||
| ->shouldReceive('supports')->once()->with(CacheInvalidator::CLEAR)->andReturnTrue() | ||
| ->shouldReceive('clearCache')->once() | ||
| ->getMock() | ||
| ; | ||
| | ||
| $application = new Application(); | ||
| $application->add(new ClearCommand($invalidator)); | ||
| | ||
| $command = $application->find('fos:httpcache:clear'); | ||
| $commandTester = new CommandTester($command); | ||
| $commandTester->execute([ | ||
| 'command' => $command->getName(), | ||
| ]); | ||
| | ||
| // the only output should be generated by the listener in verbose mode | ||
| $this->assertEquals('', $commandTester->getDisplay()); | ||
| } | ||
| | ||
| public function testExecuteInvalidate() | ||
| { | ||
| $invalidator = \Mockery::mock(CacheManager::class) | ||
| ->shouldReceive('supports')->once()->with(CacheInvalidator::CLEAR)->andReturnFalse() | ||
| ->shouldReceive('supports')->once()->with(CacheInvalidator::INVALIDATE)->andReturnTrue() | ||
| ->shouldReceive('invalidateRegex')->once()->with('.*') | ||
| ->getMock() | ||
| ; | ||
| | ||
| $application = new Application(); | ||
| $application->add(new ClearCommand($invalidator)); | ||
| | ||
| $command = $application->find('fos:httpcache:clear'); | ||
| $commandTester = new CommandTester($command); | ||
| $commandTester->execute([ | ||
| 'command' => $command->getName(), | ||
| ]); | ||
| | ||
| // the only output should be generated by the listener in verbose mode | ||
| $this->assertEquals('', $commandTester->getDisplay()); | ||
| } | ||
| | ||
| public function testExecuteNotSupported() | ||
| { | ||
| $invalidator = \Mockery::mock(CacheManager::class) | ||
| ->shouldReceive('supports')->once()->with(CacheInvalidator::CLEAR)->andReturnFalse() | ||
| ->shouldReceive('supports')->once()->with(CacheInvalidator::INVALIDATE)->andReturnfalse() | ||
| ->getMock() | ||
| ; | ||
| | ||
| $application = new Application(); | ||
| $application->add(new ClearCommand($invalidator)); | ||
| | ||
| $command = $application->find('fos:httpcache:clear'); | ||
| $commandTester = new CommandTester($command); | ||
| $commandTester->execute([ | ||
| 'command' => $command->getName(), | ||
| ]); | ||
| | ||
| $this->assertStringContainsString( | ||
| 'The configured HTTP cache does not support "clear" or "invalidate".', | ||
| $commandTester->getDisplay() | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.