LimeOutputResult.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. /*
  3. * This file is part of the Lime framework.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. * (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. /**
  12. * Collects and interprets the input of a LimeOutput... instance.
  13. *
  14. * @package Lime
  15. * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
  16. * @version SVN: $Id: LimeOutputResult.php 25932 2009-12-27 19:55:32Z bschussek $
  17. */
  18. class LimeOutputResult
  19. {
  20. private
  21. $nbExpected = null,
  22. $nbActual = 0,
  23. $nbPassed = 0,
  24. $failures = array(),
  25. $errors = array(),
  26. $warnings = array(),
  27. $todos = array();
  28. /**
  29. * Adds the given amount of tests to the test plan.
  30. *
  31. * @param integer $plan
  32. */
  33. public function addPlan($plan)
  34. {
  35. $this->nbExpected += $plan;
  36. }
  37. /**
  38. * Adds a passed test.
  39. */
  40. public function addPassed()
  41. {
  42. $this->nbActual++;
  43. $this->nbPassed++;
  44. }
  45. /**
  46. * Adds a failed test.
  47. *
  48. * @param array $failure The test failure. An array with the failure message,
  49. * the script, the line in the script and optionally
  50. * the specific error.
  51. */
  52. public function addFailure(array $failure)
  53. {
  54. $this->nbActual++;
  55. $this->failures[] = $failure;
  56. }
  57. /**
  58. * Adds a skipped test.
  59. */
  60. public function addSkipped()
  61. {
  62. $this->nbActual++;
  63. $this->nbPassed++;
  64. }
  65. /**
  66. * Adds a todo.
  67. *
  68. * @param string $text The todo message.
  69. */
  70. public function addTodo($text)
  71. {
  72. $this->nbActual++;
  73. $this->todos[] = $text;
  74. }
  75. /**
  76. * Adds a test error.
  77. *
  78. * @param LimeError $error The error.
  79. */
  80. public function addError(LimeError $error)
  81. {
  82. $this->errors[] = $error;
  83. }
  84. /**
  85. * Adds a test warning.
  86. *
  87. * @param array $warning An array with the warning message, the path of the
  88. * test script and the line of the test script where
  89. * the warning occurred.
  90. */
  91. public function addWarning(array $warning)
  92. {
  93. $this->warnings[] = $warning;
  94. }
  95. /**
  96. * Returns the actual number of tests.
  97. *
  98. * @return integer
  99. */
  100. public function getNbActual()
  101. {
  102. return $this->nbActual;
  103. }
  104. /**
  105. * Returns the expected number of tests.
  106. *
  107. * @return integer
  108. */
  109. public function getNbExpected()
  110. {
  111. return is_null($this->nbExpected) ? $this->nbActual : $this->nbExpected;
  112. }
  113. /**
  114. * Returns the number of passed tests.
  115. *
  116. * @return integer
  117. */
  118. public function getNbPassed()
  119. {
  120. return $this->nbPassed;
  121. }
  122. /**
  123. * Returns the number of failed tests.
  124. *
  125. * @return integer
  126. */
  127. public function getNbFailures()
  128. {
  129. return count($this->failures);
  130. }
  131. /**
  132. * Returns the test failures.
  133. *
  134. * @return array
  135. */
  136. public function getFailures()
  137. {
  138. return $this->failures;
  139. }
  140. /**
  141. * Returns whether the test has any failures.
  142. *
  143. * @return boolean
  144. */
  145. public function hasFailures()
  146. {
  147. return $this->getNbFailures() > 0;
  148. }
  149. /**
  150. * Returns the number of test errors.
  151. *
  152. * @return integer
  153. */
  154. public function getNbErrors()
  155. {
  156. return count($this->errors);
  157. }
  158. /**
  159. * Returns the test errors.
  160. *
  161. * @return array
  162. */
  163. public function getErrors()
  164. {
  165. return $this->errors;
  166. }
  167. /**
  168. * Returns whether the test has any errors.
  169. *
  170. * @return boolean
  171. */
  172. public function hasErrors()
  173. {
  174. return $this->getNbErrors() > 0;
  175. }
  176. /**
  177. * Returns the number of test warnings.
  178. *
  179. * @return integer
  180. */
  181. public function getNbWarnings()
  182. {
  183. return count($this->warnings);
  184. }
  185. /**
  186. * Returns the test warnings.
  187. *
  188. * @return array
  189. */
  190. public function getWarnings()
  191. {
  192. return $this->warnings;
  193. }
  194. /**
  195. * Returns whether the test has any warnings.
  196. *
  197. * @return boolean
  198. */
  199. public function hasWarnings()
  200. {
  201. return $this->getNbWarnings() > 0;
  202. }
  203. /**
  204. * Returns the number of todos.
  205. *
  206. * @return integer
  207. */
  208. public function getNbTodos()
  209. {
  210. return count($this->todos);
  211. }
  212. /**
  213. * Returns the todos.
  214. *
  215. * @return integer
  216. */
  217. public function getTodos()
  218. {
  219. return $this->todos;
  220. }
  221. /**
  222. * Returns whether the test has any todos.
  223. *
  224. * @return boolean
  225. */
  226. public function hasTodos()
  227. {
  228. return $this->getNbTodos() > 0;
  229. }
  230. /**
  231. * Returns whether not all expected tests have been executed.
  232. *
  233. * @return boolean
  234. */
  235. public function isIncomplete()
  236. {
  237. return $this->nbExpected > 0 && $this->nbActual != $this->nbExpected;
  238. }
  239. /**
  240. * Returns whether the test has failed.
  241. *
  242. * A test is considered failed, if any test case failed, any error occurred
  243. * or the test is incomplete, i.e. not all expected tests have been executed.
  244. *
  245. * @return boolean
  246. */
  247. public function isFailed()
  248. {
  249. return $this->hasErrors() || $this->hasFailures() || $this->isIncomplete();
  250. }
  251. }