Completed
Pull Request — master (#556)
by Evgenij
02:53
created

ConfigurationTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 67
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainer() 0 15 1
B testConfig() 0 25 1
A testContextDefaults() 0 22 2
1
<?php
2
3
/*
4
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace JMS\SerializerBundle\Tests\DependencyInjection;
20
21
use JMS\SerializerBundle\DependencyInjection\Configuration;
22
use JMS\SerializerBundle\JMSSerializerBundle;
23
use Symfony\Component\Config\Definition\Processor;
24
use Symfony\Component\DependencyInjection\ContainerBuilder;
25
26
class ConfigurationTest extends \PHPUnit_Framework_TestCase
27
{
28
    private function getContainer(array $configs = array())
29
    {
30
        $container = new ContainerBuilder();
31
32
        $container->setParameter('kernel.debug', true);
33
        $container->setParameter('kernel.cache_dir', sys_get_temp_dir() . '/serializer');
34
        $container->setParameter('kernel.bundles', array('JMSSerializerBundle' => 'JMS\SerializerBundle\JMSSerializerBundle'));
35
36
        $bundle = new JMSSerializerBundle();
37
38
        $extension = $bundle->getContainerExtension();
39
        $extension->load($configs, $container);
40
41
        return $container;
42
    }
43
44
    public function testConfig()
45
    {
46
        $ref = new JMSSerializerBundle();
47
        $container = $this->getContainer([
48
            [
49
                'metadata' => [
50
                    'directories' => [
51
                        [
52
                            'namespace_prefix' => 'JMSSerializerBundleNs1',
53
                            'path' => '@JMSSerializerBundle',
54
                        ],
55
                        [
56
                            'namespace_prefix' => 'JMSSerializerBundleNs2',
57
                            'path' => '@JMSSerializerBundle/Resources/config',
58
                        ],
59
                    ]
60
                ]
61
            ],
62
        ]);
63
64
        $directories = $container->getDefinition('jms_serializer.metadata.file_locator')->getArgument(0);
65
66
        $this->assertEquals($ref->getPath(), $directories['JMSSerializerBundleNs1']);
67
        $this->assertEquals($ref->getPath().'/Resources/config', $directories['JMSSerializerBundleNs2']);
68
    }
69
70
    public function testContextDefaults()
71
    {
72
        $processor = new Processor();
73
        $config = $processor->processConfiguration(new Configuration(true), []);
74
75
        $this->assertArrayHasKey('default_context', $config);
76
        foreach (['serialization', 'deserialization'] as $item) {
77
            $this->assertArrayHasKey($item, $config['default_context']);
78
79
            $defaultContext = $config['default_context'][$item];
80
            $this->assertArrayHasKey('attributes', $defaultContext);
81
            $this->assertTrue(is_array($defaultContext['attributes']));
82
            $this->assertEmpty($defaultContext['attributes']);
83
            $this->assertArrayHasKey('groups', $defaultContext);
84
            $this->assertSame(['Default'], $defaultContext['groups']);
85
            $this->assertArrayHasKey('version', $defaultContext);
86
            $this->assertNull($defaultContext['version']);
87
            $this->assertArrayHasKey('serialize_null', $defaultContext);
88
            $this->assertFalse($defaultContext['serialize_null']);
89
        }
90
91
    }
92
}
93