PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/application/libraries/PHPUnit/Util/Report/Node/Directory.php

https://github.com/grandison/budo16
PHP | 392 lines | 163 code | 56 blank | 173 comment | 13 complexity | e2f14c3b931e45372d1035e21ff64e96 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 3.2.0
  44. */
  45. require_once 'PHPUnit/Util/Filter.php';
  46. require_once 'PHPUnit/Util/Filesystem.php';
  47. require_once 'PHPUnit/Util/Template.php';
  48. require_once 'PHPUnit/Util/Report/Node.php';
  49. require_once 'PHPUnit/Util/Report/Node/File.php';
  50. PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
  51. /**
  52. * Represents a directory in the code coverage information tree.
  53. *
  54. * @category Testing
  55. * @package PHPUnit
  56. * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
  57. * @copyright 2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
  58. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  59. * @version Release: 3.4.15
  60. * @link http://www.phpunit.de/
  61. * @since Class available since Release 3.2.0
  62. */
  63. class PHPUnit_Util_Report_Node_Directory extends PHPUnit_Util_Report_Node
  64. {
  65. /**
  66. * @var PHPUnit_Util_Report_Node[]
  67. */
  68. protected $children = array();
  69. /**
  70. * @var PHPUnit_Util_Report_Node_Directory[]
  71. */
  72. protected $directories = array();
  73. /**
  74. * @var PHPUnit_Util_Report_Node_File[]
  75. */
  76. protected $files = array();
  77. /**
  78. * @var array
  79. */
  80. protected $classes;
  81. /**
  82. * @var integer
  83. */
  84. protected $numExecutableLines = -1;
  85. /**
  86. * @var integer
  87. */
  88. protected $numExecutedLines = -1;
  89. /**
  90. * @var integer
  91. */
  92. protected $numClasses = -1;
  93. /**
  94. * @var integer
  95. */
  96. protected $numTestedClasses = -1;
  97. /**
  98. * @var integer
  99. */
  100. protected $numMethods = -1;
  101. /**
  102. * @var integer
  103. */
  104. protected $numTestedMethods = -1;
  105. /**
  106. * Adds a new directory.
  107. *
  108. * @return PHPUnit_Util_Report_Node_Directory
  109. */
  110. public function addDirectory($name)
  111. {
  112. $directory = new PHPUnit_Util_Report_Node_Directory($name, $this);
  113. $this->children[] = $directory;
  114. $this->directories[] = &$this->children[count($this->children) - 1];
  115. return $directory;
  116. }
  117. /**
  118. * Adds a new file.
  119. *
  120. * @param string $name
  121. * @param array $lines
  122. * @param boolean $yui
  123. * @param boolean $highlight
  124. * @return PHPUnit_Util_Report_Node_File
  125. * @throws RuntimeException
  126. */
  127. public function addFile($name, array $lines, $yui, $highlight)
  128. {
  129. $file = new PHPUnit_Util_Report_Node_File(
  130. $name, $this, $lines, $yui, $highlight
  131. );
  132. $this->children[] = $file;
  133. $this->files[] = &$this->children[count($this->children) - 1];
  134. $this->numExecutableLines = -1;
  135. $this->numExecutedLines = -1;
  136. return $file;
  137. }
  138. /**
  139. * Returns the directories in this directory.
  140. *
  141. * @return array
  142. */
  143. public function getDirectories()
  144. {
  145. return $this->directories;
  146. }
  147. /**
  148. * Returns the files in this directory.
  149. *
  150. * @return array
  151. */
  152. public function getFiles()
  153. {
  154. return $this->files;
  155. }
  156. /**
  157. * Returns the classes of this node.
  158. *
  159. * @return array
  160. */
  161. public function getClasses()
  162. {
  163. if ($this->classes === NULL) {
  164. $this->classes = array();
  165. foreach ($this->children as $child) {
  166. $this->classes = array_merge($this->classes, $child->getClasses());
  167. }
  168. }
  169. return $this->classes;
  170. }
  171. /**
  172. * Returns the number of executable lines.
  173. *
  174. * @return integer
  175. */
  176. public function getNumExecutableLines()
  177. {
  178. if ($this->numExecutableLines == -1) {
  179. $this->numExecutableLines = 0;
  180. foreach ($this->children as $child) {
  181. $this->numExecutableLines += $child->getNumExecutableLines();
  182. }
  183. }
  184. return $this->numExecutableLines;
  185. }
  186. /**
  187. * Returns the number of executed lines.
  188. *
  189. * @return integer
  190. */
  191. public function getNumExecutedLines()
  192. {
  193. if ($this->numExecutedLines == -1) {
  194. $this->numExecutedLines = 0;
  195. foreach ($this->children as $child) {
  196. $this->numExecutedLines += $child->getNumExecutedLines();
  197. }
  198. }
  199. return $this->numExecutedLines;
  200. }
  201. /**
  202. * Returns the number of classes.
  203. *
  204. * @return integer
  205. */
  206. public function getNumClasses()
  207. {
  208. if ($this->numClasses == -1) {
  209. $this->numClasses = 0;
  210. foreach ($this->children as $child) {
  211. $this->numClasses += $child->getNumClasses();
  212. }
  213. }
  214. return $this->numClasses;
  215. }
  216. /**
  217. * Returns the number of tested classes.
  218. *
  219. * @return integer
  220. */
  221. public function getNumTestedClasses()
  222. {
  223. if ($this->numTestedClasses == -1) {
  224. $this->numTestedClasses = 0;
  225. foreach ($this->children as $child) {
  226. $this->numTestedClasses += $child->getNumTestedClasses();
  227. }
  228. }
  229. return $this->numTestedClasses;
  230. }
  231. /**
  232. * Returns the number of methods.
  233. *
  234. * @return integer
  235. */
  236. public function getNumMethods()
  237. {
  238. if ($this->numMethods == -1) {
  239. $this->numMethods = 0;
  240. foreach ($this->children as $child) {
  241. $this->numMethods += $child->getNumMethods();
  242. }
  243. }
  244. return $this->numMethods;
  245. }
  246. /**
  247. * Returns the number of tested methods.
  248. *
  249. * @return integer
  250. */
  251. public function getNumTestedMethods()
  252. {
  253. if ($this->numTestedMethods == -1) {
  254. $this->numTestedMethods = 0;
  255. foreach ($this->children as $child) {
  256. $this->numTestedMethods += $child->getNumTestedMethods();
  257. }
  258. }
  259. return $this->numTestedMethods;
  260. }
  261. /**
  262. * Renders this node.
  263. *
  264. * @param string $target
  265. * @param string $title
  266. * @param string $charset
  267. * @param integer $lowUpperBound
  268. * @param integer $highLowerBound
  269. */
  270. public function render($target, $title, $charset = 'ISO-8859-1', $lowUpperBound = 35, $highLowerBound = 70)
  271. {
  272. $this->doRender(
  273. $target, $title, $charset, $lowUpperBound, $highLowerBound
  274. );
  275. foreach ($this->children as $child) {
  276. $child->render(
  277. $target, $title, $charset, $lowUpperBound, $highLowerBound
  278. );
  279. }
  280. $this->children = array();
  281. }
  282. /**
  283. * @param string $target
  284. * @param string $title
  285. * @param string $charset
  286. * @param integer $lowUpperBound
  287. * @param integer $highLowerBound
  288. */
  289. protected function doRender($target, $title, $charset, $lowUpperBound, $highLowerBound)
  290. {
  291. $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
  292. $file = $target . $cleanId . '.html';
  293. $template = new PHPUnit_Util_Template(
  294. PHPUnit_Util_Report::$templatePath . 'directory.html'
  295. );
  296. $this->setTemplateVars($template, $title, $charset);
  297. $template->setVar(
  298. array(
  299. 'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound),
  300. 'items' => $this->renderItems($lowUpperBound, $highLowerBound),
  301. 'low_upper_bound' => $lowUpperBound,
  302. 'high_lower_bound' => $highLowerBound
  303. )
  304. );
  305. $template->renderTo($file);
  306. $this->directories = array();
  307. $this->files = array();
  308. }
  309. /**
  310. * @param float $lowUpperBound
  311. * @param float $highLowerBound
  312. * @return string
  313. */
  314. protected function renderItems($lowUpperBound, $highLowerBound)
  315. {
  316. $items = $this->doRenderItems($this->directories, $lowUpperBound, $highLowerBound, 'coverDirectory');
  317. $items .= $this->doRenderItems($this->files, $lowUpperBound, $highLowerBound, 'coverFile');
  318. return $items;
  319. }
  320. /**
  321. * @param array $items
  322. * @param float $lowUpperBound
  323. * @param float $highLowerBound
  324. * @param string $itemClass
  325. * @return string
  326. */
  327. protected function doRenderItems(array $items, $lowUpperBound, $highLowerBound, $itemClass)
  328. {
  329. $result = '';
  330. foreach ($items as $item) {
  331. $result .= $this->doRenderItemObject($item, $lowUpperBound, $highLowerBound, NULL, $itemClass);
  332. }
  333. return $result;
  334. }
  335. }
  336. ?>