LimeParserTap.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. class LimeParserTap extends LimeParser
  3. {
  4. public function __construct(LimeOutputInterface $output)
  5. {
  6. parent::__construct($output);
  7. }
  8. public function parse($data)
  9. {
  10. $this->buffer .= $data;
  11. while (!$this->done())
  12. {
  13. if (preg_match('/^(.+)\n/', $this->buffer, $matches))
  14. {
  15. $this->buffer = substr($this->buffer, strlen($matches[0]));
  16. $line = $matches[0];
  17. if (preg_match('/^1\.\.(\d+)\n/', $line, $matches))
  18. {
  19. $this->output->plan((int)$matches[1]);
  20. }
  21. else if (preg_match('/^ok \d+( - (.+?))?( # (SKIP|TODO)( .+)?)?\n/', $line, $matches))
  22. {
  23. $message = count($matches) > 2 ? $matches[2] : '';
  24. if (count($matches) > 3)
  25. {
  26. if ($matches[4] == 'SKIP')
  27. {
  28. $this->output->skip($message, '', '');
  29. }
  30. else
  31. {
  32. $this->output->todo($message, '', '');
  33. $this->output->warning('TODOs are expected to have status "not ok"', '', '');
  34. }
  35. }
  36. else
  37. {
  38. $this->output->pass($message, '', '');
  39. }
  40. }
  41. else if (preg_match('/^not ok \d+( - (.+?))?( # (SKIP|TODO)( .+)?)?\n/', $line, $matches))
  42. {
  43. $message = count($matches) > 2 ? $matches[2] : '';
  44. if (count($matches) > 3)
  45. {
  46. if ($matches[4] == 'SKIP')
  47. {
  48. $this->output->skip($message, '', '');
  49. $this->output->warning('Skipped tests are expected to have status "ok"', '', '');
  50. }
  51. else
  52. {
  53. $this->output->todo($message, '', '');
  54. }
  55. }
  56. else
  57. {
  58. $this->output->fail($message, '', '');
  59. }
  60. }
  61. }
  62. else
  63. {
  64. break;
  65. }
  66. }
  67. $this->clearErrors();
  68. }
  69. public function done()
  70. {
  71. return empty($this->buffer);
  72. }
  73. }