YamlOutputAdapterTest::testGetName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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