|
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\Tests\Unit\Command; |
|
13
|
|
|
|
|
14
|
|
|
use FOS\HttpCacheBundle\Command\InvalidatePathCommand; |
|
15
|
|
|
use Symfony\Component\Console\Application; |
|
16
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
17
|
|
|
|
|
18
|
|
|
class BaseInvalidateCommandTest extends \PHPUnit_Framework_TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testContainerAccess() |
|
21
|
|
|
{ |
|
22
|
|
|
$invalidator = \Mockery::mock('\FOS\HttpCacheBundle\CacheManager') |
|
23
|
|
|
->shouldReceive('invalidatePath')->once()->with('/my/path') |
|
24
|
|
|
->shouldReceive('invalidatePath')->once()->with('/other/path') |
|
25
|
|
|
->shouldReceive('invalidatePath')->once()->with('/another') |
|
26
|
|
|
->getMock() |
|
27
|
|
|
; |
|
28
|
|
|
$container = \Mockery::mock('\Symfony\Component\DependencyInjection\ContainerInterface') |
|
29
|
|
|
->shouldReceive('get')->once()->with('fos_http_cache.cache_manager')->andReturn($invalidator) |
|
30
|
|
|
->getMock() |
|
31
|
|
|
; |
|
32
|
|
|
|
|
33
|
|
|
$application = new Application(); |
|
34
|
|
|
$command = new InvalidatePathCommand(); |
|
35
|
|
|
$command->setContainer($container); |
|
36
|
|
|
$application->add($command); |
|
37
|
|
|
|
|
38
|
|
|
$command = $application->find('fos:httpcache:invalidate:path'); |
|
39
|
|
|
$commandTester = new CommandTester($command); |
|
40
|
|
|
$commandTester->execute(array( |
|
41
|
|
|
'command' => $command->getName(), |
|
42
|
|
|
'paths' => array('/my/path', '/other/path'), |
|
43
|
|
|
)); |
|
44
|
|
|
|
|
45
|
|
|
// the only output should be generated by the listener in verbose mode |
|
46
|
|
|
$this->assertEquals('', $commandTester->getDisplay()); |
|
47
|
|
|
|
|
48
|
|
|
// the cache manager is only fetched once |
|
49
|
|
|
$commandTester->execute(array( |
|
50
|
|
|
'command' => $command->getName(), |
|
51
|
|
|
'paths' => array('/another'), |
|
52
|
|
|
)); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|