1 | <?php |
||
8 | class IncidentsTableTest extends TestCase |
||
9 | { |
||
10 | public $fixtures = array( |
||
11 | 'app.notifications', |
||
12 | 'app.developers', |
||
13 | 'app.reports', |
||
14 | 'app.incidents', |
||
15 | ); |
||
16 | |||
17 | public function setUp() |
||
22 | |||
23 | public function testGetStackHash() |
||
56 | |||
57 | public function testGetServer() |
||
78 | |||
79 | public function testGetSimpleVersion() |
||
104 | |||
105 | public function testGetIdentifyingLocation() |
||
170 | |||
171 | public function testGetSchematizedIncident() |
||
172 | { |
||
173 | $method = new \ReflectionMethod($this->Incidents, '_getSchematizedIncidents'); |
||
174 | $method->setAccessible(true); |
||
175 | |||
176 | // Case-1: JavaScript Report |
||
177 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_js.json'); |
||
178 | $bugReport = json_decode($bugReport, true); |
||
179 | |||
180 | $result = $method->invoke($this->Incidents, |
||
181 | $bugReport); |
||
182 | |||
183 | $expected = array( |
||
184 | array( |
||
185 | 'pma_version' => '4.0', |
||
186 | 'php_version' => '5.2', |
||
187 | 'steps' => '<script>test steps', |
||
188 | 'error_message' => 'a is not defined', |
||
189 | 'error_name' => 'ReferenceError', |
||
190 | 'browser' => 'FIREFOX 17', |
||
191 | 'user_os' => 'Windows', |
||
192 | 'locale' => 'en', |
||
193 | 'script_name' => 'tbl_relation.php', |
||
194 | 'configuration_storage' => 'enabled', |
||
195 | 'server_software' => 'NginX/1.17', |
||
196 | 'stackhash' => '9db5408094f1e76ef7161b7bbf3ddfe4', |
||
197 | 'full_report' => json_encode($bugReport), |
||
198 | 'stacktrace' => json_encode($bugReport['exception']['stack']), |
||
199 | 'exception_type' => 0, |
||
200 | ), |
||
201 | ); |
||
202 | |||
203 | $this->assertEquals($expected, $result); |
||
204 | |||
205 | // Case-2: php Report |
||
206 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_php.json'); |
||
207 | $bugReport = json_decode($bugReport, true); |
||
208 | |||
209 | $result = $method->invoke($this->Incidents, |
||
210 | $bugReport); |
||
211 | |||
212 | $expected = array( |
||
213 | array( |
||
214 | 'pma_version' => '4.3.0-dev', |
||
215 | 'php_version' => '5.5', |
||
216 | 'error_message' => 'Undefined variable: haha', |
||
217 | 'error_name' => 'Notice', |
||
218 | 'browser' => 'CHROME 27', |
||
219 | 'user_os' => 'Linux', |
||
220 | 'locale' => 'en', |
||
221 | 'script_name' => './libraries/Config.class.php', |
||
222 | 'configuration_storage' => 'disabled', |
||
223 | 'server_software' => 'Apache/2.4', |
||
224 | 'stackhash' => '5063bbe81a2daa6a6ad39c5cd315701c', |
||
225 | 'full_report' => json_encode($bugReport), |
||
226 | 'stacktrace' => json_encode($bugReport['errors'][0]['stackTrace']), |
||
227 | 'exception_type' => 1, |
||
228 | ), |
||
229 | array( |
||
230 | 'pma_version' => '4.3.0-dev', |
||
231 | 'php_version' => '5.5', |
||
232 | 'error_message' => 'Undefined variable: hihi', |
||
233 | 'error_name' => 'Notice', |
||
234 | 'browser' => 'CHROME 27', |
||
235 | 'user_os' => 'Linux', |
||
236 | 'locale' => 'en', |
||
237 | 'script_name' => './libraries/Util.class.php', |
||
238 | 'configuration_storage' => 'disabled', |
||
239 | 'server_software' => 'Apache/2.4', |
||
240 | 'stackhash' => 'e911a21765eae766463612e033773716', |
||
241 | 'full_report' => json_encode($bugReport), |
||
242 | 'stacktrace' => json_encode($bugReport['errors'][1]['stackTrace']), |
||
243 | 'exception_type' => 1, |
||
244 | ), |
||
245 | array( |
||
246 | 'pma_version' => '4.3.0-dev', |
||
247 | 'php_version' => '5.5', |
||
248 | 'error_message' => 'Undefined variable: hehe', |
||
249 | 'error_name' => 'Notice', |
||
250 | 'browser' => 'CHROME 27', |
||
251 | 'user_os' => 'Linux', |
||
252 | 'locale' => 'en', |
||
253 | 'script_name' => './index.php', |
||
254 | 'configuration_storage' => 'disabled', |
||
255 | 'server_software' => 'Apache/2.4', |
||
256 | 'stackhash' => '37848b23bdd6e737273516b9575fe407', |
||
257 | 'full_report' => json_encode($bugReport), |
||
258 | 'stacktrace' => json_encode($bugReport['errors'][2]['stackTrace']), |
||
259 | 'exception_type' => 1, |
||
260 | ), |
||
261 | ); |
||
262 | |||
263 | $this->assertEquals($expected, $result); |
||
264 | } |
||
265 | |||
266 | public function testGetReportDetails() |
||
308 | |||
309 | public function testGetClosestReport() |
||
324 | |||
325 | public function testCreateIncidentFromBugReport() |
||
326 | { |
||
327 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_js.json'); |
||
328 | $bugReport = json_decode($bugReport, true); |
||
329 | |||
330 | // Case-1: 'js' report |
||
331 | |||
332 | // Case-1.1: closest report = null |
||
333 | $result = $this->Incidents->createIncidentFromBugReport($bugReport); |
||
334 | $this->assertEquals(1, count($result)); |
||
335 | |||
336 | // Case-1.2: closest report = some report. |
||
337 | // Previously(in Case-1.1) inserted Reports serve as ClosestReports. |
||
338 | $result = $this->Incidents->createIncidentFromBugReport($bugReport); |
||
339 | $this->assertEquals(1, count($result)); |
||
340 | $incident = $this->Incidents->get($result[0]); |
||
341 | // check the incident has been reported under the same 'Report' |
||
342 | $result = TableRegistry::get('Incidents')->find('all', array('conditions' => array('report_id = ' . $incident->report_id))); |
||
343 | $result = $result->hydrate(false)->toArray(); |
||
344 | $this->assertEquals(2, count($result)); |
||
345 | |||
346 | // Case-2: for 'php' reports |
||
347 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_php.json'); |
||
348 | $bugReport = json_decode($bugReport, true); |
||
349 | // Case-2.1: closest report = null. |
||
350 | $result = $this->Incidents->createIncidentFromBugReport($bugReport); |
||
351 | $this->assertEquals(3, count($result)); |
||
352 | |||
353 | // Case-2.2: closest report = some report. |
||
354 | // Previously(in Case-2.1) inserted Reports serve as ClosestReports. |
||
355 | $result = $this->Incidents->createIncidentFromBugReport($bugReport); |
||
356 | $this->assertEquals(3, count($result)); |
||
357 | // check the incidents have been reported under the same 'Report's |
||
358 | $incident = $this->Incidents->get($result[0]); |
||
359 | $result = TableRegistry::get('Incidents')->find('all', array('conditions' => array('report_id = ' . $incident->report_id))); |
||
360 | $result = $result->hydrate(false)->toArray(); |
||
361 | $this->assertEquals(2, count($result)); |
||
362 | |||
363 | |||
364 | // Case 3.1: Long PHP report submission |
||
365 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_php.json'); |
||
366 | $bugReport = json_decode($bugReport, true); |
||
367 | |||
368 | // Forcefully inflate the report by inflating $bugReport['errors'] |
||
369 | for ($i = 0; $i < 2000; $i++) { |
||
370 | $bugReport['errors'][] = $bugReport['errors'][0]; |
||
371 | } |
||
372 | $result = $this->Incidents->createIncidentFromBugReport($bugReport); |
||
373 | |||
374 | $this->assertEquals(true, in_array(false, $result)); |
||
375 | |||
376 | |||
377 | // Case 3.2: Long JS report submission |
||
378 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_js.json'); |
||
379 | $bugReport = json_decode($bugReport, true); |
||
380 | |||
381 | // Forcefully inflate the report by inflating $bugReport['exception']['stack'] |
||
382 | for ($i = 0; $i < 1500; $i++) { |
||
383 | $bugReport['exception']['stack'][] = $bugReport['exception']['stack'][0]; |
||
384 | } |
||
385 | $result = $this->Incidents->createIncidentFromBugReport($bugReport); |
||
386 | |||
387 | $this->assertEquals(true, in_array(false, $result)); |
||
388 | } |
||
389 | |||
390 | /** |
||
391 | * @dataProvider versionsStripping |
||
392 | */ |
||
393 | public function testStripversion($version, $expected) |
||
397 | |||
398 | public function versionsStripping() |
||
409 | } |
||
410 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: