OrbitaleCmsExtensionTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 32.1 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInexistentPageClass() 13 13 1
A testInexistentCategoryClass() 13 13 1
A testYamlConfiguration() 0 14 2
A provideYamlConfiguration() 0 21 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
* This file is part of the OrbitaleCmsBundle package.
5
*
6
* (c) Alexandre Rock Ancelet <[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 Orbitale\Bundle\CmsBundle\Tests\DependencyInjection;
13
14
use Orbitale\Bundle\CmsBundle\DependencyInjection\OrbitaleCmsExtension;
15
use PHPUnit\Framework\TestCase;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\Yaml\Yaml;
18
use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Category;
19
use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page;
20
21
class OrbitaleCmsExtensionTest extends TestCase
22
{
23
    /**
24
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
25
     * @expectedExceptionMessage Page class must be a valid class extending Orbitale\Bundle\CmsBundle\Entity\Page. "inexistent_page_class" given.
26
     */
27 View Code Duplication
    public function testInexistentPageClass()
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...
28
    {
29
        $builder = new ContainerBuilder();
30
31
        $ext = new OrbitaleCmsExtension();
32
33
        $ext->load([
34
            'orbitale_cms' => [
35
                'page_class'     => 'inexistent_page_class',
36
                'category_class' => Category::class,
37
            ],
38
        ], $builder);
39
    }
40
41
    /**
42
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
43
     * @expectedExceptionMessage Category class must be a valid class extending Orbitale\Bundle\CmsBundle\Entity\Category. "inexistent_category_class" given.
44
     */
45 View Code Duplication
    public function testInexistentCategoryClass()
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...
46
    {
47
        $builder = new ContainerBuilder();
48
49
        $ext = new OrbitaleCmsExtension();
50
51
        $ext->load([
52
            'orbitale_cms' => [
53
                'page_class'     => Page::class,
54
                'category_class' => 'inexistent_category_class',
55
            ],
56
        ], $builder);
57
    }
58
59
    /**
60
     * @dataProvider provideYamlConfiguration
61
     *
62
     * @param $config
63
     * @param $expected
64
     */
65
    public function testYamlConfiguration($config, $expected)
66
    {
67
        $builder = new ContainerBuilder();
68
69
        $ext = new OrbitaleCmsExtension();
70
71
        $ext->load($config, $builder);
72
73
        static::assertArrayHasKey('orbitale_cms', $expected);
74
75
        foreach ($expected['orbitale_cms'] as $key => $expectedValue) {
76
            static::assertEquals($expectedValue, $builder->getParameter('orbitale_cms.'.$key));
77
        }
78
    }
79
80
    public function provideYamlConfiguration(): array
81
    {
82
        $dir = __DIR__.'/../Fixtures/App/extension_test/';
83
84
        $configFiles = glob($dir.'config_*.yaml');
85
        $resultFiles = glob($dir.'result_*.yaml');
86
87
        sort($configFiles);
88
        sort($resultFiles);
89
90
        $tests = [];
91
92
        foreach ($configFiles as $k => $file) {
93
            $tests[] = [
94
                Yaml::parse(file_get_contents($file)),
95
                Yaml::parse(file_get_contents($resultFiles[$k])),
96
            ];
97
        }
98
99
        return $tests;
100
    }
101
}
102