@@ -19,38 +19,14 @@ class MetricsFactoryTest extends TestCase
19
19
* @covers ::getMethodMetrics
20
20
* @covers ::mergeFileMetrics
21
21
* @covers ::getCoveredStatements
22
+ * @dataProvider multiFilesDataProvider
22
23
*/
23
- public function testGetFilesMetrics (): void
24
+ public function testGetFilesMetrics (string $ file1Data , string $ file2Data , int $ methods , float $ coverage , array $ coveredStatements ): void
24
25
{
25
26
$ xml1 = '<?xml version="1.0" encoding="UTF-8"?>
26
27
<coverage generated="1598702199">
27
28
<project timestamp="1598702199">
28
- <file name="/API \\Example.php">
29
- <line num="1" type="method" name="methodName" count="2"/>
30
- <line num="2" type="stmt" count="2"/>
31
- <line num="3" type="stmt" count="0"/>
32
- <line num="4" type="stmt" count="0"/>
33
- <line num="5" type="stmt" count="0"/>
34
- <metrics loc="11" ncloc="11" statements="4" coveredstatements="1"/>
35
- </file>
36
- <file name="/API \\Example2.php">
37
- <line num="1" type="method" name="methodName" count="0"/>
38
- <line num="2" type="stmt" count="0"/>
39
- <line num="3" type="stmt" count="0"/>
40
- <line num="4" type="stmt" count="0"/>
41
- <line num="5" type="stmt" count="0"/>
42
- <line num="6" type="stmt" count="0"/>
43
- <metrics loc="11" ncloc="11" statements="5" coveredstatements="0"/>
44
- </file>
45
- <file name="/API \\Example3.php">
46
- <metrics loc="11" ncloc="11" statements="0" coveredstatements="0"/>
47
- </file>
48
- <file name="/API \\Example4.php">
49
- <metrics loc="11" ncloc="11" statements="1" coveredstatements="1"/>
50
- </file>
51
- <file name="/API \\Example5.php">
52
- <metrics loc="11" ncloc="11" statements="2" coveredstatements="0"/>
53
- </file>
29
+ ' . $ file1Data . '
54
30
</project>
55
31
</coverage> ' ;
56
32
@@ -60,71 +36,21 @@ public function testGetFilesMetrics(): void
60
36
$ xml2 = '<?xml version="1.0" encoding="UTF-8"?>
61
37
<coverage generated="1598702199">
62
38
<project timestamp="1598702199">
63
- <file name="/API \\Example.php">
64
- <line num="1" type="method" name="methodName" count="1"/>
65
- <line num="2" type="stmt" count="1"/>
66
- <line num="3" type="stmt" count="0"/>
67
- <line num="4" type="stmt" count="1"/>
68
- <line num="5" type="stmt" count="0"/>
69
- <metrics loc="11" ncloc="11" statements="4" coveredstatements="2"/>
70
- </file>
71
- <file name="/API \\Example2.php">
72
- <line num="1" type="method" name="methodName" count="1"/>
73
- <line num="2" type="stmt" count="1"/>
74
- <line num="3" type="stmt" count="1"/>
75
- <line num="4" type="stmt" count="1"/>
76
- <line num="5" type="stmt" count="0"/>
77
- <line num="6" type="stmt" count="1"/>
78
- <metrics loc="11" ncloc="11" statements="5" coveredstatements="4"/>
79
- </file>
80
- <file name="/API \\Example4.php">
81
- <metrics loc="11" ncloc="11" statements="0" coveredstatements="0"/>
82
- </file>
83
- <file name="/API \\Example5.php">
84
- <metrics loc="11" ncloc="11" statements="2" coveredstatements="2"/>
85
- </file>
39
+ ' . $ file2Data . '
86
40
</project>
87
41
</coverage> ' ;
88
42
89
43
$ dom2 = new DOMDocument ();
90
44
$ dom2 ->loadXML ($ xml2 );
91
45
92
46
$ metrics = MetricsFactory::getFilesMetrics ([$ dom1 , $ dom2 ]);
93
- static ::assertCount (5 , $ metrics );
47
+ static ::assertCount (1 , $ metrics );
94
48
95
- $ metric = $ metrics ['/API/Example.php ' ];
96
- static ::assertSame ('/API/Example.php ' , $ metric ->getFilepath ());
97
- static ::assertCount (1 , $ metric ->getMethods ());
98
- $ method = $ metric ->getMethods ()['methodName ' ];
99
- static ::assertSame ('methodName ' , $ method ->getMethodName ());
100
- static ::assertSame (1 , $ method ->getLineNumber ());
101
- static ::assertSame (2 , $ method ->getCount ());
102
- static ::assertSame (50.0 , $ metric ->getCoverage ());
103
- static ::assertSame ([2 , 4 ], $ metric ->getCoveredStatements ());
104
-
105
- $ metric = $ metrics ['/API/Example2.php ' ];
106
- static ::assertSame ('/API/Example2.php ' , $ metric ->getFilepath ());
107
- static ::assertCount (1 , $ metric ->getMethods ());
108
- static ::assertSame (80.0 , $ metric ->getCoverage ());
109
- static ::assertSame ([2 , 3 , 4 , 6 ], $ metric ->getCoveredStatements ());
110
-
111
- $ metric = $ metrics ['/API/Example3.php ' ];
112
- static ::assertSame ('/API/Example3.php ' , $ metric ->getFilepath ());
113
- static ::assertSame ([], $ metric ->getMethods ());
114
- static ::assertSame (100.0 , $ metric ->getCoverage ());
115
- static ::assertSame ([], $ metric ->getCoveredStatements ());
116
-
117
- $ metric = $ metrics ['/API/Example4.php ' ];
118
- static ::assertSame ('/API/Example4.php ' , $ metric ->getFilepath ());
119
- static ::assertSame ([], $ metric ->getMethods ());
120
- static ::assertSame (100.0 , $ metric ->getCoverage ());
121
- static ::assertSame ([], $ metric ->getCoveredStatements ());
122
-
123
- $ metric = $ metrics ['/API/Example5.php ' ];
124
- static ::assertSame ('/API/Example5.php ' , $ metric ->getFilepath ());
125
- static ::assertSame ([], $ metric ->getMethods ());
126
- static ::assertSame (100.0 , $ metric ->getCoverage ());
127
- static ::assertSame ([], $ metric ->getCoveredStatements ());
49
+ $ metric = $ metrics ['utTestFile.php ' ];
50
+ static ::assertSame ('utTestFile.php ' , $ metric ->getFilepath ());
51
+ static ::assertCount ($ methods , $ metric ->getMethods ());
52
+ static ::assertSame ($ coverage , $ metric ->getCoverage ());
53
+ static ::assertSame ($ coveredStatements , $ metric ->getCoveredStatements ());
128
54
}
129
55
130
56
/**
@@ -176,4 +102,83 @@ public function testGetMetricsEmptyXmlShouldReturnEmptyArray(): void
176
102
177
103
static ::assertCount (0 , MetricsFactory::getFilesMetrics ([$ dom ]));
178
104
}
105
+
106
+ public static function multiFilesDataProvider (): array
107
+ {
108
+ return [
109
+ 'second coverage is used ' => [
110
+ '<file name="utTestFile.php">
111
+ <line num="1" type="method" name="methodName" count="2"/>
112
+ <line num="2" type="stmt" count="2"/>
113
+ <line num="3" type="stmt" count="0"/>
114
+ <line num="4" type="stmt" count="0"/>
115
+ <line num="5" type="stmt" count="0"/>
116
+ <metrics loc="11" ncloc="11" statements="4" coveredstatements="1"/>
117
+ </file> ' ,
118
+ '<file name="utTestFile.php">
119
+ <line num="1" type="method" name="methodName" count="1"/>
120
+ <line num="2" type="stmt" count="1"/>
121
+ <line num="3" type="stmt" count="0"/>
122
+ <line num="4" type="stmt" count="1"/>
123
+ <line num="5" type="stmt" count="0"/>
124
+ <metrics loc="11" ncloc="11" statements="4" coveredstatements="2"/>
125
+ </file> ' ,
126
+ 1 ,
127
+ 50.0 ,
128
+ [2 , 4 ]
129
+ ],
130
+ 'second count is higher ' => [
131
+ '<file name="utTestFile.php">
132
+ <line num="1" type="method" name="methodName" count="1"/>
133
+ <line num="2" type="stmt" count="1"/>
134
+ <line num="3" type="stmt" count="1"/>
135
+ <line num="4" type="stmt" count="1"/>
136
+ <line num="5" type="stmt" count="1"/>
137
+ <metrics loc="11" ncloc="11" statements="4" coveredstatements="1"/>
138
+ </file> ' ,
139
+ '<file name="utTestFile.php">
140
+ <line num="1" type="method" name="methodName" count="2"/>
141
+ <line num="2" type="stmt" count="1"/>
142
+ <line num="3" type="stmt" count="0"/>
143
+ <line num="4" type="stmt" count="1"/>
144
+ <line num="5" type="stmt" count="0"/>
145
+ <metrics loc="11" ncloc="11" statements="4" coveredstatements="2"/>
146
+ </file> ' ,
147
+ 1 ,
148
+ 100.0 ,
149
+ [2 , 3 , 4 , 5 ]
150
+ ],
151
+ 'no second coverage ' => [
152
+ '<file name="utTestFile.php">
153
+ <metrics loc="11" ncloc="11" statements="0" coveredstatements="0"/>
154
+ </file> ' ,
155
+ '' ,
156
+ 0 ,
157
+ 100.0 ,
158
+ []
159
+ ],
160
+ 'first 100 % ' => [
161
+ '<file name="utTestFile.php">
162
+ <metrics loc="11" ncloc="11" statements="1" coveredstatements="1"/>
163
+ </file> ' ,
164
+ ' <file name="utTestFile.php">
165
+ <metrics loc="11" ncloc="11" statements="0" coveredstatements="0"/>
166
+ </file> ' ,
167
+ 0 ,
168
+ 100.0 ,
169
+ []
170
+ ],
171
+ 'second 100% ' => [
172
+ '<file name="utTestFile.php">
173
+ <metrics loc="11" ncloc="11" statements="2" coveredstatements="0"/>
174
+ </file> ' ,
175
+ '<file name="utTestFile.php">
176
+ <metrics loc="11" ncloc="11" statements="2" coveredstatements="2"/>
177
+ </file> ' ,
178
+ 0 ,
179
+ 100.0 ,
180
+ []
181
+ ]
182
+ ];
183
+ }
179
184
}
0 commit comments