Skip to content

Commit 22ea027

Browse files
Adjust from invalidateDomain to clearCache
1 parent 6d86331 commit 22ea027

File tree

5 files changed

+81
-105
lines changed

5 files changed

+81
-105
lines changed

src/Command/ClearCommand.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSHttpCacheBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\HttpCacheBundle\Command;
13+
14+
use FOS\HttpCacheBundle\CacheManager;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
18+
/**
19+
* A command to trigger cache invalidation by path from the command line.
20+
*
21+
* @author Alexander Schranz <[email protected]>
22+
*/
23+
class ClearCommand extends BaseInvalidateCommand
24+
{
25+
use PathSanityCheck;
26+
27+
protected static $defaultName = 'fos:httpcache:invalidate';
28+
29+
/**
30+
* If no cache manager is specified explicitly, fos_http_cache.cache_manager
31+
* is automatically loaded.
32+
*
33+
* @param CacheManager|null $cacheManager The cache manager to talk to
34+
*/
35+
public function __construct(CacheManager $cacheManager = null)
36+
{
37+
parent::__construct($cacheManager);
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
protected function configure()
44+
{
45+
$this
46+
->setName(static::$defaultName) // BC with 2.8
47+
->setDescription('Invalidate the whole http cache.')
48+
->setHelp(
49+
<<<'EOF'
50+
The <info>%command.name%</info> command invalidates the whole cache in the configured caching proxies.
51+
52+
Example:
53+
54+
<info>php %command.full_name%</info>
55+
EOF
56+
)
57+
;
58+
}
59+
60+
/**
61+
* {@inheritdoc}
62+
*/
63+
protected function execute(InputInterface $input, OutputInterface $output): int
64+
{
65+
$this->getCacheManager()->clearCache();
66+
67+
return 0;
68+
}
69+
}

src/Command/InvalidateDomainCommand.php

Lines changed: 0 additions & 86 deletions
This file was deleted.

src/Resources/config/cache_manager_commands.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<tag name="console.command"/>
2222
</service>
2323

24-
<service id="fos_http_cache.command.invalidate_domain" class="FOS\HttpCacheBundle\Command\InvalidateDomainCommand">
24+
<service id="fos_http_cache.command.clear" class="FOS\HttpCacheBundle\Command\ClearCommand">
2525
<argument type="service" id="fos_http_cache.cache_manager" />
2626
<tag name="console.command"/>
2727
</service>

tests/Functional/Command/InvalidateDomainCommandTest.php renamed to tests/Functional/Command/ClearCommandTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use FOS\HttpCacheBundle\CacheManager;
1515

16-
class InvalidateDomainCommandTest extends CommandTestCase
16+
class ClearCommandTest extends CommandTestCase
1717
{
1818
public function testExecuteVerbose()
1919
{
@@ -24,22 +24,17 @@ public function testExecuteVerbose()
2424
->zeroOrMoreTimes()
2525
->andReturnTrue()
2626
;
27-
$mock->shouldReceive('invalidateDomain')
27+
$mock->shouldReceive('clearCache')
2828
->once()
29-
->with('localhost')
30-
;
31-
$mock->shouldReceive('invalidateDomain')
32-
->once()
33-
->with('example.localhost')
3429
;
3530
$mock->shouldReceive('flush')
3631
->once()
3732
->andReturn(2)
3833
;
3934
$client->getContainer()->set('fos_http_cache.cache_manager', $mock);
4035

41-
$output = $this->runCommand($client, 'fos:httpcache:invalidate:domain localhost example.localhost');
36+
$output = $this->runCommand($client, 'fos:httpcache:clear');
4237

43-
$this->assertEquals("Sent 2 invalidation request(s)\n", $output);
38+
$this->assertEquals("Sent 1 invalidation request(s)\n", $output);
4439
}
4540
}

tests/Unit/Command/InvalidateDomainCommandTest.php renamed to tests/Unit/Command/ClearCommandTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
namespace FOS\HttpCacheBundle\Tests\Unit\Command;
1313

1414
use FOS\HttpCacheBundle\CacheManager;
15-
use FOS\HttpCacheBundle\Command\InvalidateDomainCommand;
15+
use FOS\HttpCacheBundle\Command\ClearCommand;
1616
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
1717
use PHPUnit\Framework\TestCase;
1818
use Symfony\Component\Console\Application;
1919
use Symfony\Component\Console\Tester\CommandTester;
2020

21-
class InvalidateDomainCommandTest extends TestCase
21+
class ClearCommandTest extends TestCase
2222
{
2323
use MockeryPHPUnitIntegration;
2424

@@ -30,29 +30,27 @@ public function testExecuteMissingParameters()
3030
$invalidator = \Mockery::mock(CacheManager::class);
3131

3232
$application = new Application();
33-
$application->add(new InvalidateDomainCommand($invalidator));
33+
$application->add(new ClearCommand($invalidator));
3434

35-
$command = $application->find('fos:httpcache:invalidate:domain');
35+
$command = $application->find('fos:httpcache:clear');
3636
$commandTester = new CommandTester($command);
3737
$commandTester->execute(['command' => $command->getName()]);
3838
}
3939

4040
public function testExecuteParameter()
4141
{
4242
$invalidator = \Mockery::mock(CacheManager::class)
43-
->shouldReceive('invalidateDomain')->once()->with('localhost')
44-
->shouldReceive('invalidateDomain')->once()->with('example.localhost')
43+
->shouldReceive('clearCache')->once()
4544
->getMock()
4645
;
4746

4847
$application = new Application();
49-
$application->add(new InvalidateDomainCommand($invalidator));
48+
$application->add(new ClearCommand($invalidator));
5049

51-
$command = $application->find('fos:httpcache:invalidate:domain');
50+
$command = $application->find('fos:httpcache:clear');
5251
$commandTester = new CommandTester($command);
5352
$commandTester->execute([
5453
'command' => $command->getName(),
55-
'domains' => ['localhost', 'example.localhost'],
5654
]);
5755

5856
// the only output should be generated by the listener in verbose mode

0 commit comments

Comments
 (0)