CustomNamingStrategy   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 7
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A translateName() 0 4 1
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\Serializer\Metadata\PropertyMetadata;
22
use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
23
use JMS\SerializerBundle\DependencyInjection\JMSSerializerExtension;
24
use PHPUnit\Framework\TestCase;
25
use Symfony\Component\DependencyInjection\ContainerBuilder;
26
27
class NamingStrategyTest extends TestCase
28
{
29
    /**
30
     *
31
     * @param array $configs
32
     * @return ContainerBuilder
33
     */
34 View Code Duplication
    private function getContainer(array $configs = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
35
    {
36
        $loader = new JMSSerializerExtension();
37
        $container = new ContainerBuilder();
38
39
        $container->setParameter('kernel.debug', true);
40
        $container->setParameter('kernel.cache_dir', sys_get_temp_dir() . '/serializer');
41
        $container->setParameter('kernel.bundles', array());
42
43
        $loader->load(['jms_serializer' => $configs], $container);
44
        return $container;
45
    }
46
47
    public function testCustomNamingStrategy()
48
    {
49
        $container = $this->getContainer(array(
50
            'property_naming' => array(
51
                'id' => 'custom_naming_strategy',
52
                'enable_cache' => false
53
            )
54
        ));
55
        $customNamingStrategy = new CustomNamingStrategy();
56
        $container->set("custom_naming_strategy", $customNamingStrategy);
57
58
        $this->assertSame($customNamingStrategy, $container->get('jms_serializer.naming_strategy'));
59
    }
60
61
    public function testCachedNamingStrategy()
62
    {
63
        $container = $this->getContainer(array(
64
            'property_naming' => array(
65
                'enable_cache' => true
66
            )
67
        ));
68
69
        $namingStrategy = $container->get('jms_serializer.naming_strategy');
70
        $this->assertInstanceOf('JMS\Serializer\Naming\CacheNamingStrategy', $namingStrategy);
71
    }
72
}
73
74
class CustomNamingStrategy implements PropertyNamingStrategyInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
75
{
76
    public function translateName(PropertyMetadata $property)
77
    {
78
        return 'foo';
79
    }
80
}
81