ErrorCheckstyleTest::testGettingFileList()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 30
nc 1
nop 0
dl 0
loc 44
rs 9.44
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Test case
5
 *
6
 * Copyright (c) 2007-2010, Mayflower GmbH
7
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions
11
 * are met:
12
 *
13
 *   * Redistributions of source code must retain the above copyright
14
 *     notice, this list of conditions and the following disclaimer.
15
 *
16
 *   * Redistributions in binary form must reproduce the above copyright
17
 *     notice, this list of conditions and the following disclaimer in
18
 *     the documentation and/or other materials provided with the
19
 *     distribution.
20
 *
21
 *   * Neither the name of Mayflower GmbH nor the names of his
22
 *     contributors may be used to endorse or promote products derived
23
 *     from this software without specific prior written permission.
24
 *
25
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
 * POSSIBILITY OF SUCH DAMAGE.
37
 *
38
 * @category PHP_CodeBrowser
39
 *
40
 * @author Simon Kohlmeyer <[email protected]
41
 *
42
 * @copyright 2007-2010 Mayflower GmbH
43
 *
44
 * @license http://www.opensource.org/licenses/bsd-license.php  BSD License
45
 *
46
 * @version SVN: $Id$
47
 *
48
 * @link http://www.phpunit.de/
49
 *
50
 * @since File available since  0.9.0
51
 */
52
53
namespace PHPCodeBrowser\Tests\Plugins;
54
55
use DOMDocument;
56
use PHPCodeBrowser\File;
57
use PHPCodeBrowser\Issue;
58
use PHPCodeBrowser\IssueXML;
59
use PHPCodeBrowser\Plugins\ErrorCheckstyle;
60
use PHPCodeBrowser\Tests\AbstractTestCase;
61
62
/**
63
 * ErrorCheckstyleTest
64
 *
65
 * @category PHP_CodeBrowser
66
 *
67
 * @author Simon Kohlmeyer <[email protected]>
68
 *
69
 * @copyright 2007-2010 Mayflower GmbH
70
 *
71
 * @license http://www.opensource.org/licenses/bsd-license.php  BSD License
72
 *
73
 * @version Release: @package_version@
74
 *
75
 * @link http://www.phpunit.de/
76
 *
77
 * @since Class available since  0.9.0
78
 */
79
class ErrorCheckstyleTest extends AbstractTestCase
80
{
81
    /**
82
     * The object to test.
83
     *
84
     * @var ErrorCheckstyle
85
     */
86
    protected $errorCheckstyle;
87
88
    /**
89
     * The xml string to test the plugin against.
90
     *
91
     * @var string
92
     */
93
    protected $testXml = <<<HERE
94
<?xml version="1.0" encoding="UTF-8"?>
95
<checkstyle version="1.2.2">
96
 <file name="/some/file">
97
  <error line="117"
98
         column="32"
99
         severity="error"
100
         message="Message 1"
101
         source="Source3"/>
102
  <error line="121"
103
         column="88"
104
         severity="warning"
105
         message="Message 2"
106
         source="Source2"/>
107
 </file>
108
 <file name="/other/file">
109
  <error line="48"
110
         column="67"
111
         severity="error"
112
         message="Message 3"
113
         source="Source1"/>
114
 </file>
115
 <file name="/no/violations">
116
 </file>
117
</checkstyle>
118
HERE;
119
120
    /**
121
     * (non-PHPDoc)
122
     *
123
     * @see tests/cbAbstractTests#setUp()
124
     */
125
    protected function setUp(): void
126
    {
127
        parent::setUp();
128
        $issueXML             = new IssueXML();
129
        $xml                  = new DOMDocument('1.0', 'UTF-8');
130
        $xml->validateOnParse = true;
131
        $xml->loadXML($this->testXml);
132
        $issueXML->addXMLFile($xml);
133
        $this->errorCheckstyle = new ErrorCheckstyle($issueXML);
134
    }
135
136
    /**
137
     * Test getFileList
138
     *
139
     * @return void
140
     */
141
    public function testGettingFileList(): void
142
    {
143
        $expected = [
144
            new File(
145
                '/some/file',
146
                [
147
                    new Issue(
148
                        '/some/file',
149
                        117,
150
                        117,
151
                        'Checkstyle',
152
                        'Message 1',
153
                        'error'
154
                    ),
155
                    new Issue(
156
                        '/some/file',
157
                        121,
158
                        121,
159
                        'Checkstyle',
160
                        'Message 2',
161
                        'warning'
162
                    ),
163
                ]
164
            ),
165
            new File(
166
                '/other/file',
167
                [
168
                    new Issue(
169
                        '/other/file',
170
                        48,
171
                        48,
172
                        'Checkstyle',
173
                        'Message 3',
174
                        'error'
175
                    ),
176
                ]
177
            ),
178
            new File(
179
                '/no/violations',
180
                []
181
            ),
182
        ];
183
        $actual   = $this->errorCheckstyle->getFileList();
184
        static::assertEquals($expected, $actual);
185
    }
186
}
187