[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DifferentialUpdateUnitResultsConduitAPIMethod 4 extends DifferentialConduitAPIMethod { 5 6 public function getAPIMethodName() { 7 return 'differential.updateunitresults'; 8 } 9 10 public function getMethodDescription() { 11 return 'Update arc unit results for a postponed test.'; 12 } 13 14 public function defineParamTypes() { 15 return array( 16 'diff_id' => 'required diff_id', 17 'file' => 'required string', 18 'name' => 'required string', 19 'link' => 'optional string', 20 'result' => 'required string', 21 'message' => 'required string', 22 'coverage' => 'optional map<string, string>', 23 ); 24 } 25 26 public function defineReturnType() { 27 return 'void'; 28 } 29 30 public function defineErrorTypes() { 31 return array( 32 'ERR_BAD_DIFF' => 'Bad diff ID.', 33 'ERR_NO_RESULTS' => 'Could not find the postponed test', 34 ); 35 } 36 37 protected function execute(ConduitAPIRequest $request) { 38 39 $diff_id = $request->getValue('diff_id'); 40 if (!$diff_id) { 41 throw new ConduitException('ERR_BAD_DIFF'); 42 } 43 44 $file = $request->getValue('file'); 45 $name = $request->getValue('name'); 46 $link = $request->getValue('link'); 47 $message = $request->getValue('message'); 48 $result = $request->getValue('result'); 49 $coverage = $request->getValue('coverage', array()); 50 51 $diff_property = id(new DifferentialDiffProperty())->loadOneWhere( 52 'diffID = %d AND name = %s', 53 $diff_id, 54 'arc:unit'); 55 56 if (!$diff_property) { 57 throw new ConduitException('ERR_NO_RESULTS'); 58 } 59 60 $diff = id(new DifferentialDiffQuery()) 61 ->setViewer($request->getUser()) 62 ->withIDs(array($diff_id)) 63 ->executeOne(); 64 65 $unit_results = $diff_property->getData(); 66 $postponed_count = 0; 67 $unit_status = null; 68 69 // If the test result already exists, then update it with 70 // the new info. 71 foreach ($unit_results as &$unit_result) { 72 if ($unit_result['name'] === $name || 73 $unit_result['name'] === $file || 74 $unit_result['name'] === $diff->getSourcePath().$file) { 75 $unit_result['name'] = $name; 76 $unit_result['link'] = $link; 77 $unit_result['file'] = $file; 78 $unit_result['result'] = $result; 79 $unit_result['userdata'] = $message; 80 $unit_result['coverage'] = $coverage; 81 $unit_status = $result; 82 break; 83 } 84 } 85 unset($unit_result); 86 87 // If the test result doesn't exist, just add it. 88 if (!$unit_status) { 89 $unit_result = array(); 90 $unit_result['file'] = $file; 91 $unit_result['name'] = $name; 92 $unit_result['link'] = $link; 93 $unit_result['result'] = $result; 94 $unit_result['userdata'] = $message; 95 $unit_result['coverage'] = $coverage; 96 $unit_status = $result; 97 $unit_results[] = $unit_result; 98 } 99 unset($unit_result); 100 101 $diff_property->setData($unit_results); 102 $diff_property->save(); 103 104 // Map external unit test status to internal overall diff status 105 $status_codes = 106 array( 107 DifferentialUnitTestResult::RESULT_PASS => 108 DifferentialUnitStatus::UNIT_OKAY, 109 DifferentialUnitTestResult::RESULT_UNSOUND => 110 DifferentialUnitStatus::UNIT_WARN, 111 DifferentialUnitTestResult::RESULT_FAIL => 112 DifferentialUnitStatus::UNIT_FAIL, 113 DifferentialUnitTestResult::RESULT_BROKEN => 114 DifferentialUnitStatus::UNIT_FAIL, 115 DifferentialUnitTestResult::RESULT_SKIP => 116 DifferentialUnitStatus::UNIT_OKAY, 117 DifferentialUnitTestResult::RESULT_POSTPONED => 118 DifferentialUnitStatus::UNIT_POSTPONED, 119 ); 120 121 // These are the relative priorities for the unit test results 122 $status_codes_priority = 123 array( 124 DifferentialUnitStatus::UNIT_OKAY => 1, 125 DifferentialUnitStatus::UNIT_WARN => 2, 126 DifferentialUnitStatus::UNIT_POSTPONED => 3, 127 DifferentialUnitStatus::UNIT_FAIL => 4, 128 ); 129 130 // Walk the now-current list of status codes to find the overall diff 131 // status 132 $final_diff_status = DifferentialUnitStatus::UNIT_NONE; 133 foreach ($unit_results as $unit_result) { 134 // Convert the text result into a diff unit status value 135 $status_code = idx($status_codes, 136 $unit_result['result'], 137 DifferentialUnitStatus::UNIT_NONE); 138 139 // Convert the unit status into a relative value 140 $diff_status_priority = idx($status_codes_priority, $status_code, 0); 141 142 // If the relative value of this result is "more bad" than previous 143 // results, use it as the new final diff status 144 if ($diff_status_priority > idx($status_codes_priority, 145 $final_diff_status, 0)) { 146 $final_diff_status = $status_code; 147 } 148 } 149 150 // Update our unit test result status with the final value 151 $diff->setUnitStatus($final_diff_status); 152 $diff->save(); 153 } 154 155 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |