PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/units/classes/report/fields/runner/tests/coverage/cli.php

http://github.com/mageekguy/atoum
PHP | 241 lines | 229 code | 12 blank | 0 comment | 0 complexity | eb0ffbf8fea4ad3a3b315de297f2152c MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\report\fields\runner\tests\coverage;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\mock,
  6. mageekguy\atoum\score,
  7. mageekguy\atoum\locale,
  8. mageekguy\atoum\cli\prompt,
  9. mageekguy\atoum\cli\colorizer,
  10. mageekguy\atoum\report\fields\runner\tests
  11. ;
  12. require_once __DIR__ . '/../../../../../../runner.php';
  13. class cli extends atoum\test
  14. {
  15. public function testClass()
  16. {
  17. $this->testedClass->extends('mageekguy\atoum\report\fields\runner\tests\coverage');
  18. }
  19. public function test__construct()
  20. {
  21. $this
  22. ->if($field = new tests\coverage\cli())
  23. ->then
  24. ->object($field->getTitlePrompt())->isEqualTo(new prompt())
  25. ->object($field->getClassPrompt())->isEqualTo(new prompt())
  26. ->object($field->getMethodPrompt())->isEqualTo(new prompt())
  27. ->object($field->getTitleColorizer())->isEqualTo(new colorizer())
  28. ->object($field->getCoverageColorizer())->isEqualTo(new colorizer())
  29. ->object($field->getLocale())->isEqualTo(new locale())
  30. ->variable($field->getCoverage())->isNull()
  31. ->array($field->getEvents())->isEqualTo(array(atoum\runner::runStop))
  32. ;
  33. }
  34. public function testSetTitlePrompt()
  35. {
  36. $this
  37. ->if($field = new tests\coverage\cli())
  38. ->then
  39. ->object($field->setTitlePrompt($prompt = new prompt()))->isIdenticalTo($field)
  40. ->object($field->getTitlePrompt())->isEqualTo($prompt)
  41. ->object($field->setTitlePrompt())->isIdenticalTo($field)
  42. ->object($field->getTitlePrompt())
  43. ->isNotIdenticalTo($prompt)
  44. ->isEqualTo(new prompt())
  45. ;
  46. }
  47. public function testSetClassPrompt()
  48. {
  49. $this
  50. ->if($field = new tests\coverage\cli())
  51. ->then
  52. ->object($field->setClassPrompt($prompt = new prompt()))->isIdenticalTo($field)
  53. ->object($field->getClassPrompt())->isEqualTo($prompt)
  54. ->object($field->setClassPrompt())->isIdenticalTo($field)
  55. ->object($field->getClassPrompt())
  56. ->isNotIdenticalTo($prompt)
  57. ->isEqualTo(new prompt())
  58. ;
  59. }
  60. public function testSetMethodPrompt()
  61. {
  62. $this
  63. ->if($field = new tests\coverage\cli())
  64. ->then
  65. ->object($field->setMethodPrompt($prompt = new prompt()))->isIdenticalTo($field)
  66. ->object($field->getMethodPrompt())->isEqualTo($prompt)
  67. ->object($field->setMethodPrompt())->isIdenticalTo($field)
  68. ->object($field->getMethodPrompt())
  69. ->isNotIdenticalTo($prompt)
  70. ->isEqualTo(new prompt())
  71. ;
  72. }
  73. public function testSetTitleColorizer()
  74. {
  75. $this
  76. ->if($field = new tests\coverage\cli())
  77. ->then
  78. ->object($field->setTitleColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  79. ->object($field->getTitleColorizer())->isIdenticalTo($colorizer)
  80. ->object($field->setTitleColorizer())->isIdenticalTo($field)
  81. ->object($field->getTitleColorizer())
  82. ->isNotIdenticalTo($colorizer)
  83. ->isEqualTo(new colorizer())
  84. ;
  85. }
  86. public function testSetTitleCoverageColorizer()
  87. {
  88. $this
  89. ->if($field = new tests\coverage\cli())
  90. ->then
  91. ->object($field->setCoverageColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  92. ->object($field->getCoverageColorizer())->isIdenticalTo($colorizer)
  93. ->object($field->setCoverageColorizer())->isIdenticalTo($field)
  94. ->object($field->getCoverageColorizer())
  95. ->isNotIdenticalTo($colorizer)
  96. ->isEqualTo(new colorizer())
  97. ;
  98. }
  99. public function testHandleEvent()
  100. {
  101. $this
  102. ->if($field = new tests\coverage\cli())
  103. ->then
  104. ->boolean($field->handleEvent(atoum\runner::runStart, new atoum\runner()))->isFalse()
  105. ->variable($field->getCoverage())->isNull()
  106. ->boolean($field->handleEvent(atoum\runner::runStop, $runner = new atoum\runner()))->isTrue()
  107. ->object($field->getCoverage())->isIdenticalTo($runner->getScore()->getCoverage())
  108. ;
  109. }
  110. public function test__toString()
  111. {
  112. $this
  113. ->if($scoreCoverage = new score\coverage())
  114. ->and($score = new \mock\mageekguy\atoum\runner\score())
  115. ->and($score->getMockController()->getCoverage = function() use ($scoreCoverage) { return $scoreCoverage; })
  116. ->and($runner = new atoum\runner())
  117. ->and($runner->setScore($score))
  118. ->and($defaultField = new tests\coverage\cli())
  119. ->and($customField = new tests\coverage\cli())
  120. ->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))
  121. ->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  122. ->and($customField->setClassPrompt($classPrompt = new prompt(uniqid())))
  123. ->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))
  124. ->and($customField->setCoverageColorizer($coverageColorizer = new colorizer(uniqid(), uniqid())))
  125. ->and($customField->setLocale($locale = new locale()))
  126. ->then
  127. ->castToString($defaultField)->isEmpty()
  128. ->castToString($customField)->isEmpty()
  129. ->if($defaultField->handleEvent(atoum\runner::runStart, $runner))
  130. ->and($customField->handleEvent(atoum\runner::runStart, $runner))
  131. ->then
  132. ->castToString($defaultField)->isEmpty()
  133. ->castToString($customField)->isEmpty()
  134. ->if($defaultField->handleEvent(atoum\runner::runStop, $runner))
  135. ->and($customField->handleEvent(atoum\runner::runStop, $runner))
  136. ->then
  137. ->castToString($defaultField)->isEmpty()
  138. ->castToString($customField)->isEmpty()
  139. ->if($classController = new mock\controller())
  140. ->and($classController->disableMethodChecking())
  141. ->and($classController->__construct = function() {})
  142. ->and($classController->getName = function() use (& $className) { return $className; })
  143. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  144. ->and($classController->getTraits = array())
  145. ->and($classController->getStartLine = 1)
  146. ->and($classController->getEndLine = 12)
  147. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  148. ->and($methodController = new mock\controller())
  149. ->and($methodController->__construct = function() {})
  150. ->and($methodController->isAbstract = false)
  151. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  152. ->and($methodController->getDeclaringClass = $class)
  153. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  154. ->and($methodController->getStartLine = 6)
  155. ->and($methodController->getEndLine = 8)
  156. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  157. ->and($className = uniqid())
  158. ->and($methodName = uniqid())
  159. ->and($scoreCoverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  160. ->and($scoreCoverage->addXdebugDataForTest($this, $xdebugData = array(
  161. ($classFile = uniqid()) =>
  162. array(
  163. 5 => 1,
  164. 6 => 2,
  165. 7 => 3,
  166. 8 => 2,
  167. 9 => 1
  168. ),
  169. uniqid() =>
  170. array(
  171. 5 => 2,
  172. 6 => 3,
  173. 7 => 4,
  174. 8 => 3,
  175. 9 => 2
  176. )
  177. )
  178. )
  179. )
  180. ->and($defaultField = new tests\coverage\cli())
  181. ->and($customField = new tests\coverage\cli())
  182. ->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))
  183. ->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  184. ->and($customField->setClassPrompt($classPrompt = new prompt(uniqid())))
  185. ->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))
  186. ->and($customField->setCoverageColorizer($coverageColorizer = new colorizer(uniqid(), uniqid())))
  187. ->and($customField->setLocale($locale = new locale()))
  188. ->then
  189. ->castToString($defaultField)->isEmpty()
  190. ->castToString($customField)->isEmpty()
  191. ->if($defaultField->handleEvent(atoum\runner::runStart, $runner))
  192. ->and($customField->handleEvent(atoum\runner::runStart, $runner))
  193. ->then
  194. ->castToString($defaultField)->isEmpty()
  195. ->castToString($customField)->isEmpty()
  196. ->if($defaultField->handleEvent(atoum\runner::runStop, $runner))
  197. ->and($customField->handleEvent(atoum\runner::runStop, $runner))
  198. ->then
  199. ->castToString($defaultField)->isEqualTo(
  200. $defaultField->getTitlePrompt() . sprintf($defaultField->getLocale()->_('Code coverage value: %3.2f%%'), $scoreCoverage->getValue() * 100) . PHP_EOL .
  201. $defaultField->getClassPrompt() . sprintf($defaultField->getLocale()->_('Class %s: %3.2f%%'), $className, $scoreCoverage->getValueForClass($className) * 100.0) . PHP_EOL .
  202. $defaultField->getMethodPrompt() . sprintf($defaultField->getLocale()->_('%s::%s(): %3.2f%%'), $className, $methodName, $scoreCoverage->getValueForMethod($className, $methodName) * 100.0) . PHP_EOL
  203. )
  204. ->castToString($customField)->isEqualTo(
  205. $titlePrompt .
  206. sprintf(
  207. $locale->_('%s: %s'),
  208. $titleColorizer->colorize($locale->_('Code coverage value')),
  209. $coverageColorizer->colorize(sprintf('%3.2f%%', $scoreCoverage->getValue() * 100.0))
  210. ) .
  211. PHP_EOL .
  212. $classPrompt .
  213. sprintf(
  214. $locale->_('%s: %s'),
  215. $titleColorizer->colorize(sprintf($locale->_('Class %s'), $className)),
  216. $coverageColorizer->colorize(sprintf('%3.2f%%', $scoreCoverage->getValueForClass($className) * 100.0))
  217. ) .
  218. PHP_EOL .
  219. $methodPrompt .
  220. sprintf(
  221. $locale->_('%s: %s'),
  222. $titleColorizer->colorize(sprintf($locale->_('%s::%s()'), $className, $methodName)),
  223. $coverageColorizer->colorize(sprintf('%3.2f%%', $scoreCoverage->getValueForClass($className, $methodName) * 100.0))
  224. ) .
  225. PHP_EOL
  226. )
  227. ;
  228. }
  229. }