YamlOutputAdapterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 81
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 3
dl 81
loc 81
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 5 5 1
A testGetName() 5 5 1
A testProcess() 11 11 1
B processProvider() 40 40 1

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
namespace Paro\EnvironmentParameters\Tests\Adapter\Ouput;
3
4
use Paro\EnvironmentParameters\Adapter\Output\YamlOutputAdapter;
5
use org\bovigo\vfs\vfsStream;
6
use org\bovigo\vfs\vfsStreamDirectory;
7
use org\bovigo\vfs\vfsStreamWrapper;
8
9 View Code Duplication
class YamlOutputAdapterTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
12
    /**
13
     * @var YamlOutputAdapter
14
     */
15
    private $YamlOutputAdapter;
16
17
    protected function setUp()
18
    {
19
        parent::setUp();
20
        $this->YamlOutputAdapter = new YamlOutputAdapter('parameters');
21
    }
22
23
    public function testGetName()
24
    {
25
        $actual = $this->YamlOutputAdapter->getName();
26
        $this->assertEquals('yaml', $actual);
27
    }
28
29
    /**
30
     * @param $parameters
31
     * @param $fileName
32
     * @param $env
33
     * @param $expected
34
     *
35
     * @dataProvider processProvider
36
     */
37
    public function testProcess($parameters, $fileName, $env, $date, $expected)
38
    {
39
        vfsStreamWrapper::register();
40
        vfsStreamWrapper::setRoot(new vfsStreamDirectory('root'));
41
42
        $fileNameVFS = vfsStream::url('root/' . $fileName);
43
        $this->YamlOutputAdapter->process($parameters, $fileNameVFS, $env, $date);
44
        $actual = file_get_contents(vfsStream::url('root/' . $fileName));
45
        $this->assertEquals($expected, $actual);
46
        vfsStreamWrapper::unregister();
47
    }
48
49
    public function processProvider()
50
    {
51
        $date = time();
52
        return array(
53
            'number' => array(
54
                'parameters' => array(
55
                    'PARAMETER' => 1100,
56
                    'PARAMETER1' => 1.100
57
                ),
58
                'fileName' => 'parameters.php',
59
                'env' => 'devlike/test',
60
                'date' => $date,
61
                'expected' => sprintf("%s\n%s\n%s\n%s\n",
62
                    sprintf("# This file is auto-generated during the build process of '%s' environment at %s", 'devlike/test', date(DATE_ATOM, $date)),
63
                    "parameters:",
64
                    "    PARAMETER: 1100",
65
                    "    PARAMETER1: 1.1"
66
                ),
67
68
            ),
69
            'array' => array(
70
                'parameters' => array(
71
                    'PARAMETER' => array(100, 200, 300, "aaa'", array("'\"'")),
72
                    'PARAMETER1' => true,
73
                    'PARAMETER2' => null
74
                ),
75
                'fileName' => 'parameters.php',
76
                'env' => 'devlike/test',
77
                'date' => $date,
78
                'expected' => sprintf("%s\n%s\n%s\n%s\n%s\n",
79
                    sprintf("# This file is auto-generated during the build process of '%s' environment at %s", 'devlike/test', date(DATE_ATOM, $date)),
80
                    "parameters:",
81
                    "    PARAMETER: [100, 200, 300, 'aaa''', ['''\"''']]",
82
                    "    PARAMETER1: true",
83
                    "    PARAMETER2: null"
84
                ),
85
86
            ),
87
        );
88
    }
89
}
90