1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CloverReporterTest; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use CloverReporter\Parser; |
7
|
|
|
|
8
|
|
|
class ParserTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
use \CloverReporterTest\Helper; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @expectedException \InvalidArgumentException |
14
|
|
|
*/ |
15
|
|
|
public function testCreateParserForNotExistingFile() |
16
|
|
|
{ |
17
|
|
|
new Parser('plik', ['skip-dir' => '']); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @expectedException \InvalidArgumentException |
22
|
|
|
*/ |
23
|
|
|
public function testCreateParserForNoneAccessibleFile() |
24
|
|
|
{ |
25
|
|
|
new Parser('tests/reports/no_accessible.xml', ['skip-dir' => '']); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function testCreateParser() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$parser = new Parser( |
31
|
|
|
$this->reportPaths['base'] . 'clover_log.xml', |
32
|
|
|
[ |
33
|
|
|
'skip-dir' => '', |
34
|
|
|
'show-coverage' => false, |
35
|
|
|
] |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$this->assertEquals( |
39
|
|
|
$this->infoList(), |
40
|
|
|
$parser->getInfoList() |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testCreateParserWithDirSkipping() |
45
|
|
|
{ |
46
|
|
|
$parser = new Parser( |
47
|
|
|
$this->reportPaths['base'] . 'clover_log.xml', |
48
|
|
|
[ |
49
|
|
|
'skip-dir' => 'src', |
50
|
|
|
'show-coverage' => false, |
51
|
|
|
] |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->assertEquals( |
55
|
|
|
[ |
56
|
|
|
'files' => [ |
57
|
|
|
'package' => 'SimpleLog\Message', |
58
|
|
|
], |
59
|
|
|
], |
60
|
|
|
$parser->getInfoList() |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function testCreateParserWithDirSkippingForNoneExistingDir() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$parser = new Parser( |
67
|
|
|
$this->reportPaths['base'] . 'clover_log.xml', |
68
|
|
|
[ |
69
|
|
|
'skip-dir' => 'foo', |
70
|
|
|
'show-coverage' => false, |
71
|
|
|
] |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$this->assertEquals( |
75
|
|
|
$this->infoList(), |
76
|
|
|
$parser->getInfoList() |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function infoList() |
81
|
|
|
{ |
82
|
|
|
return [ |
83
|
|
|
'files' => [ |
84
|
|
|
'package' => 'SimpleLog\Message', |
85
|
|
|
[ |
86
|
|
|
'path' => '{$path}log/src/Log.php', |
87
|
|
|
'package' => 'SimpleLog', |
88
|
|
|
'namespace' => 'Log', |
89
|
|
|
'percent' => 84.210526315789465, |
90
|
|
|
'info' => [ |
91
|
|
|
45 => '9', |
92
|
|
|
47 => '9', |
93
|
|
|
49 => '9', |
94
|
|
|
50 => '9', |
95
|
|
|
52 => '9', |
96
|
|
|
53 => '9', |
97
|
|
|
54 => '9', |
98
|
|
|
63 => '8', |
99
|
|
|
65 => '8', |
100
|
|
|
74 => '10', |
101
|
|
|
76 => '10', |
102
|
|
|
77 => '1', |
103
|
|
|
80 => '9', |
104
|
|
|
81 => '9', |
105
|
|
|
82 => '8', |
106
|
|
|
84 => '8', |
107
|
|
|
85 => '8', |
108
|
|
|
90 => '10', |
109
|
|
|
92 => '10', |
110
|
|
|
93 => '0', |
111
|
|
|
94 => '0', |
112
|
|
|
97 => '10', |
113
|
|
|
98 => '10', |
114
|
|
|
104 => '9', |
115
|
|
|
106 => '9', |
116
|
|
|
107 => '0', |
117
|
|
|
108 => '0', |
118
|
|
|
111 => '9', |
119
|
|
|
112 => '9', |
120
|
|
|
122 => '3', |
121
|
|
|
124 => '3', |
122
|
|
|
125 => '3', |
123
|
|
|
134 => '3', |
124
|
|
|
136 => '3', |
125
|
|
|
137 => '1', |
126
|
|
|
140 => '3', |
127
|
|
|
146 => '1', |
128
|
|
|
148 => '1', |
129
|
|
|
], |
130
|
|
|
], |
131
|
|
|
[ |
132
|
|
|
'path' => '{$path}log/src/LogStatic.php', |
133
|
|
|
'package' => 'SimpleLog', |
134
|
|
|
'namespace' => 'LogStatic', |
135
|
|
|
'percent' => 100, |
136
|
|
|
'info' => [ |
137
|
|
|
21 => '1', |
138
|
|
|
23 => '1', |
139
|
|
|
24 => '1', |
140
|
|
|
35 => '1', |
141
|
|
|
37 => '1', |
142
|
|
|
38 => '1', |
143
|
|
|
48 => '2', |
144
|
|
|
50 => '2', |
145
|
|
|
51 => '2', |
146
|
|
|
60 => '2', |
147
|
|
|
62 => '2', |
148
|
|
|
63 => '2', |
149
|
|
|
71 => '2', |
150
|
|
|
73 => '2', |
151
|
|
|
74 => '1', |
152
|
|
|
76 => '2', |
153
|
|
|
], |
154
|
|
|
], |
155
|
|
|
[ |
156
|
|
|
'path' => '{$path}log/src/DefaultJsonMessage.php', |
157
|
|
|
'package' => 'SimpleLog\Message', |
158
|
|
|
'namespace' => 'DefaultJsonMessage', |
159
|
|
|
'percent' => 0, |
160
|
|
|
'info' => [ |
161
|
|
|
18 => '0', |
162
|
|
|
21 => '0', |
163
|
|
|
26 => '0', |
164
|
|
|
28 => '0', |
165
|
|
|
], |
166
|
|
|
], |
167
|
|
|
], |
168
|
|
|
]; |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
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.