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

http://github.com/mageekguy/atoum · PHP · 240 lines · 227 code · 13 blank · 0 comment · 0 complexity · dee82b6417f702e789e7885b1b659208 MD5 · raw file

  1. <?php
  2. namespace mageekguy\atoum\tests\units\report\fields\runner\exceptions;
  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. mageekguy\atoum\report\fields\runner
  10. ;
  11. require_once __DIR__ . '/../../../../../runner.php';
  12. class cli extends atoum\test
  13. {
  14. public function testClass()
  15. {
  16. $this->testedClass->extends('mageekguy\atoum\report\fields\runner\exceptions');
  17. }
  18. public function test__construct()
  19. {
  20. $this
  21. ->if($field = new runner\exceptions\cli())
  22. ->then
  23. ->object($field->getTitlePrompt())->isEqualTo(new prompt())
  24. ->object($field->getTitleColorizer())->isEqualTo(new colorizer())
  25. ->object($field->getMethodPrompt())->isEqualTo(new prompt())
  26. ->object($field->getMethodColorizer())->isEqualTo(new colorizer())
  27. ->object($field->getExceptionPrompt())->isEqualTo(new prompt())
  28. ->object($field->getExceptionColorizer())->isEqualTo(new colorizer())
  29. ->object($field->getLocale())->isEqualTo(new locale())
  30. ->variable($field->getRunner())->isNull()
  31. ->array($field->getEvents())->isEqualTo(array(atoum\runner::runStop))
  32. ;
  33. }
  34. public function testSetTitlePrompt()
  35. {
  36. $this
  37. ->if($field = new runner\exceptions\cli())
  38. ->then
  39. ->object($field->setTitlePrompt($prompt = new prompt(uniqid())))->isIdenticalTo($field)
  40. ->object($field->getTitlePrompt())->isIdenticalTo($prompt)
  41. ->object($field->setTitlePrompt())->isIdenticalTo($field)
  42. ->object($field->getTitlePrompt())
  43. ->isNotIdenticalTo($prompt)
  44. ->isEqualTo(new prompt())
  45. ;
  46. }
  47. public function testSetTitleColorizer()
  48. {
  49. $this
  50. ->if($field = new runner\exceptions\cli())
  51. ->then
  52. ->object($field->setTitleColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  53. ->object($field->getTitleColorizer())->isIdenticalTo($colorizer)
  54. ->object($field->setTitleColorizer())->isIdenticalTo($field)
  55. ->object($field->getTitleColorizer())
  56. ->isNotIdenticalTo($colorizer)
  57. ->isEqualTo(new colorizer())
  58. ;
  59. }
  60. public function testSetMethodPrompt()
  61. {
  62. $this
  63. ->if($field = new runner\exceptions\cli())
  64. ->then
  65. ->object($field->setMethodPrompt($prompt = new prompt(uniqid())))->isIdenticalTo($field)
  66. ->object($field->getMethodPrompt())->isIdenticalTo($prompt)
  67. ->object($field->setMethodPrompt())->isIdenticalTo($field)
  68. ->object($field->getTitlePrompt())
  69. ->isNotIdenticalTo($prompt)
  70. ->isEqualTo(new prompt())
  71. ;
  72. }
  73. public function testSetMethodColorizer()
  74. {
  75. $this
  76. ->if($field = new runner\exceptions\cli())
  77. ->then
  78. ->object($field->setMethodColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  79. ->object($field->getMethodColorizer())->isIdenticalTo($colorizer)
  80. ->object($field->setMethodColorizer())->isIdenticalTo($field)
  81. ->object($field->getTitleColorizer())
  82. ->isNotIdenticalTo($colorizer)
  83. ->isEqualTo(new colorizer())
  84. ;
  85. }
  86. public function testSetExceptionPrompt()
  87. {
  88. $this
  89. ->if($field = new runner\exceptions\cli())
  90. ->then
  91. ->object($field->setExceptionPrompt($prompt = new prompt(uniqid())))->isIdenticalTo($field)
  92. ->object($field->getExceptionPrompt())->isIdenticalTo($prompt)
  93. ->object($field->setExceptionPrompt())->isIdenticalTo($field)
  94. ->object($field->getTitlePrompt())
  95. ->isNotIdenticalTo($prompt)
  96. ->isEqualTo(new prompt())
  97. ;
  98. }
  99. public function testSetExceptionColorizer()
  100. {
  101. $this
  102. ->if($field = new runner\exceptions\cli())
  103. ->then
  104. ->object($field->setExceptionColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  105. ->object($field->getExceptionColorizer())->isIdenticalTo($colorizer)
  106. ->object($field->setExceptionColorizer())->isIdenticalTo($field)
  107. ->object($field->getTitleColorizer())
  108. ->isNotIdenticalTo($colorizer)
  109. ->isEqualTo(new colorizer())
  110. ;
  111. }
  112. public function testHandleEvent()
  113. {
  114. $this
  115. ->if($field = new runner\exceptions\cli())
  116. ->then
  117. ->boolean($field->handleEvent(atoum\runner::runStart, new atoum\runner()))->isFalse()
  118. ->variable($field->getRunner())->isNull()
  119. ->if($runner = new atoum\runner())
  120. ->then
  121. ->boolean($field->handleEvent(atoum\runner::runStop, $runner))->isTrue()
  122. ->object($field->getRunner())->isIdenticalTo($runner)
  123. ;
  124. }
  125. public function test__toString()
  126. {
  127. $this
  128. ->if($score = new \mock\mageekguy\atoum\runner\score())
  129. ->and($score->getMockController()->getExceptions = array())
  130. ->and($runner = new atoum\runner())
  131. ->and($runner->setScore($score))
  132. ->and($field = new runner\exceptions\cli())
  133. ->then
  134. ->castToString($field)->isEmpty()
  135. ->if($field->handleEvent(atoum\runner::runStart, $runner))
  136. ->then
  137. ->castToString($field)->isEmpty()
  138. ->if($field->handleEvent(atoum\runner::runStop, $runner))
  139. ->then
  140. ->castToString($field)->isEmpty()
  141. ->if($score->getMockController()->getExceptions = $exceptions = array(
  142. array(
  143. 'class' => $class = uniqid(),
  144. 'method' => $method = uniqid(),
  145. 'file' => $file = uniqid(),
  146. 'line' => $line = uniqid(),
  147. 'value' => $value = uniqid()
  148. ),
  149. array(
  150. 'class' => $otherClass = uniqid(),
  151. 'method' => $otherMethod = uniqid(),
  152. 'file' => $otherFile = uniqid(),
  153. 'line' => $otherLine = uniqid(),
  154. 'value' => ($firstOtherValue = uniqid()) . PHP_EOL . ($secondOtherValue = uniqid())
  155. ),
  156. )
  157. )
  158. ->and($field = new runner\exceptions\cli())
  159. ->then
  160. ->castToString($field)->isEmpty()
  161. ->if($field->handleEvent(atoum\runner::runStart, $runner))
  162. ->then
  163. ->castToString($field)->isEmpty()
  164. ->if($field->handleEvent(atoum\runner::runStop, $runner))
  165. ->then
  166. ->castToString($field)->isEqualTo(sprintf('There are %d exceptions:', sizeof($exceptions)) . PHP_EOL .
  167. $class . '::' . $method . '():' . PHP_EOL .
  168. sprintf('An exception has been thrown in file %s on line %d:', $file, $line) . PHP_EOL .
  169. $value . PHP_EOL .
  170. $otherClass . '::' . $otherMethod . '():' . PHP_EOL .
  171. sprintf('An exception has been thrown in file %s on line %d:', $otherFile, $otherLine) . PHP_EOL .
  172. $firstOtherValue . PHP_EOL .
  173. $secondOtherValue . PHP_EOL
  174. )
  175. ->if($field = new runner\exceptions\cli())
  176. ->and($field->setTitlePrompt($titlePrompt = new prompt(uniqid())))
  177. ->and($field->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  178. ->and($field->setMethodPrompt($methodPrompt = new prompt(uniqid())))
  179. ->and($field->setMethodColorizer($methodColorizer = new colorizer(uniqid(), uniqid())))
  180. ->and($field->setExceptionPrompt($exceptionPrompt = new prompt(uniqid())))
  181. ->and($field->setExceptionColorizer($exceptionColorizer = new colorizer(uniqid(), uniqid())))
  182. ->and($field->setLocale($locale = new locale()))
  183. ->then
  184. ->castToString($field)->isEmpty()
  185. ->if($field->handleEvent(atoum\runner::runStart, $runner))
  186. ->then
  187. ->castToString($field)->isEmpty()
  188. ->if($field->handleEvent(atoum\runner::runStop, $runner))
  189. ->then
  190. ->castToString($field)->isEqualTo(
  191. $titlePrompt .
  192. sprintf(
  193. $locale->_('%s:'),
  194. $titleColorizer->colorize(sprintf($field->getLocale()->__('There is %d exception', 'There are %d exceptions', sizeof($exceptions)), sizeof($exceptions)))
  195. ) .
  196. PHP_EOL .
  197. $methodPrompt .
  198. sprintf(
  199. $locale->_('%s:'),
  200. $methodColorizer->colorize($class . '::' . $method . '()')
  201. ) .
  202. PHP_EOL .
  203. $exceptionPrompt .
  204. sprintf(
  205. $locale->_('%s:'),
  206. $exceptionColorizer->colorize(sprintf($locale->_('An exception has been thrown in file %s on line %d'), $file, $line))
  207. ) .
  208. PHP_EOL .
  209. $exceptionPrompt . $value . PHP_EOL .
  210. $methodPrompt .
  211. sprintf(
  212. $locale->_('%s:'),
  213. $methodColorizer->colorize($otherClass . '::' . $otherMethod . '()')
  214. ) .
  215. PHP_EOL .
  216. $exceptionPrompt .
  217. sprintf(
  218. $locale->_('%s:'),
  219. $exceptionColorizer->colorize(sprintf($locale->_('An exception has been thrown in file %s on line %d'), $otherFile, $otherLine))
  220. ) .
  221. PHP_EOL .
  222. $exceptionPrompt . $firstOtherValue . PHP_EOL .
  223. $exceptionPrompt . $secondOtherValue . PHP_EOL
  224. )
  225. ;
  226. }
  227. }