HTMLRendererTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testRendererCreatesExpectedHtmlTableRow() 0 36 1
A testRendererAddsProcessingErrorsToHtmlReport() 0 34 1
1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD\Renderer;
19
20
use PHPMD\AbstractTest;
21
use PHPMD\ProcessingError;
22
use PHPMD\Stubs\WriterStub;
23
24
/**
25
 * Test case for the html renderer implementation.
26
 *
27
 * @covers \PHPMD\Renderer\HTMLRenderer
28
 */
29
class HTMLRendererTest extends AbstractTest
30
{
31
    /**
32
     * testRendererCreatesExpectedNumberOfTextEntries
33
     *
34
     * @return void
35
     */
36
    public function testRendererCreatesExpectedHtmlTableRow()
37
    {
38
        // Create a writer instance.
39
        $writer = new WriterStub();
40
41
        $violations = array(
42
            $this->getRuleViolationMock('/bar.php', 1),
43
            $this->getRuleViolationMock('/foo.php', 2),
44
            $this->getRuleViolationMock('/foo.php', 3),
45
        );
46
47
        $report = $this->getReportMock(0);
48
        $report->expects($this->once())
49
            ->method('getRuleViolations')
50
            ->willReturn(new \ArrayIterator($violations));
51
        $report->expects($this->once())
52
            ->method('getErrors')
53
            ->willReturn(new \ArrayIterator(array()));
54
55
        $renderer = new HTMLRenderer();
56
        $renderer->setWriter($writer);
57
58
        $renderer->start();
59
        $renderer->renderReport($report);
60
        $renderer->end();
61
62
        $this->assertContains(
63
            '<tr>' . PHP_EOL .
64
            '<td align="center">2</td>' . PHP_EOL .
65
            '<td>/foo.php</td>' . PHP_EOL .
66
            '<td align="center" width="5%">2</td>' . PHP_EOL .
67
            '<td><a href="https://phpmd.org/rules/index.html">Test description</a></td>' . PHP_EOL .
68
            '</tr>',
69
            $writer->getData()
70
        );
71
    }
72
73
    /**
74
     * testRendererAddsProcessingErrorsToHtmlReport
75
     *
76
     * @return void
77
     */
78
    public function testRendererAddsProcessingErrorsToHtmlReport()
79
    {
80
        // Create a writer instance.
81
        $writer = new WriterStub();
82
83
        $errors = array(
84
            new ProcessingError('Failed for file "/tmp/foo.php".'),
85
            new ProcessingError('Failed for file "/tmp/bar.php".'),
86
            new ProcessingError('Failed for file "/tmp/baz.php".'),
87
        );
88
89
        $report = $this->getReportMock(0);
90
        $report->expects($this->once())
91
            ->method('getRuleViolations')
92
            ->willReturn(new \ArrayIterator(array()));
93
        $report->expects($this->once())
94
            ->method('getErrors')
95
            ->willReturn(new \ArrayIterator($errors));
96
97
        $renderer = new HTMLRenderer();
98
        $renderer->setWriter($writer);
99
100
        $renderer->start();
101
        $renderer->renderReport($report);
102
        $renderer->end();
103
104
        $this->assertContains(
105
            '<tr>' .
106
            '<td>/tmp/bar.php</td>' .
107
            '<td>Failed for file &quot;/tmp/bar.php&quot;.</td>' .
108
            '</tr>',
109
            $writer->getData()
110
        );
111
    }
112
}
113