Completed
Push — master ( 525456...12ac84 )
by Ivo
03:31
created

getObjectManagerConfigurationTestData()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 24
rs 8.9713
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Ivoaz ContentEditable bundle.
5
 *
6
 * (c) Ivo Azirjans <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Ivoaz\Bundle\ContentEditableBundle\Tests\DependencyInjection;
13
14
use Ivoaz\Bundle\ContentEditableBundle\DependencyInjection\IvoazContentEditableExtension;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class IvoazContentEditableExtensionTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @var IvoazContentEditableExtension
22
     */
23
    private $extension;
24
25
    /**
26
     * @var ContainerBuilder
27
     */
28
    private $container;
29
30
    public function setUp()
31
    {
32
        $this->extension = new IvoazContentEditableExtension();
33
        $this->container = new ContainerBuilder();
34
35
        $this->container->setParameter('doctrine.default_entity_manager', 'default');
36
        $this->container->setParameter('doctrine_mongodb.odm.default_document_manager', 'default');
37
    }
38
39
    /**
40
     * @dataProvider getEditorConfigurationTestData
41
     *
42
     * @param string $expected
43
     * @param array  $configs
44
     * @param string $message
45
     */
46
    public function testEditorConfiguration($expected, $configs, $message = '')
47
    {
48
        $this->extension->load($configs, $this->container);
49
50
        $alias = $this->container->getAlias('ivoaz_content_editable.editor');
51
52
        $this->assertEquals($expected, $alias, $message);
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    public function getEditorConfigurationTestData()
59
    {
60
        return [
61
            ['ivoaz_content_editable.default_editor', [], 'The default editor service was not used.'],
62
            [
63
                'custom_editor_service',
64
                ['ivoaz_content_editable' => ['editor' => 'custom_editor_service']],
65
                'Custom editor service was not set.',
66
            ],
67
        ];
68
    }
69
70
    /**
71
     * @dataProvider getModelTypeConfigurationTestData
72
     *
73
     * @param string $expected
74
     * @param array  $configs
75
     * @param string $message
76
     */
77
    public function testModelTypeConfiguration($expected, $configs, $message = '')
78
    {
79
        $this->extension->load($configs, $this->container);
80
81
        try {
82
            $parameter = $this->container->getParameter(sprintf('ivoaz_content_editable.model_type_%s', $expected));
83
        } catch (\InvalidArgumentException $e) {
84
            $parameter = false;
85
        }
86
87
        $this->assertTrue($parameter, $message);
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function getModelTypeConfigurationTestData()
94
    {
95
        return [
96
            ['orm', [], 'The default model type was not used.'],
97
            [
98
                'orm',
99
                ['ivoaz_content_editable' => ['model_type' => 'orm']],
100
                'The orm model type was not used.',
101
            ],
102
            [
103
                'mongodb',
104
                ['ivoaz_content_editable' => ['model_type' => 'mongodb'],],
105
                'The mongodb model type was not used.',
106
            ],
107
        ];
108
    }
109
110
    /**
111
     * @dataProvider getObjectManagerConfigurationTestData
112
     *
113
     * @param string $expectedModelManagerName
114
     * @param string $expectedObjectManager
115
     * @param array  $configs
116
     * @param string $message
117
     */
118
    public function testObjectManagerConfiguration(
119
        $expectedModelManagerName,
120
        $expectedObjectManager,
121
        $configs,
122
        $message = ''
123
    ) {
124
        $this->extension->load($configs, $this->container);
125
126
        $alias = $this->container->getAlias('ivoaz_content_editable.object_manager');
127
        $modelManagerName = $this->container->getParameter('ivoaz_content_editable.model_manager_name');
128
129
        $this->assertEquals($expectedObjectManager, $alias, $message);
130
        $this->assertEquals($expectedModelManagerName, $modelManagerName, $message);
131
    }
132
133
    /**
134
     * @return array
135
     */
136
    public function getObjectManagerConfigurationTestData()
137
    {
138
        return [
139
            ['default', 'doctrine.orm.default_entity_manager', [], 'The default orm object manager was not used.'],
140
            [
141
                'default',
142
                'doctrine.orm.default_entity_manager',
143
                ['ivoaz_content_editable' => ['model_type' => 'orm']],
144
                'The default orm object manager was not used.',
145
            ],
146
            [
147
                'default',
148
                'doctrine_mongodb.odm.default_document_manager',
149
                ['ivoaz_content_editable' => ['model_type' => 'mongodb']],
150
                'The default mongodb object manager was not used.',
151
            ],
152
            [
153
                'custom',
154
                'doctrine_mongodb.odm.custom_document_manager',
155
                ['ivoaz_content_editable' => ['model_type' => 'mongodb', 'model_manager_name' => 'custom']],
156
                'A custom object manager was not used.',
157
            ],
158
        ];
159
    }
160
}
161