[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DifferentialUnitField 4 extends DifferentialCustomField { 5 6 public function getFieldKey() { 7 return 'differential:unit'; 8 } 9 10 public function getFieldName() { 11 return pht('Unit'); 12 } 13 14 public function getFieldDescription() { 15 return pht('Shows unit test results.'); 16 } 17 18 public function shouldAppearInPropertyView() { 19 return true; 20 } 21 22 public function renderPropertyViewLabel() { 23 return $this->getFieldName(); 24 } 25 26 public function getRequiredDiffPropertiesForRevisionView() { 27 return array( 28 'arc:unit', 29 'arc:unit-excuse', 30 ); 31 } 32 33 public function renderPropertyViewValue(array $handles) { 34 $diff = $this->getObject()->getActiveDiff(); 35 36 $ustar = DifferentialRevisionUpdateHistoryView::renderDiffUnitStar($diff); 37 $umsg = DifferentialRevisionUpdateHistoryView::getDiffUnitMessage($diff); 38 39 $rows = array(); 40 41 $rows[] = array( 42 'style' => 'star', 43 'name' => $ustar, 44 'value' => $umsg, 45 'show' => true, 46 ); 47 48 $excuse = $diff->getProperty('arc:unit-excuse'); 49 if ($excuse) { 50 $rows[] = array( 51 'style' => 'excuse', 52 'name' => 'Excuse', 53 'value' => phutil_escape_html_newlines($excuse), 54 'show' => true, 55 ); 56 } 57 58 $show_limit = 10; 59 $hidden = array(); 60 61 $udata = $diff->getProperty('arc:unit'); 62 if ($udata) { 63 $sort_map = array( 64 ArcanistUnitTestResult::RESULT_BROKEN => 0, 65 ArcanistUnitTestResult::RESULT_FAIL => 1, 66 ArcanistUnitTestResult::RESULT_UNSOUND => 2, 67 ArcanistUnitTestResult::RESULT_SKIP => 3, 68 ArcanistUnitTestResult::RESULT_POSTPONED => 4, 69 ArcanistUnitTestResult::RESULT_PASS => 5, 70 ); 71 72 foreach ($udata as $key => $test) { 73 $udata[$key]['sort'] = idx($sort_map, idx($test, 'result')); 74 } 75 $udata = isort($udata, 'sort'); 76 $engine = new PhabricatorMarkupEngine(); 77 $engine->setViewer($this->getViewer()); 78 $markup_objects = array(); 79 foreach ($udata as $key => $test) { 80 $userdata = idx($test, 'userdata'); 81 if ($userdata) { 82 if ($userdata !== false) { 83 $userdata = str_replace("\000", '', $userdata); 84 } 85 $markup_object = id(new PhabricatorMarkupOneOff()) 86 ->setContent($userdata) 87 ->setPreserveLinebreaks(true); 88 $engine->addObject($markup_object, 'default'); 89 $markup_objects[$key] = $markup_object; 90 } 91 } 92 $engine->process(); 93 foreach ($udata as $key => $test) { 94 $result = idx($test, 'result'); 95 96 $default_hide = false; 97 switch ($result) { 98 case ArcanistUnitTestResult::RESULT_POSTPONED: 99 case ArcanistUnitTestResult::RESULT_PASS: 100 $default_hide = true; 101 break; 102 } 103 104 if ($show_limit && !$default_hide) { 105 --$show_limit; 106 $show = true; 107 } else { 108 $show = false; 109 if (empty($hidden[$result])) { 110 $hidden[$result] = 0; 111 } 112 $hidden[$result]++; 113 } 114 115 $value = idx($test, 'name'); 116 if (!empty($test['link'])) { 117 $value = phutil_tag( 118 'a', 119 array( 120 'href' => $test['link'], 121 'target' => '_blank', 122 ), 123 $value); 124 } 125 $rows[] = array( 126 'style' => $this->getResultStyle($result), 127 'name' => ucwords($result), 128 'value' => $value, 129 'show' => $show, 130 ); 131 132 if (isset($markup_objects[$key])) { 133 $rows[] = array( 134 'style' => 'details', 135 'value' => $engine->getOutput($markup_objects[$key], 'default'), 136 'show' => false, 137 ); 138 if (empty($hidden['details'])) { 139 $hidden['details'] = 0; 140 } 141 $hidden['details']++; 142 } 143 } 144 } 145 146 $show_string = $this->renderShowString($hidden); 147 148 $view = new DifferentialResultsTableView(); 149 $view->setRows($rows); 150 $view->setShowMoreString($show_string); 151 152 return $view->render(); 153 } 154 155 private function getResultStyle($result) { 156 $map = array( 157 ArcanistUnitTestResult::RESULT_PASS => 'green', 158 ArcanistUnitTestResult::RESULT_FAIL => 'red', 159 ArcanistUnitTestResult::RESULT_SKIP => 'blue', 160 ArcanistUnitTestResult::RESULT_BROKEN => 'red', 161 ArcanistUnitTestResult::RESULT_UNSOUND => 'yellow', 162 ArcanistUnitTestResult::RESULT_POSTPONED => 'blue', 163 ); 164 return idx($map, $result); 165 } 166 167 private function renderShowString(array $hidden) { 168 if (!$hidden) { 169 return null; 170 } 171 172 // Reorder hidden things by severity. 173 $hidden = array_select_keys( 174 $hidden, 175 array( 176 ArcanistUnitTestResult::RESULT_BROKEN, 177 ArcanistUnitTestResult::RESULT_FAIL, 178 ArcanistUnitTestResult::RESULT_UNSOUND, 179 ArcanistUnitTestResult::RESULT_SKIP, 180 ArcanistUnitTestResult::RESULT_POSTPONED, 181 ArcanistUnitTestResult::RESULT_PASS, 182 'details', 183 )) + $hidden; 184 185 $noun = array( 186 ArcanistUnitTestResult::RESULT_BROKEN => 'Broken', 187 ArcanistUnitTestResult::RESULT_FAIL => 'Failed', 188 ArcanistUnitTestResult::RESULT_UNSOUND => 'Unsound', 189 ArcanistUnitTestResult::RESULT_SKIP => 'Skipped', 190 ArcanistUnitTestResult::RESULT_POSTPONED => 'Postponed', 191 ArcanistUnitTestResult::RESULT_PASS => 'Passed', 192 ); 193 194 $show = array(); 195 foreach ($hidden as $key => $value) { 196 if ($key == 'details') { 197 $show[] = pht('%d Detail(s)', $value); 198 } else { 199 $show[] = $value.' '.idx($noun, $key); 200 } 201 } 202 203 return 'Show Full Unit Results ('.implode(', ', $show).')'; 204 } 205 206 public function getWarningsForDetailView() { 207 $status = $this->getObject()->getActiveDiff()->getUnitStatus(); 208 209 $warnings = array(); 210 if ($status < DifferentialUnitStatus::UNIT_WARN) { 211 // Don't show any warnings. 212 } else if ($status == DifferentialUnitStatus::UNIT_AUTO_SKIP) { 213 // Don't show any warnings. 214 } else if ($status == DifferentialUnitStatus::UNIT_POSTPONED) { 215 $warnings[] = pht( 216 'Background tests have not finished executing on these changes.'); 217 } else if ($status == DifferentialUnitStatus::UNIT_SKIP) { 218 $warnings[] = pht( 219 'Unit tests were skipped when generating these changes.'); 220 } else { 221 $warnings[] = pht('These changes have unit test problems.'); 222 } 223 224 return $warnings; 225 } 226 227 228 }
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 |