1<?php 2 3namespace Drupal\Core\Test; 4 5/** 6 * Consolidates test result status information. 7 * 8 * For our test runners, a $status of 0 = passed test, 1 = failed test, 9 * 2 = exception, >2 indicates segfault timeout, or other type of system 10 * failure. 11 */ 12class TestStatus { 13 14 /** 15 * Signify that the test result was a passed test. 16 */ 17 const PASS = 0; 18 19 /** 20 * Signify that the test result was a failed test. 21 */ 22 const FAIL = 1; 23 24 /** 25 * Signify that the test result was an exception or code error. 26 * 27 * This means that the test runner was able to exit and report an error. 28 */ 29 const EXCEPTION = 2; 30 31 /** 32 * Signify a system error where the test runner was unable to complete. 33 * 34 * Note that SYSTEM actually represents the lowest value of system errors, and 35 * the returned value could be as high as 127. Since that's the case, this 36 * constant should be used for range comparisons, and not just for equality. 37 * 38 * @see http://php.net/manual/pcntl.constants.php 39 */ 40 const SYSTEM = 3; 41 42 /** 43 * Turns a status code into a human-readable string. 44 * 45 * @param int $status 46 * A test runner return code. 47 * 48 * @return string 49 * The human-readable version of the status code. 50 */ 51 public static function label($status) { 52 $statusMap = [ 53 static::PASS => 'pass', 54 static::FAIL => 'fail', 55 static::EXCEPTION => 'exception', 56 static::SYSTEM => 'error', 57 ]; 58 // For status 3 and higher, we want 'error.' 59 $label = $statusMap[$status > static::SYSTEM ? static::SYSTEM : $status]; 60 return $label; 61 } 62 63} 64