Completed
Push — core-test-reorganisation ( b9cfa9...ce9ad9 )
by Kamil
43:54 queued 22:56
created

LocaleAwareCamelKeysNormalizerTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 94
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A it_does_not_override_existing_keys() 0 10 1
A it_normalizes_snake_cased_keys_to_camel_case() 0 5 1
A it_does_not_normalize_locales_codes() 0 5 1
A normalizeProvider() 0 15 1
A localeAwareNormalizeProvider() 0 13 1
A normalizeProviderCommon() 0 14 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\ApiBundle\Tests\Normalizer;
13
14
use Sylius\Bundle\ApiBundle\Normalizer\LocaleAwareCamelKeysNormalizer;
15
16
/**
17
 * @see \FOS\RestBundle\Tests\Normalizer\CamelKeysNormalizerTest
18
 *
19
 * @author Łukasz Chruściel <[email protected]>
20
 */
21
final class LocaleAwareCamelKeysNormalizerTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @test
25
     *
26
     * @expectedException \FOS\RestBundle\Normalizer\Exception\NormalizationException
27
     */
28
    public function it_does_not_override_existing_keys()
29
    {
30
        $normalizer = new LocaleAwareCamelKeysNormalizer();
31
        $normalizer->normalize([
32
            'foo' => [
33
                'foo_bar' => 'foo',
34
                'foo_Bar' => 'foo',
35
            ],
36
        ]);
37
    }
38
39
    /**
40
     * @test
41
     *
42
     * @dataProvider normalizeProvider
43
     */
44
    public function it_normalizes_snake_cased_keys_to_camel_case(array $array, array $expected)
45
    {
46
        $normalizer = new LocaleAwareCamelKeysNormalizer();
47
        $this->assertEquals($expected, $normalizer->normalize($array));
48
    }
49
50
    /**
51
     * @test
52
     *
53
     * @dataProvider localeAwareNormalizeProvider
54
     */
55
    public function it_does_not_normalize_locales_codes(array $array, array $expected)
56
    {
57
        $normalizer = new LocaleAwareCamelKeysNormalizer();
58
        $this->assertEquals($expected, $normalizer->normalize($array));
59
    }
60
61
    /**
62
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array[][].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
63
     */
64
    public function normalizeProvider()
65
    {
66
        $array = $this->normalizeProviderCommon();
67
        $array[] = [[
68
            '__username' => 'foo',
69
            '_password' => 'bar',
70
            '_foo_bar' => 'foobar',
71
        ], [
72
            '_Username' => 'foo',
73
            'Password' => 'bar',
74
            'FooBar' => 'foobar',
75
        ]];
76
77
        return $array;
78
    }
79
80
    /**
81
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array[][].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
82
     */
83
    public function localeAwareNormalizeProvider()
84
    {
85
        $array = $this->normalizeProviderCommon();
86
        $array[] = [['translations' => [
87
            'en_US' => ['foo_bar' => 'mops'],
88
            'nl_NL' => ['bar' => 'narwhale_io']],
89
        ], ['translations' => [
90
            'en_US' => ['fooBar' => 'mops'],
91
            'nl_NL' => ['bar' => 'narwhale_io']],
92
        ]];
93
94
        return $array;
95
    }
96
97
    /**
98
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array[][].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
99
     */
100
    private function normalizeProviderCommon()
101
    {
102
        return [
103
            [[], []],
104
            [
105
                ['foo' => ['Foo_bar_baz' => ['foo_Bar' => ['foo_bar' => 'foo_bar']]],
106
                    'foo_1ar' => ['foo_bar'],
107
                ],
108
                ['foo' => ['FooBarBaz' => ['fooBar' => ['fooBar' => 'foo_bar']]],
109
                    'foo1ar' => ['foo_bar'],
110
                ],
111
            ],
112
        ];
113
    }
114
}