summaryrefslogtreecommitdiffstatshomepage
path: root/core/lib/Drupal/Core/Test/TestStatus.php
blob: 91689eb07339eb5e6573a9f197e32918257eb0f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

namespace Drupal\Core\Test;

/**
 * Consolidates test result status information.
 *
 * For our test runners, a $status of 0 = passed test, 1 = failed test,
 * 2 = errored test, >2 indicates segfault timeout, or other type of system
 * failure.
 */
class TestStatus {

  /**
   * Signify that the test result was a passed test.
   */
  const PASS = 0;

  /**
   * Signify that the test result was a failed test.
   */
  const FAIL = 1;

  /**
   * Signify that the test result was a code error.
   *
   * This means that the test runner was able to exit and report an error.
   */
  const ERROR = 2;

  /**
   * Signify a system error where the test runner was unable to complete.
   *
   * Note that SYSTEM actually represents the lowest value of system errors, and
   * the returned value could be as high as 127. Since that's the case, this
   * constant should be used for range comparisons, and not just for equality.
   *
   * @see http://php.net/manual/pcntl.constants.php
   */
  const SYSTEM = 3;

  /**
   * Turns a status code into a human-readable string.
   *
   * @param int $status
   *   A test runner return code.
   *
   * @return string
   *   The human-readable version of the status code.
   */
  public static function label($status) {
    $statusMap = [
      static::PASS => 'pass',
      static::FAIL => 'fail',
      static::ERROR => 'error',
      static::SYSTEM => 'exception',
    ];
    // For status 3 and higher, we want 'exception.'
    $label = $statusMap[$status > static::SYSTEM ? static::SYSTEM : $status];
    return $label;
  }

}