PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/application/libraries/PHPUnit/Util/TestDox/ResultPrinter.php

https://github.com/grandison/budo16
PHP | 337 lines | 139 code | 37 blank | 161 comment | 22 complexity | 61d4bda1cd9939c33e3fa09da9fb2032 MD5 | raw file
  1. <?php
  2. /**
  3. * PHPUnit
  4. *
  5. * Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * * Neither the name of Sebastian Bergmann nor the names of his
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  34. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. * @category Testing
  38. * @package PHPUnit
  39. * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
  40. * @copyright 2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
  41. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  42. * @link http://www.phpunit.de/
  43. * @since File available since Release 2.3.0
  44. */
  45. require_once 'PHPUnit/Framework.php';
  46. require_once 'PHPUnit/Util/Filter.php';
  47. require_once 'PHPUnit/Util/TestDox/NamePrettifier.php';
  48. require_once 'PHPUnit/Util/Printer.php';
  49. PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
  50. /**
  51. * Base class for printers of TestDox documentation.
  52. *
  53. * @category Testing
  54. * @package PHPUnit
  55. * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
  56. * @copyright 2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
  57. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  58. * @version Release: 3.4.15
  59. * @link http://www.phpunit.de/
  60. * @since Class available since Release 2.1.0
  61. */
  62. abstract class PHPUnit_Util_TestDox_ResultPrinter extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
  63. {
  64. /**
  65. * @var PHPUnit_Util_TestDox_NamePrettifier
  66. */
  67. protected $prettifier;
  68. /**
  69. * @var string
  70. */
  71. protected $testClass = '';
  72. /**
  73. * @var integer
  74. */
  75. protected $testStatus = FALSE;
  76. /**
  77. * @var array
  78. */
  79. protected $tests = array();
  80. protected $successful = 0;
  81. protected $failed = 0;
  82. protected $skipped = 0;
  83. protected $incomplete = 0;
  84. protected $testTypeOfInterest = 'PHPUnit_Framework_TestCase';
  85. /**
  86. * @var string
  87. */
  88. protected $currentTestClassPrettified;
  89. /**
  90. * @var string
  91. */
  92. protected $currentTestMethodPrettified;
  93. /**
  94. * Constructor.
  95. *
  96. * @param resource $out
  97. */
  98. public function __construct($out = NULL)
  99. {
  100. parent::__construct($out);
  101. $this->prettifier = new PHPUnit_Util_TestDox_NamePrettifier;
  102. $this->startRun();
  103. }
  104. /**
  105. * Flush buffer and close output.
  106. *
  107. */
  108. public function flush()
  109. {
  110. $this->doEndClass();
  111. $this->endRun();
  112. parent::flush();
  113. }
  114. /**
  115. * An error occurred.
  116. *
  117. * @param PHPUnit_Framework_Test $test
  118. * @param Exception $e
  119. * @param float $time
  120. */
  121. public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
  122. {
  123. if ($test instanceof $this->testTypeOfInterest) {
  124. $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR;
  125. $this->failed++;
  126. }
  127. }
  128. /**
  129. * A failure occurred.
  130. *
  131. * @param PHPUnit_Framework_Test $test
  132. * @param PHPUnit_Framework_AssertionFailedError $e
  133. * @param float $time
  134. */
  135. public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
  136. {
  137. if ($test instanceof $this->testTypeOfInterest) {
  138. $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE;
  139. $this->failed++;
  140. }
  141. }
  142. /**
  143. * Incomplete test.
  144. *
  145. * @param PHPUnit_Framework_Test $test
  146. * @param Exception $e
  147. * @param float $time
  148. */
  149. public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
  150. {
  151. if ($test instanceof $this->testTypeOfInterest) {
  152. $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE;
  153. $this->incomplete++;
  154. }
  155. }
  156. /**
  157. * Skipped test.
  158. *
  159. * @param PHPUnit_Framework_Test $test
  160. * @param Exception $e
  161. * @param float $time
  162. * @since Method available since Release 3.0.0
  163. */
  164. public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
  165. {
  166. if ($test instanceof $this->testTypeOfInterest) {
  167. $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED;
  168. $this->skipped++;
  169. }
  170. }
  171. /**
  172. * A testsuite started.
  173. *
  174. * @param PHPUnit_Framework_TestSuite $suite
  175. * @since Method available since Release 2.2.0
  176. */
  177. public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
  178. {
  179. }
  180. /**
  181. * A testsuite ended.
  182. *
  183. * @param PHPUnit_Framework_TestSuite $suite
  184. * @since Method available since Release 2.2.0
  185. */
  186. public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
  187. {
  188. }
  189. /**
  190. * A test started.
  191. *
  192. * @param PHPUnit_Framework_Test $test
  193. */
  194. public function startTest(PHPUnit_Framework_Test $test)
  195. {
  196. if ($test instanceof $this->testTypeOfInterest) {
  197. $class = get_class($test);
  198. if ($this->testClass != $class) {
  199. if ($this->testClass != '') {
  200. $this->doEndClass();
  201. }
  202. $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
  203. $this->startClass($class);
  204. $this->testClass = $class;
  205. $this->tests = array();
  206. }
  207. $prettified = FALSE;
  208. if ($test instanceof PHPUnit_Framework_TestCase &&
  209. !$test instanceof PHPUnit_Framework_Warning) {
  210. $annotations = $test->getAnnotations();
  211. if (isset($annotations['method']['testdox'][0])) {
  212. $this->currentTestMethodPrettified = $annotations['method']['testdox'][0];
  213. $prettified = TRUE;
  214. }
  215. }
  216. if (!$prettified) {
  217. $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(FALSE));
  218. }
  219. $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
  220. }
  221. }
  222. /**
  223. * A test ended.
  224. *
  225. * @param PHPUnit_Framework_Test $test
  226. * @param float $time
  227. */
  228. public function endTest(PHPUnit_Framework_Test $test, $time)
  229. {
  230. if ($test instanceof $this->testTypeOfInterest) {
  231. if (!isset($this->tests[$this->currentTestMethodPrettified])) {
  232. if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
  233. $this->tests[$this->currentTestMethodPrettified]['success'] = 1;
  234. $this->tests[$this->currentTestMethodPrettified]['failure'] = 0;
  235. } else {
  236. $this->tests[$this->currentTestMethodPrettified]['success'] = 0;
  237. $this->tests[$this->currentTestMethodPrettified]['failure'] = 1;
  238. }
  239. } else {
  240. if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
  241. $this->tests[$this->currentTestMethodPrettified]['success']++;
  242. } else {
  243. $this->tests[$this->currentTestMethodPrettified]['failure']++;
  244. }
  245. }
  246. $this->currentTestClassPrettified = NULL;
  247. $this->currentTestMethodPrettified = NULL;
  248. }
  249. }
  250. /**
  251. * @since Method available since Release 2.3.0
  252. */
  253. protected function doEndClass()
  254. {
  255. foreach ($this->tests as $name => $data) {
  256. $this->onTest($name, $data['failure'] == 0);
  257. }
  258. $this->endClass($this->testClass);
  259. }
  260. /**
  261. * Handler for 'start run' event.
  262. *
  263. */
  264. protected function startRun()
  265. {
  266. }
  267. /**
  268. * Handler for 'start class' event.
  269. *
  270. * @param string $name
  271. */
  272. protected function startClass($name)
  273. {
  274. }
  275. /**
  276. * Handler for 'on test' event.
  277. *
  278. * @param string $name
  279. * @param boolean $success
  280. */
  281. protected function onTest($name, $success = TRUE)
  282. {
  283. }
  284. /**
  285. * Handler for 'end class' event.
  286. *
  287. * @param string $name
  288. */
  289. protected function endClass($name)
  290. {
  291. }
  292. /**
  293. * Handler for 'end run' event.
  294. *
  295. */
  296. protected function endRun()
  297. {
  298. }
  299. }
  300. ?>