PageRenderTime 59ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/mageekguy/atoum
PHP | 274 lines | 260 code | 14 blank | 0 comment | 0 complexity | c40440ea8baef580d390078556d9a307 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\report\fields\runner\tests\uncompleted;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\locale,
  6. mageekguy\atoum\cli\prompt,
  7. mageekguy\atoum\cli\colorizer,
  8. mageekguy\atoum\tests\units,
  9. mock\mageekguy\atoum as mock,
  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\uncompleted');
  18. }
  19. public function test__construct()
  20. {
  21. $this
  22. ->if($field = new tests\uncompleted\cli())
  23. ->then
  24. ->object($field->getTitlePrompt())->isEqualTo(new prompt())
  25. ->object($field->getTitleColorizer())->isEqualTo(new colorizer())
  26. ->object($field->getMethodPrompt())->isEqualTo(new prompt())
  27. ->object($field->getMethodColorizer())->isEqualTo(new colorizer())
  28. ->object($field->getOutputPrompt())->isEqualTo(new prompt())
  29. ->object($field->getOutputColorizer())->isEqualTo(new colorizer())
  30. ->object($field->getLocale())->isEqualTo(new locale())
  31. ->variable($field->getRunner())->isNull()
  32. ->array($field->getEvents())->isEqualTo(array(atoum\runner::runStop))
  33. ;
  34. }
  35. public function testSetTitlePrompt()
  36. {
  37. $this
  38. ->if($field = new tests\uncompleted\cli())
  39. ->then
  40. ->object($field->setTitlePrompt($prompt = new prompt(uniqid())))->isIdenticalTo($field)
  41. ->object($field->getTitlePrompt())->isIdenticalTo($prompt)
  42. ->object($field->setTitlePrompt())->isIdenticalTo($field)
  43. ->object($field->getTitlePrompt())
  44. ->isNotIdenticalTo($prompt)
  45. ->isEqualTo(new prompt())
  46. ;
  47. }
  48. public function testSetTitleColorizer()
  49. {
  50. $this
  51. ->if($field = new tests\uncompleted\cli())
  52. ->then
  53. ->object($field->setTitleColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  54. ->object($field->getTitleColorizer())->isIdenticalTo($colorizer)
  55. ->object($field->setTitleColorizer())->isIdenticalTo($field)
  56. ->object($field->getTitleColorizer())
  57. ->isNotIdenticalTo($colorizer)
  58. ->isEqualTo(new colorizer())
  59. ;
  60. }
  61. public function testSetMethodPrompt()
  62. {
  63. $this
  64. ->if($field = new tests\uncompleted\cli())
  65. ->then
  66. ->object($field->setMethodPrompt($prompt = new prompt(uniqid())))->isIdenticalTo($field)
  67. ->object($field->getMethodPrompt())->isIdenticalTo($prompt)
  68. ->object($field->setMethodPrompt())->isIdenticalTo($field)
  69. ->object($field->getMethodPrompt())
  70. ->isNotIdenticalTo($prompt)
  71. ->isEqualTo(new prompt())
  72. ;
  73. }
  74. public function testSetMethodColorizer()
  75. {
  76. $this
  77. ->if($field = new tests\uncompleted\cli())
  78. ->then
  79. ->object($field->setMethodColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  80. ->object($field->getMethodColorizer())->isIdenticalTo($colorizer)
  81. ->object($field->setMethodColorizer())->isIdenticalTo($field)
  82. ->object($field->getMethodColorizer())
  83. ->isNotIdenticalTo($colorizer)
  84. ->isEqualTo(new colorizer())
  85. ;
  86. }
  87. public function testSetOutputPrompt()
  88. {
  89. $this
  90. ->if($field = new tests\uncompleted\cli())
  91. ->then
  92. ->object($field->setOutputPrompt($prompt = new prompt(uniqid())))->isIdenticalTo($field)
  93. ->object($field->getOutputPrompt())->isIdenticalTo($prompt)
  94. ->object($field->setOutputPrompt())->isIdenticalTo($field)
  95. ->object($field->getOutputPrompt())
  96. ->isNotIdenticalTo($prompt)
  97. ->isEqualTo(new prompt())
  98. ;
  99. }
  100. public function testSetOutputColorizer()
  101. {
  102. $this
  103. ->if($field = new tests\uncompleted\cli())
  104. ->then
  105. ->object($field->setOutputColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  106. ->object($field->getOutputColorizer())->isIdenticalTo($colorizer)
  107. ->object($field->setOutputColorizer())->isIdenticalTo($field)
  108. ->object($field->getOutputColorizer())
  109. ->isNotIdenticalTo($colorizer)
  110. ->isEqualTo(new colorizer())
  111. ;
  112. }
  113. public function testSetLocale()
  114. {
  115. $this
  116. ->if($field = new tests\uncompleted\cli())
  117. ->then
  118. ->object($field->setLocale($locale = new atoum\locale()))->isIdenticalTo($field)
  119. ->object($field->getLocale())->isIdenticalTo($locale)
  120. ->if($field = new tests\uncompleted\cli(null, null, null, null, null, null, $locale = new atoum\locale()))
  121. ->then
  122. ->object($field->setLocale($locale = new atoum\locale()))->isIdenticalTo($field)
  123. ->object($field->getLocale())->isIdenticalTo($locale)
  124. ;
  125. }
  126. public function testHandleEvent()
  127. {
  128. $this
  129. ->if($field = new tests\uncompleted\cli())
  130. ->then
  131. ->boolean($field->handleEvent(atoum\runner::runStart, new atoum\runner()))->isFalse()
  132. ->variable($field->getRunner())->isNull()
  133. ->boolean($field->handleEvent(atoum\runner::runStop, $runner = new atoum\runner()))->isTrue()
  134. ->object($field->getRunner())->isIdenticalTo($runner)
  135. ;
  136. }
  137. public function test__toString()
  138. {
  139. $this
  140. ->if($score = new \mock\mageekguy\atoum\runner\score())
  141. ->and($this->calling($score)->getUncompletedMethods = array())
  142. ->and($runner = new atoum\runner())
  143. ->and($runner->setScore($score))
  144. ->and($defaultField = new tests\uncompleted\cli())
  145. ->and($customField = new tests\uncompleted\cli())
  146. ->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))
  147. ->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  148. ->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))
  149. ->and($customField->setMethodColorizer($methodColorizer = new colorizer(uniqid(), uniqid())))
  150. ->and($customField->setOutputPrompt($outputPrompt = new prompt(uniqid())))
  151. ->and($customField->setOutputColorizer($outputColorizer = new colorizer(uniqid(), uniqid())))
  152. ->and($customField->setLocale($locale = new atoum\locale()))
  153. ->then
  154. ->castToString($defaultField)->isEmpty()
  155. ->castToString($customField)->isEmpty()
  156. ->if($defaultField->handleEvent(atoum\runner::runStart, $runner))
  157. ->then
  158. ->castToString($defaultField)->isEmpty()
  159. ->if($customField->handleEvent(atoum\runner::runStart, $runner))
  160. ->then
  161. ->castToString($customField)->isEmpty()
  162. ->if($defaultField->handleEvent(atoum\runner::runStop, $runner))
  163. ->then
  164. ->castToString($defaultField)->isEmpty()
  165. ->if($customField->handleEvent(atoum\runner::runStop, $runner))
  166. ->then
  167. ->castToString($customField)->isEmpty()
  168. ->if($score->getMockController()->getUncompletedMethods = $allUncompletedMethods = array(
  169. array(
  170. 'class' => $class = uniqid(),
  171. 'method' => $method = uniqid(),
  172. 'exitCode' => $exitCode = rand(1, PHP_INT_MAX),
  173. 'output' => $output = uniqid()
  174. ),
  175. array(
  176. 'class' => $otherClass = uniqid(),
  177. 'method' => $otherMethod = uniqid(),
  178. 'exitCode' => $otherExitCode = rand(1, PHP_INT_MAX),
  179. 'output' => ($otherOutputLine1 = uniqid()) . PHP_EOL . ($otherOutputLine2 = uniqid())
  180. ),
  181. array(
  182. 'class' => $anotherClass = uniqid(),
  183. 'method' => $anotherMethod = uniqid(),
  184. 'exitCode' => $anotherExitCode = rand(1, PHP_INT_MAX),
  185. 'output' => ''
  186. )
  187. )
  188. )
  189. ->and($defaultField = new tests\uncompleted\cli())
  190. ->and($customField = new tests\uncompleted\cli())
  191. ->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))
  192. ->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  193. ->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))
  194. ->and($customField->setMethodColorizer($methodColorizer = new colorizer(uniqid(), uniqid())))
  195. ->and($customField->setOutputPrompt($outputPrompt = new prompt(uniqid())))
  196. ->and($customField->setOutputColorizer($outputColorizer = new colorizer(uniqid(), uniqid())))
  197. ->and($customField->setLocale($locale = new atoum\locale()))
  198. ->then
  199. ->castToString($defaultField)->isEmpty()
  200. ->castToString($customField)->isEmpty()
  201. ->if($defaultField->handleEvent(atoum\runner::runStart, $runner))
  202. ->then
  203. ->castToString($defaultField)->isEmpty()
  204. ->if($customField->handleEvent(atoum\runner::runStart, $runner))
  205. ->then
  206. ->castToString($customField)->isEmpty()
  207. ->if($defaultField->handleEvent(atoum\runner::runStop, $runner))
  208. ->then
  209. ->castToString($defaultField)->isEqualTo(sprintf('There are %d uncompleted methods:', sizeof($allUncompletedMethods)) . PHP_EOL .
  210. sprintf('%s::%s() with exit code %d:', $class, $method, $exitCode) . PHP_EOL .
  211. 'output(' . strlen($output) . ') "' . $output . '"' . PHP_EOL .
  212. sprintf('%s::%s() with exit code %d:', $otherClass, $otherMethod, $otherExitCode) . PHP_EOL .
  213. 'output(' . (strlen($otherOutputLine1 . PHP_EOL . $otherOutputLine2)) . ') "' . $otherOutputLine1 . PHP_EOL .
  214. $otherOutputLine2 . '"' . PHP_EOL .
  215. sprintf('%s::%s() with exit code %d:', $anotherClass, $anotherMethod, $anotherExitCode) . PHP_EOL .
  216. 'output(0) ""' . PHP_EOL
  217. )
  218. ->if($customField->handleEvent(atoum\runner::runStop, $runner))
  219. ->then
  220. ->castToString($customField)->isEqualTo(
  221. $titlePrompt .
  222. sprintf(
  223. $locale->_('%s:'),
  224. $titleColorizer->colorize(sprintf($locale->__('There is %d uncompleted method', 'There are %d uncompleted methods', sizeof($allUncompletedMethods)), sizeof($allUncompletedMethods)))
  225. ) .
  226. PHP_EOL .
  227. $methodPrompt .
  228. sprintf(
  229. $locale->_('%s:'),
  230. $methodColorizer->colorize(sprintf('%s::%s() with exit code %d', $class, $method, $exitCode))
  231. ) .
  232. PHP_EOL .
  233. $outputPrompt .
  234. 'output(' . strlen($output) . ') "' . $output . '"' .
  235. PHP_EOL .
  236. $methodPrompt .
  237. sprintf(
  238. $locale->_('%s:'),
  239. $methodColorizer->colorize(sprintf('%s::%s() with exit code %d', $otherClass, $otherMethod, $otherExitCode))
  240. ) .
  241. PHP_EOL .
  242. $outputPrompt .
  243. 'output(' . (strlen($otherOutputLine1 . PHP_EOL . $otherOutputLine2)) . ') "' . $otherOutputLine1 .
  244. PHP_EOL .
  245. $outputPrompt .
  246. $otherOutputLine2 . '"' .
  247. PHP_EOL .
  248. $methodPrompt .
  249. sprintf(
  250. $locale->_('%s:'),
  251. $methodColorizer->colorize(sprintf('%s::%s() with exit code %d', $anotherClass, $anotherMethod, $anotherExitCode))
  252. ) .
  253. PHP_EOL .
  254. $outputPrompt .
  255. 'output(0) ""' .
  256. PHP_EOL
  257. )
  258. ;
  259. }
  260. }