TestStatus.php 1.6 KB

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