Completed
Push — master ( 0fd1e7...aad679 )
by Jérémy
02:00
created

NovawayOpenGraphExtension::testLoadNoCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Novaway\Bundle\OpenGraphBundle\Tests\Units\DependencyInjection;
4
5
use atoum;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Parameter;
8
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
9
10
class NovawayOpenGraphExtension extends atoum
11
{
12
    public function testLoadDefault()
13
    {
14
        $this
15
            ->given(
16
                $extension = $this->newTestedInstance(),
17
                $container = $this->createContainer()
18
            )
19
            ->if($extension->load([], $container))
20
            ->then
21
                ->boolean($container->has('novaway.open_graph.metadata.cache'))
22
                    ->isTrue()
23
                ->boolean($container->has('novaway.open_graph.generator'))
24
                    ->isTrue()
25
                ->object($container->get('novaway.open_graph.generator'))
26
                    ->isInstanceOf('Novaway\Component\OpenGraph\OpenGraphGenerator')
27
        ;
28
    }
29
30
    public function testLoadNoCache()
31
    {
32
        $this
33
            ->given(
34
                $extension = $this->newTestedInstance(),
35
                $container = $this->createContainer(),
36
                $configuration = [['metadata' => ['cache' => 'none']]]
37
            )
38
            ->if($extension->load($configuration, $container))
39
            ->then
40
                ->boolean($container->has('novaway.open_graph.metadata.cache'))
41
                    ->isFalse()
42
        ;
43
    }
44
45
    public function testLoadCacheOverride()
46
    {
47
        $this
48
            ->given(
49
                $extension = $this->newTestedInstance(),
50
                $container = $this->createContainer(),
51
                $configuration = [['metadata' => [
52
                    'cache'      => 'file',
53
                    'file_cache' => ['dir' => sys_get_temp_dir().'/my-cache']
54
                ]]]
55
            )
56
            ->if($extension->load($configuration, $container))
57
            ->then
58
                ->boolean($container->has('novaway.open_graph.metadata.cache'))
59
                    ->isTrue()
60
                ->string($container->getDefinition('novaway.open_graph.metadata.file_cache')->getArgument(0))
61
                    ->isEqualTo(sys_get_temp_dir().'/my-cache')
62
        ;
63
    }
64
65
    public function testLoadWithBundles()
66
    {
67
        $this
68
            ->given(
69
                $extension = $this->newTestedInstance(),
70
                $container = $this->createContainer(['kernel.bundles' => [
71
                    'FrameworkBundle' => 'Symfony\Bundle\FrameworkBundle\FrameworkBundle',
72
                ]])
73
            )
74
            ->if($extension->load([], $container))
75
            ->then
76
                ->array($container->get('novaway.open_graph.metadata.file_locator')->getDirs())
77
                    ->hasKey('Symfony\Bundle\FrameworkBundle')
78
                    ->string['Symfony\Bundle\FrameworkBundle']->endWith('FrameworkBundle/Resources/config/open-graph')
79
                    ->hasSize(1)
80
        ;
81
    }
82
83
    protected function createContainer(array $params = [])
84
    {
85
        $params = array_merge([
86
            'kernel.bundles'   => [],
87
            'kernel.cache_dir' => sys_get_temp_dir(),
88
            'kernel.debug'     => false,
89
        ], $params);
90
91
        return new ContainerBuilder(new ParameterBag($params));
92
    }
93
}
94