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

MarkdownRendererTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 31.71 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 4
c 3
b 0
f 2
lcom 0
cbo 1
dl 13
loc 41
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\Factory;
6
use PHPUnit_Framework_TestCase;
7
8
class MarkdownRendererTest extends PHPUnit_Framework_TestCase
9
{
10
    public function testIntegrity()
11
    {
12
        $renderer = Factory::createRenderer('markdown');
13
        $output = $renderer->render('# Hello World!');
14
15
        $this->assertEquals("<h1>Hello World!</h1>\n", $output);
16
    }
17
18
    public function basicParserProvider()
19
    {
20
        $sets = array();
21
22
        foreach (glob(__DIR__ . '/examples/markdown/*.text') as $file) {
23
            $sets[] = array(
24
                realpath($file),
25
                realpath(substr($file, 0, -5) . '.xhtml')
26
            );
27
        }
28
29
        return $sets;
30
    }
31
32
    /**
33
     * @dataProvider basicParserProvider
34
     */
35
    public function testBasicParser($fileInput, $fileExpected)
36
    {
37
        $renderer = Factory::createRenderer('markdown');
38
39
        $output = $renderer->render(file_get_contents($fileInput));
40
41
        $expected = file_get_contents($fileExpected);
42
43
        $output   = str_replace(array("\r\n", "\r"), "\n", $output);
44
        $expected = str_replace(array("\r\n", "\r"), "\n", $expected);
45
46
        $this->assertEquals($expected, $output);
47
    }
48
}
49