PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/qcodo/_core/PHPUnit/Util/TestDox/ResultPrinter.php

https://github.com/allanfreitas/qcodo
PHP | 338 lines | 139 code | 37 blank | 162 comment | 22 complexity | db5d9b5364a0f1f986ff3fa8b92ff695 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.11
  59. * @link http://www.phpunit.de/
  60. * @since Class available since Release 2.1.0
  61. * @abstract
  62. */
  63. abstract class PHPUnit_Util_TestDox_ResultPrinter extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
  64. {
  65. /**
  66. * @var PHPUnit_Util_TestDox_NamePrettifier
  67. */
  68. protected $prettifier;
  69. /**
  70. * @var string
  71. */
  72. protected $testClass = '';
  73. /**
  74. * @var integer
  75. */
  76. protected $testStatus = FALSE;
  77. /**
  78. * @var array
  79. */
  80. protected $tests = array();
  81. protected $successful = 0;
  82. protected $failed = 0;
  83. protected $skipped = 0;
  84. protected $incomplete = 0;
  85. protected $testTypeOfInterest = 'PHPUnit_Framework_TestCase';
  86. /**
  87. * @var string
  88. */
  89. protected $currentTestClassPrettified;
  90. /**
  91. * @var string
  92. */
  93. protected $currentTestMethodPrettified;
  94. /**
  95. * Constructor.
  96. *
  97. * @param resource $out
  98. */
  99. public function __construct($out = NULL)
  100. {
  101. parent::__construct($out);
  102. $this->prettifier = new PHPUnit_Util_TestDox_NamePrettifier;
  103. $this->startRun();
  104. }
  105. /**
  106. * Flush buffer and close output.
  107. *
  108. */
  109. public function flush()
  110. {
  111. $this->doEndClass();
  112. $this->endRun();
  113. parent::flush();
  114. }
  115. /**
  116. * An error occurred.
  117. *
  118. * @param PHPUnit_Framework_Test $test
  119. * @param Exception $e
  120. * @param float $time
  121. */
  122. public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
  123. {
  124. if ($test instanceof $this->testTypeOfInterest) {
  125. $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR;
  126. $this->failed++;
  127. }
  128. }
  129. /**
  130. * A failure occurred.
  131. *
  132. * @param PHPUnit_Framework_Test $test
  133. * @param PHPUnit_Framework_AssertionFailedError $e
  134. * @param float $time
  135. */
  136. public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
  137. {
  138. if ($test instanceof $this->testTypeOfInterest) {
  139. $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE;
  140. $this->failed++;
  141. }
  142. }
  143. /**
  144. * Incomplete test.
  145. *
  146. * @param PHPUnit_Framework_Test $test
  147. * @param Exception $e
  148. * @param float $time
  149. */
  150. public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
  151. {
  152. if ($test instanceof $this->testTypeOfInterest) {
  153. $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE;
  154. $this->incomplete++;
  155. }
  156. }
  157. /**
  158. * Skipped test.
  159. *
  160. * @param PHPUnit_Framework_Test $test
  161. * @param Exception $e
  162. * @param float $time
  163. * @since Method available since Release 3.0.0
  164. */
  165. public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
  166. {
  167. if ($test instanceof $this->testTypeOfInterest) {
  168. $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED;
  169. $this->skipped++;
  170. }
  171. }
  172. /**
  173. * A testsuite started.
  174. *
  175. * @param PHPUnit_Framework_TestSuite $suite
  176. * @since Method available since Release 2.2.0
  177. */
  178. public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
  179. {
  180. }
  181. /**
  182. * A testsuite ended.
  183. *
  184. * @param PHPUnit_Framework_TestSuite $suite
  185. * @since Method available since Release 2.2.0
  186. */
  187. public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
  188. {
  189. }
  190. /**
  191. * A test started.
  192. *
  193. * @param PHPUnit_Framework_Test $test
  194. */
  195. public function startTest(PHPUnit_Framework_Test $test)
  196. {
  197. if ($test instanceof $this->testTypeOfInterest) {
  198. $class = get_class($test);
  199. if ($this->testClass != $class) {
  200. if ($this->testClass != '') {
  201. $this->doEndClass();
  202. }
  203. $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
  204. $this->startClass($class);
  205. $this->testClass = $class;
  206. $this->tests = array();
  207. }
  208. $prettified = FALSE;
  209. if ($test instanceof PHPUnit_Framework_TestCase &&
  210. !$test instanceof PHPUnit_Framework_Warning) {
  211. $annotations = $test->getAnnotations();
  212. if (isset($annotations['method']['testdox'][0])) {
  213. $this->currentTestMethodPrettified = $annotations['method']['testdox'][0];
  214. $prettified = TRUE;
  215. }
  216. }
  217. if (!$prettified) {
  218. $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(FALSE));
  219. }
  220. $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
  221. }
  222. }
  223. /**
  224. * A test ended.
  225. *
  226. * @param PHPUnit_Framework_Test $test
  227. * @param float $time
  228. */
  229. public function endTest(PHPUnit_Framework_Test $test, $time)
  230. {
  231. if ($test instanceof $this->testTypeOfInterest) {
  232. if (!isset($this->tests[$this->currentTestMethodPrettified])) {
  233. if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
  234. $this->tests[$this->currentTestMethodPrettified]['success'] = 1;
  235. $this->tests[$this->currentTestMethodPrettified]['failure'] = 0;
  236. } else {
  237. $this->tests[$this->currentTestMethodPrettified]['success'] = 0;
  238. $this->tests[$this->currentTestMethodPrettified]['failure'] = 1;
  239. }
  240. } else {
  241. if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
  242. $this->tests[$this->currentTestMethodPrettified]['success']++;
  243. } else {
  244. $this->tests[$this->currentTestMethodPrettified]['failure']++;
  245. }
  246. }
  247. $this->currentTestClassPrettified = NULL;
  248. $this->currentTestMethodPrettified = NULL;
  249. }
  250. }
  251. /**
  252. * @since Method available since Release 2.3.0
  253. */
  254. protected function doEndClass()
  255. {
  256. foreach ($this->tests as $name => $data) {
  257. $this->onTest($name, $data['failure'] == 0);
  258. }
  259. $this->endClass($this->testClass);
  260. }
  261. /**
  262. * Handler for 'start run' event.
  263. *
  264. */
  265. protected function startRun()
  266. {
  267. }
  268. /**
  269. * Handler for 'start class' event.
  270. *
  271. * @param string $name
  272. */
  273. protected function startClass($name)
  274. {
  275. }
  276. /**
  277. * Handler for 'on test' event.
  278. *
  279. * @param string $name
  280. * @param boolean $success
  281. */
  282. protected function onTest($name, $success = TRUE)
  283. {
  284. }
  285. /**
  286. * Handler for 'end class' event.
  287. *
  288. * @param string $name
  289. */
  290. protected function endClass($name)
  291. {
  292. }
  293. /**
  294. * Handler for 'end run' event.
  295. *
  296. */
  297. protected function endRun()
  298. {
  299. }
  300. }
  301. ?>