@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class DifferentialUnitStatus extends Phobject {
4
5 const UNIT_NONE = 0;
6 const UNIT_OKAY = 1;
7 const UNIT_WARN = 2;
8 const UNIT_FAIL = 3;
9 const UNIT_SKIP = 4;
10 const UNIT_AUTO_SKIP = 6;
11
12 private $value;
13
14 public static function newStatusFromValue($value) {
15 $status = new self();
16 $status->value = $value;
17 return $status;
18 }
19
20 public function getValue() {
21 return $this->value;
22 }
23
24 public function getName() {
25 $name = $this->getUnitStatusProperty('name');
26
27 if ($name === null) {
28 $name = pht('Unknown Unit Status ("%s")', $this->getValue());
29 }
30
31 return $name;
32 }
33
34 public function getIconIcon() {
35 return $this->getUnitStatusProperty('icon.icon');
36 }
37
38 public function getIconColor() {
39 return $this->getUnitStatusProperty('icon.color');
40 }
41
42 public static function getStatusMap() {
43 $results = array();
44
45 foreach (self::newUnitStatusMap() as $value => $ignored) {
46 $results[$value] = self::newStatusFromValue($value);
47 }
48
49 return $results;
50 }
51
52 private function getUnitStatusProperty($key, $default = null) {
53 $map = self::newUnitStatusMap();
54 $properties = idx($map, $this->getValue(), array());
55 return idx($properties, $key, $default);
56 }
57
58 private static function newUnitStatusMap() {
59 return array(
60 self::UNIT_NONE => array(
61 'name' => pht('No Test Coverage'),
62 'icon.icon' => 'fa-ban',
63 'icon.color' => 'grey',
64 ),
65 self::UNIT_OKAY => array(
66 'name' => pht('Tests Passed'),
67 'icon.icon' => 'fa-check',
68 'icon.color' => 'green',
69 ),
70 self::UNIT_WARN => array(
71 'name' => pht('Test Warnings'),
72 'icon.icon' => 'fa-exclamation-triangle',
73 'icon.color' => 'yellow',
74 ),
75 self::UNIT_FAIL => array(
76 'name' => pht('Test Failures'),
77 'icon.icon' => 'fa-times',
78 'icon.color' => 'red',
79 ),
80 self::UNIT_SKIP => array(
81 'name' => pht('Tests Skipped'),
82 'icon.icon' => 'fa-fast-forward',
83 'icon.color' => 'blue',
84 ),
85 self::UNIT_AUTO_SKIP => array(
86 'name' => pht('Tests Not Applicable'),
87 'icon.icon' => 'fa-code',
88 'icon.color' => 'grey',
89 ),
90 );
91 }
92
93}