Completed
Push — master ( 9de1be...100987 )
by David
8s
created

BaseInvalidateCommandTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 7
dl 0
loc 37
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testContainerAccess() 0 34 1
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