testStorageDriverIsRequired()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
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 Xabbuh\LRSBundle\Tests\DependencyInjection;
13
14
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
15
use Symfony\Component\DependencyInjection\Reference;
16
use Xabbuh\XApi\Bundle\LrsBundle\DependencyInjection\XabbuhLrsExtension;
17
18
/**
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
class XabbuhLrsExtensionTest extends AbstractExtensionTestCase
22
{
23
    /**
24
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
25
     */
26
    public function testStorageDriverIsRequired()
27
    {
28
        $this->load();
29
30
        $this->validateContainerBuilder();
31
    }
32
33
    public function testMongoDBStorageDriver()
34
    {
35
        $this->load(array('driver' => 'mongodb'));
36
37
        $this->validateContainerBuilder();
38
        $this->assertContainerBuilderHasService(
39
            'xabbuh_lrs.statement_manager',
40
            'Xabbuh\XApi\Storage\Doctrine\Manager\StatementManager'
41
        );
42
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
43
            'xabbuh_lrs.statement_manager',
44
            0,
45
            new Reference('xabbuh_lrs.statement_repository')
46
        );
47
        $this->assertContainerBuilderHasService('xabbuh_lrs.statement_object_manager');
48
    }
49
50
    protected function getContainerExtensions()
51
    {
52
        return array(new XabbuhLrsExtension());
53
    }
54
55
    private function validateContainerBuilder()
56
    {
57
        $this->validateSerializers();
58
        $this->validateListeners();
59
    }
60
61
    private function validateSerializers()
62
    {
63
        $serializers = array(
64
            'xabbuh_lrs.actor_serializer' => 'Xabbuh\XApi\Serializer\ActorSerializer',
65
            'xabbuh_lrs.document_serializer' => 'Xabbuh\XApi\Serializer\DocumentSerializer',
66
            'xabbuh_lrs.statement_result_serializer' => 'Xabbuh\XApi\Serializer\StatementResultSerializer',
67
            'xabbuh_lrs.statement_serializer' => 'Xabbuh\XApi\Serializer\StatementSerializer',
68
        );
69
70
        foreach ($serializers as $id => $class) {
71
            $this->assertContainerBuilderHasService(
72
                $id,
73
                $class
74
            );
75
            $this->assertContainerBuilderHasServiceDefinitionWithArgument(
76
                $id,
77
                0,
78
                new Reference('jms_serializer')
79
            );
80
        }
81
    }
82
83
    private function validateListeners()
84
    {
85
        $listeners = array(
86
            array(
87
                'id' => 'xabbuh_lrs.listener.statement_serializer',
88
                'className' => 'StatementSerializerListener',
89
                'serializer' => 'xabbuh_lrs.statement_serializer',
90
            ),
91
            array(
92
                'id' => 'xabbuh_lrs.listener.statement_result_serializer',
93
                'className' => 'StatementResultSerializerListener',
94
                'serializer' => 'xabbuh_lrs.statement_result_serializer',
95
            ),
96
        );
97
98
        foreach ($listeners as $listener) {
99
            $this->assertContainerBuilderHasService(
100
                $listener['id'],
101
                'Xabbuh\XApi\Bundle\LrsBundle\Listener\\'.$listener['className']
102
            );
103
            $this->assertContainerBuilderHasServiceDefinitionWithArgument(
104
                $listener['id'],
105
                0,
106
                new Reference($listener['serializer'])
107
            );
108
            $this->assertContainerBuilderHasServiceDefinitionWithTag(
109
                $listener['id'],
110
                'kernel.event_listener',
111
                array('event' => 'kernel.view', 'method' => 'onKernelView')
112
            );
113
        }
114
    }
115
}
116