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\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use FOS\HttpCacheBundle\DependencyInjection\Compiler\LoggerPass; |
15
|
|
|
use FOS\HttpCacheBundle\DependencyInjection\FOSHttpCacheExtension; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
18
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
19
|
|
|
|
20
|
|
|
class LoggerPassTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
public function testLogger() |
23
|
|
|
{ |
24
|
|
|
$extension = new FOSHttpCacheExtension(); |
25
|
|
|
$loggerPass = new LoggerPass(); |
26
|
|
|
$container = $this->createContainer(); |
27
|
|
|
$config = $this->getConfig(); |
28
|
|
|
$extension->load(array($config), $container); |
29
|
|
|
$container->setDefinition('logger', new Definition()); |
30
|
|
|
$loggerPass->process($container); |
31
|
|
|
|
32
|
|
|
$this->assertHasTaggedService($container, 'fos_http_cache.event_listener.log', 'kernel.event_subscriber'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function testNoLogger() |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$extension = new FOSHttpCacheExtension(); |
38
|
|
|
$loggerPass = new LoggerPass(); |
39
|
|
|
$container = $this->createContainer(); |
40
|
|
|
$config = $this->getConfig(); |
41
|
|
|
$extension->load(array($config), $container); |
42
|
|
|
$loggerPass->process($container); |
43
|
|
|
|
44
|
|
|
$this->assertIsAbstract($container, 'fos_http_cache.event_listener.log'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function assertHasTaggedService(ContainerBuilder $container, $id, $tag) |
48
|
|
|
{ |
49
|
|
|
$this->assertTrue($container->hasDefinition($id)); |
50
|
|
|
$definition = $container->getDefinition($id); |
51
|
|
|
$this->assertFalse($definition->isAbstract()); |
52
|
|
|
$this->assertTrue($definition->hasTag($tag)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private function assertIsAbstract(ContainerBuilder $container, $id) |
56
|
|
|
{ |
57
|
|
|
$this->assertTrue($container->hasDefinition($id)); |
58
|
|
|
$definition = $container->getDefinition($id); |
59
|
|
|
$this->assertTrue($definition->isAbstract()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function createContainer() |
63
|
|
|
{ |
64
|
|
|
return new ContainerBuilder(new ParameterBag(array( |
65
|
|
|
'kernel.debug' => false, |
66
|
|
|
))); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
private function getConfig() |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
return array( |
72
|
|
|
'proxy_client' => array( |
73
|
|
|
'varnish' => array( |
74
|
|
|
'http' => [ |
75
|
|
|
'base_url' => 'my_hostname', |
76
|
|
|
'servers' => array( |
77
|
|
|
'127.0.0.1', |
78
|
|
|
), |
79
|
|
|
], |
80
|
|
|
), |
81
|
|
|
), |
82
|
|
|
'tags' => array( |
83
|
|
|
'enabled' => true, |
84
|
|
|
), |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.