Completed
Push — master ( 974133...f3d891 )
by Marc
05:38
created

InigoRendererTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 22.41 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

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
namespace Kaloa\Tests;
4
5
use Kaloa\Renderer\Config;
6
use Kaloa\Renderer\Factory;
7
use PHPUnit_Framework_TestCase;
8
9
/**
10
 *
11
 */
12
class InigoRendererTest extends PHPUnit_Framework_TestCase
13
{
14
    /**
15
     *
16
     */
17
    public function testIntegrity()
18
    {
19
        // Environment
20
        $contentToRender = file_get_contents(__DIR__ . '/examples/inigo/klangbilder.txt');
21
        $resourceBasePath = __DIR__ . '/examples/inigo/res';
22
        $filter = 'inigo';
23
24
        $config = new Config($resourceBasePath);
25
26
        $renderer = Factory::createRenderer($filter, $config);
27
28
        $output = $renderer->render($contentToRender);
29
30
        $expected = file_get_contents(__DIR__ . '/examples/inigo/klangbilder.expected');
31
32
        $expected = str_replace('__RESOURCE_BASE_PATH__', $config->getResourceBasePath(), $expected);
33
34
        $this->assertEquals($expected, $output);
35
    }
36
37
    public function runSuiteProvider()
38
    {
39
        $sets = array();
40
41
        foreach (glob(__DIR__ . '/examples/inigo/*.txt') as $file) {
42
            $sets[] = array(
43
                realpath($file),
44
                realpath(substr($file, 0, -4) . '.expected')
45
            );
46
        }
47
48
        return $sets;
49
    }
50
51
    /**
52
     * @dataProvider runSuiteProvider
53
     */
54
    public function testRunSuite($fileInput, $fileExpected)
55
    {
56
        $resourceBasePath = __DIR__ . '/examples/inigo/res';
57
58
        $config = new Config($resourceBasePath);
59
60
        $renderer = Factory::createRenderer('inigo', $config);
61
62
        $output   = $renderer->render(file_get_contents($fileInput));
63
        $expected = file_get_contents($fileExpected);
64
65
        $expected = str_replace('__RESOURCE_BASE_PATH__', $config->getResourceBasePath(), $expected);
66
67
        $this->assertEquals($expected, $output);
68
    }
69
}
70