@@ -62,4 +62,156 @@ public function testRun(): void
62
62
63
63
$ this ->assertSame ($ expectedTimeInSeconds , (float )$ matches ['timesum ' ]);
64
64
}
65
+
66
+ /**
67
+ * @covers ::run
68
+ */
69
+ public function testRunWithCodeception5Reports (): void
70
+ {
71
+ $ expectedTimeInSeconds = '03:34.98 ' ;
72
+ $ expectedSuccess = 3 ;
73
+
74
+ $ reportPath = TEST_PATH . '/fixtures/reports/html/ ' ;
75
+ $ task = new HtmlReportMerger ();
76
+ $ task ->setLogger (new Logger (new NullOutput ()));
77
+
78
+ $ resultReport = TEST_PATH . '/result/report_codeception5.html ' ;
79
+ $ task
80
+ ->from (
81
+ [
82
+ $ reportPath . 'report_0_codeception5.html ' , // this file did not exists and it should not fail
83
+ $ reportPath . 'report_1_codeception5.html ' ,
84
+ $ reportPath . 'report_2_codeception5.html ' ,
85
+ $ reportPath . 'report_3_codeception5.html ' ,
86
+ ]
87
+ )
88
+ ->into ($ resultReport )
89
+ ->run ();
90
+
91
+ $ this ->assertFileExists ($ resultReport );
92
+
93
+ //read first source file as main
94
+ $ dstHTML = new DOMDocument ();
95
+ $ dstHTML ->loadHTMLFile ($ resultReport , LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
96
+ /** @var DOMNodeList $values */
97
+ $ values = (new DOMXPath ($ dstHTML ))
98
+ ->query ("//*[contains(@class,'scenarioSuccessValue')] " );
99
+
100
+ $ this ->assertCount (1 , $ values );
101
+ $ this ->assertSame ($ expectedSuccess , (int )$ values [0 ]->nodeValue );
102
+
103
+ $ values = (new DOMXPath ($ dstHTML ))
104
+ ->query ("//h1[text() = 'Codeception Results '] " );
105
+ preg_match (
106
+ '#^Codeception Results .* \((?<timesum>(([0-1]?\d|2[0-3])(?::([0-5]?\d))?(?::([0-5]?\d))\.\d+))\)$# ' ,
107
+ $ values [0 ]->nodeValue ,
108
+ $ matches
109
+ );
110
+
111
+ $ this ->assertSame ($ expectedTimeInSeconds , (string )$ matches ['timesum ' ]);
112
+ }
113
+
114
+ /**
115
+ * @covers ::run
116
+ */
117
+ public function testRunMaxTimeReports (): void
118
+ {
119
+ $ expectedTime = '129.25 ' ;
120
+ $ expectedSuccess = 3 ;
121
+
122
+ $ reportPath = TEST_PATH . '/fixtures/reports/html/ ' ;
123
+ $ task = new HtmlReportMerger ();
124
+ $ task ->setLogger (new Logger (new NullOutput ()));
125
+
126
+ $ resultReport = TEST_PATH . '/result/report_max_time.html ' ;
127
+ $ task ->maxTime ();
128
+ $ task
129
+ ->from (
130
+ [
131
+ $ reportPath . 'report_0.html ' , // this file did not exists and it should not fail
132
+ $ reportPath . 'report_1.html ' ,
133
+ $ reportPath . 'report_2.html ' ,
134
+ $ reportPath . 'report_3.html ' ,
135
+ ]
136
+ )
137
+ ->into ($ resultReport )
138
+ ->run ();
139
+
140
+ $ this ->assertFileExists ($ resultReport );
141
+
142
+ //read first source file as main
143
+ $ dstHTML = new DOMDocument ();
144
+ $ dstHTML ->loadHTMLFile ($ resultReport , LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
145
+ /** @var DOMNodeList $values */
146
+ $ values = (new DOMXPath ($ dstHTML ))
147
+ ->query ("//*[contains(@class,'scenarioSuccessValue')] " );
148
+
149
+ $ this ->assertCount (1 , $ values );
150
+ $ this ->assertSame ($ expectedSuccess , (int )$ values [0 ]->nodeValue );
151
+
152
+ $ values = (new DOMXPath ($ dstHTML ))
153
+ ->query ("//h1[text() = 'Codeception Results '] " );
154
+ preg_match (
155
+ '#^Codeception Results .* \((?<timesum>\d+\.\d+)s\)$# ' ,
156
+ $ values [0 ]->nodeValue ,
157
+ $ matches
158
+ );
159
+ $ executionTime [] = (string )$ matches ['timesum ' ];
160
+ usort ($ executionTime , function ($ a , $ b ) {
161
+ return strcmp ($ a , $ b );
162
+ });
163
+ $ this ->assertSame ($ expectedTime , max ($ executionTime ));
164
+ }
165
+
166
+ /**
167
+ * @covers ::run
168
+ */
169
+ public function testRunMaxTimeWithCodeception5Reports (): void
170
+ {
171
+ $ expectedTime = '02:09.25 ' ;
172
+ $ expectedSuccess = 3 ;
173
+
174
+ $ reportPath = TEST_PATH . '/fixtures/reports/html/ ' ;
175
+ $ task = new HtmlReportMerger ();
176
+ $ task ->setLogger (new Logger (new NullOutput ()));
177
+
178
+ $ resultReport = TEST_PATH . '/result/report_codeception5_max_time.html ' ;
179
+ $ task ->maxTime ();
180
+ $ task
181
+ ->from (
182
+ [
183
+ $ reportPath . 'report_0_codeception5.html ' , // this file did not exists and it should not fail
184
+ $ reportPath . 'report_1_codeception5.html ' ,
185
+ $ reportPath . 'report_2_codeception5.html ' ,
186
+ $ reportPath . 'report_3_codeception5.html ' ,
187
+ ]
188
+ )
189
+ ->into ($ resultReport )
190
+ ->run ();
191
+
192
+ $ this ->assertFileExists ($ resultReport );
193
+
194
+ //read first source file as main
195
+ $ dstHTML = new DOMDocument ();
196
+ $ dstHTML ->loadHTMLFile ($ resultReport , LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
197
+ /** @var DOMNodeList $values */
198
+ $ values = (new DOMXPath ($ dstHTML ))
199
+ ->query ("//*[contains(@class,'scenarioSuccessValue')] " );
200
+
201
+ $ this ->assertCount (1 , $ values );
202
+ $ this ->assertSame ($ expectedSuccess , (int )$ values [0 ]->nodeValue );
203
+
204
+ $ values = (new DOMXPath ($ dstHTML ))
205
+ ->query ("//h1[text() = 'Codeception Results '] " );
206
+ preg_match (
207
+ '#^Codeception Results .* \((?<timesum>(([0-1]?\d|2[0-3])(?::([0-5]?\d))?(?::([0-5]?\d))\.\d+))\)$# ' ,
208
+ $ values [0 ]->nodeValue ,
209
+ $ matches
210
+ );
211
+ $ executionTime [] = (string )$ matches ['timesum ' ];
212
+ usort ($ executionTime , function ($ a , $ b ) {
213
+ return strcmp ($ a , $ b );
214
+ });
215
+ $ this ->assertSame ($ expectedTime , max ($ executionTime ));
216
+ }
65
217
}
0 commit comments