annotate core/lib/Drupal/Core/Test/TestStatus.php @ 19:fa3358dc1485 tip

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