testRendererCreatesExpectedNumberOfJsonElements()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 31
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 31
loc 31
rs 9.424
c 0
b 0
f 0
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 JSON renderer implementation.
26
 *
27
 * @covers \PHPMD\Renderer\JSONRenderer
28
 */
29 View Code Duplication
class JSONRendererTest extends AbstractTest
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...
30
{
31
    /**
32
     * testRendererCreatesExpectedNumberOfJsonElements
33
     *
34
     * @return void
35
     */
36
    public function testRendererCreatesExpectedNumberOfJsonElements()
37
    {
38
        // Create a writer instance.
39
        $writer = new WriterStub();
40
        
41
        $violations = array(
42
            $this->getRuleViolationMock('/bar.php'),
43
            $this->getRuleViolationMock('/foo.php'),
44
            $this->getRuleViolationMock('/bar.php'),
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 JSONRenderer();
56
        $renderer->setWriter($writer);
57
58
        $renderer->start();
59
        $renderer->renderReport($report);
60
        $renderer->end();
61
62
        $this->assertJsonEquals(
63
            $writer->getData(),
64
            'renderer/json_renderer_expected.json'
65
        );
66
    }
67
68
    /**
69
     * testRendererAddsProcessingErrorsToJsonReport
70
     *
71
     * @return void
72
     */
73
    public function testRendererAddsProcessingErrorsToJsonReport()
74
    {
75
        // Create a writer instance.
76
        $writer = new WriterStub();
77
78
        $processingErrors = array(
79
            new ProcessingError('Failed for file "/tmp/foo.php".'),
80
            new ProcessingError('Failed for file "/tmp/bar.php".'),
81
            new ProcessingError('Failed for file "/tmp/baz.php".'),
82
            new ProcessingError('Cannot read file "/tmp/foo.php". Permission denied.'),
83
        );
84
85
        $report = $this->getReportMock(0);
86
        $report->expects($this->once())
87
            ->method('getRuleViolations')
88
            ->willReturn(new \ArrayIterator(array()));
89
        $report->expects($this->once())
90
            ->method('getErrors')
91
            ->willReturn(new \ArrayIterator($processingErrors));
92
93
        $renderer = new JSONRenderer();
94
        $renderer->setWriter($writer);
95
96
        $renderer->start();
97
        $renderer->renderReport($report);
98
        $renderer->end();
99
100
        $this->assertJsonEquals(
101
            $writer->getData(),
102
            'renderer/json_renderer_processing_errors.json'
103
        );
104
    }
105
}
106