PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/mageekguy/atoum
PHP | 335 lines | 324 code | 11 blank | 0 comment | 0 complexity | 33b7c98083a78aed26f4d0509844229b MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\report\fields\runner\failures;
  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\failures');
  17. }
  18. public function test__construct()
  19. {
  20. $this
  21. ->if($field = new runner\failures\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->getLocale())->isEqualTo(new locale())
  28. ->variable($field->getRunner())->isNull()
  29. ->array($field->getEvents())->isEqualTo(array(atoum\runner::runStop))
  30. ;
  31. }
  32. public function testSetTitlePrompt()
  33. {
  34. $this
  35. ->if($field = new runner\failures\cli())
  36. ->then
  37. ->object($field->setTitlePrompt($prompt = new prompt(uniqid())))->isIdenticalTo($field)
  38. ->object($field->getTitlePrompt())->isIdenticalTo($prompt)
  39. ->object($field->setTitlePrompt())->isIdenticalTo($field)
  40. ->object($field->getTitlePrompt())
  41. ->isNotIdenticalTo($prompt)
  42. ->isEqualTo(new prompt())
  43. ;
  44. }
  45. public function testSetTitleColorizer()
  46. {
  47. $this
  48. ->if($field = new runner\failures\cli())
  49. ->then
  50. ->object($field->setTitleColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  51. ->object($field->getTitleColorizer())->isIdenticalTo($colorizer)
  52. ->object($field->setTitleColorizer())->isIdenticalTo($field)
  53. ->object($field->getTitleColorizer())
  54. ->isNotIdenticalTo($colorizer)
  55. ->isEqualTo(new colorizer())
  56. ;
  57. }
  58. public function testSetMethodPrompt()
  59. {
  60. $this
  61. ->if($field = new runner\failures\cli())
  62. ->then
  63. ->object($field->setMethodPrompt($prompt = new prompt(uniqid())))->isIdenticalTo($field)
  64. ->object($field->getMethodPrompt())->isIdenticalTo($prompt)
  65. ->object($field->setMethodPrompt())->isIdenticalTo($field)
  66. ->object($field->getMethodPrompt())
  67. ->isNotIdenticalTo($prompt)
  68. ->isEqualTo(new prompt())
  69. ;
  70. }
  71. public function testSetMethodColorizer()
  72. {
  73. $this
  74. ->if($field = new runner\failures\cli())
  75. ->then
  76. ->object($field->setMethodColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  77. ->object($field->getMethodColorizer())->isIdenticalTo($colorizer)
  78. ->object($field->setTitleColorizer())->isIdenticalTo($field)
  79. ->object($field->getTitleColorizer())
  80. ->isNotIdenticalTo($colorizer)
  81. ->isEqualTo(new colorizer())
  82. ;
  83. }
  84. public function testHandleEvent()
  85. {
  86. $this
  87. ->if($field = new runner\failures\cli())
  88. ->then
  89. ->boolean($field->handleEvent(atoum\runner::runStart, new atoum\runner()))->isFalse()
  90. ->variable($field->getRunner())->isNull()
  91. ->boolean($field->handleEvent(atoum\runner::runStop, $runner = new atoum\runner()))->isTrue()
  92. ->object($field->getRunner())->isIdenticalTo($runner)
  93. ;
  94. }
  95. public function test__toString()
  96. {
  97. $this
  98. ->if($score = new \mock\mageekguy\atoum\runner\score())
  99. ->and($score->getMockController()->getErrors = array())
  100. ->and($runner = new atoum\runner())
  101. ->and($runner->setScore($score))
  102. ->and($defaultField = new runner\failures\cli())
  103. ->and($customField = new runner\failures\cli())
  104. ->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))
  105. ->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  106. ->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))
  107. ->and($customField->setMethodColorizer($methodColorizer = new colorizer(uniqid(), uniqid())))
  108. ->and($customField->setLocale($locale = new atoum\locale()))
  109. ->then
  110. ->castToString($defaultField)->isEmpty()
  111. ->castToString($customField)->isEmpty()
  112. ->if($defaultField->handleEvent(atoum\runner::runStart, $runner))
  113. ->and($customField->handleEvent(atoum\runner::runStart, $runner))
  114. ->then
  115. ->castToString($defaultField)->isEmpty()
  116. ->castToString($customField)->isEmpty()
  117. ->if($defaultField->handleEvent(atoum\runner::runStop, $runner))
  118. ->and($customField->handleEvent(atoum\runner::runStop, $runner))
  119. ->then
  120. ->castToString($defaultField)->isEmpty()
  121. ->castToString($customField)->isEmpty()
  122. ->if($score->getMockController()->getFailAssertions = $fails = array(
  123. array(
  124. 'case' => null,
  125. 'dataSetKey' => null,
  126. 'class' => $class = uniqid(),
  127. 'method' => $method = uniqid(),
  128. 'file' => $file = uniqid(),
  129. 'line' => $line = uniqid(),
  130. 'asserter' => $asserter = uniqid(),
  131. 'fail' => $fail = uniqid()
  132. ),
  133. array(
  134. 'case' => null,
  135. 'dataSetKey' => null,
  136. 'class' => $otherClass = uniqid(),
  137. 'method' => $otherMethod = uniqid(),
  138. 'file' => $otherFile = uniqid(),
  139. 'line' => $otherLine = uniqid(),
  140. 'asserter' => $otherAsserter = uniqid(),
  141. 'fail' => $otherFail = uniqid()
  142. )
  143. )
  144. )
  145. ->and($defaultField = new runner\failures\cli())
  146. ->and($customField = new runner\failures\cli())
  147. ->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))
  148. ->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  149. ->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))
  150. ->and($customField->setMethodColorizer($methodColorizer = new colorizer(uniqid(), uniqid())))
  151. ->and($customField->setLocale($locale = new atoum\locale()))
  152. ->then
  153. ->castToString($defaultField)->isEmpty()
  154. ->castToString($customField)->isEmpty()
  155. ->if($defaultField->handleEvent(atoum\runner::runStop, $runner))
  156. ->and($customField->handleEvent(atoum\runner::runStop, $runner))
  157. ->then
  158. ->castToString($defaultField)->isEqualTo(sprintf('There are %d failures:', sizeof($fails)) . PHP_EOL .
  159. $class . '::' . $method . '():' . PHP_EOL .
  160. sprintf('In file %s on line %d, %s failed: %s', $file, $line, $asserter, $fail) . PHP_EOL .
  161. $otherClass . '::' . $otherMethod . '():' . PHP_EOL .
  162. sprintf('In file %s on line %d, %s failed: %s', $otherFile, $otherLine, $otherAsserter, $otherFail) . PHP_EOL
  163. )
  164. ->castToString($customField)->isEqualTo(
  165. $titlePrompt .
  166. sprintf(
  167. $locale->_('%s:'),
  168. $titleColorizer->colorize(sprintf($locale->__('There is %d failure', 'There are %d failures', sizeof($fails)), sizeof($fails)))
  169. ) .
  170. PHP_EOL .
  171. $methodPrompt .
  172. sprintf(
  173. $locale->_('%s:'),
  174. $methodColorizer->colorize($class . '::' . $method . '()')
  175. ) .
  176. PHP_EOL .
  177. sprintf($locale->_('In file %s on line %d, %s failed: %s'), $file, $line, $asserter, $fail) .
  178. PHP_EOL .
  179. $methodPrompt .
  180. sprintf(
  181. $locale->_('%s:'),
  182. $methodColorizer->colorize($otherClass . '::' . $otherMethod . '()')
  183. ) .
  184. PHP_EOL .
  185. sprintf($locale->_('In file %s on line %d, %s failed: %s'), $otherFile, $otherLine, $otherAsserter, $otherFail) .
  186. PHP_EOL
  187. )
  188. ->if($score->getMockController()->getFailAssertions = $fails = array(
  189. array(
  190. 'case' => $case = uniqid(),
  191. 'dataSetKey' => null,
  192. 'class' => $class = uniqid(),
  193. 'method' => $method = uniqid(),
  194. 'file' => $file = uniqid(),
  195. 'line' => $line = uniqid(),
  196. 'asserter' => $asserter = uniqid(),
  197. 'fail' => $fail = uniqid()
  198. ),
  199. array(
  200. 'case' => $otherCase = uniqid(),
  201. 'dataSetKey' => null,
  202. 'class' => $otherClass = uniqid(),
  203. 'method' => $otherMethod = uniqid(),
  204. 'file' => $otherFile = uniqid(),
  205. 'line' => $otherLine = uniqid(),
  206. 'asserter' => $otherAsserter = uniqid(),
  207. 'fail' => $otherFail = uniqid()
  208. )
  209. )
  210. )
  211. ->and($defaultField = new runner\failures\cli())
  212. ->and($customField = new runner\failures\cli())
  213. ->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))
  214. ->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  215. ->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))
  216. ->and($customField->setMethodColorizer($methodColorizer = new colorizer(uniqid(), uniqid())))
  217. ->and($customField->setLocale($locale = new atoum\locale()))
  218. ->then
  219. ->castToString($defaultField)->isEmpty()
  220. ->castToString($customField)->isEmpty()
  221. ->if($defaultField->handleEvent(atoum\runner::runStop, $runner))
  222. ->and($customField->handleEvent(atoum\runner::runStop, $runner))
  223. ->then
  224. ->castToString($defaultField)->isEqualTo(sprintf('There are %d failures:', sizeof($fails)) . PHP_EOL .
  225. $class . '::' . $method . '():' . PHP_EOL .
  226. sprintf('In file %s on line %d in case \'%s\', %s failed: %s', $file, $line, $case, $asserter, $fail) . PHP_EOL .
  227. $otherClass . '::' . $otherMethod . '():' . PHP_EOL .
  228. sprintf('In file %s on line %d in case \'%s\', %s failed: %s', $otherFile, $otherLine, $otherCase, $otherAsserter, $otherFail) . PHP_EOL
  229. )
  230. ->castToString($customField)->isEqualTo(
  231. $titlePrompt .
  232. sprintf(
  233. $locale->_('%s:'),
  234. $titleColorizer->colorize(sprintf($locale->__('There is %d failure', 'There are %d failures', sizeof($fails)), sizeof($fails)))
  235. ) .
  236. PHP_EOL .
  237. $methodPrompt .
  238. sprintf(
  239. $locale->_('%s:'),
  240. $methodColorizer->colorize($class . '::' . $method . '()')
  241. ) .
  242. PHP_EOL .
  243. sprintf($locale->_('In file %s on line %d in case \'%s\', %s failed: %s'), $file, $line, $case, $asserter, $fail) .
  244. PHP_EOL .
  245. $methodPrompt .
  246. sprintf(
  247. $locale->_('%s:'),
  248. $methodColorizer->colorize($otherClass . '::' . $otherMethod . '()')
  249. ) .
  250. PHP_EOL .
  251. sprintf($locale->_('In file %s on line %d in case \'%s\', %s failed: %s'), $otherFile, $otherLine, $otherCase, $otherAsserter, $otherFail) .
  252. PHP_EOL
  253. )
  254. ->if($score->getMockController()->getFailAssertions = $fails = array(
  255. array(
  256. 'case' => $case = uniqid(),
  257. 'dataSetKey' => $dataSetKey = rand(1, PHP_INT_MAX),
  258. 'dataSetProvider' => $dataSetProvider = uniqid(),
  259. 'class' => $class = uniqid(),
  260. 'method' => $method = uniqid(),
  261. 'file' => $file = uniqid(),
  262. 'line' => $line = uniqid(),
  263. 'asserter' => $asserter = uniqid(),
  264. 'fail' => $fail = uniqid()
  265. ),
  266. array(
  267. 'case' => $otherCase = uniqid(),
  268. 'dataSetKey' => $otherDataSetKey = rand(1, PHP_INT_MAX),
  269. 'dataSetProvider' => $otherDataSetProvider = uniqid(),
  270. 'class' => $otherClass = uniqid(),
  271. 'method' => $otherMethod = uniqid(),
  272. 'file' => $otherFile = uniqid(),
  273. 'line' => $otherLine = uniqid(),
  274. 'asserter' => $otherAsserter = uniqid(),
  275. 'fail' => $otherFail = uniqid()
  276. )
  277. )
  278. )
  279. ->and($defaultField = new runner\failures\cli())
  280. ->and($customField = new runner\failures\cli())
  281. ->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))
  282. ->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  283. ->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))
  284. ->and($customField->setMethodColorizer($methodColorizer = new colorizer(uniqid(), uniqid())))
  285. ->and($customField->setLocale($locale = new atoum\locale()))
  286. ->then
  287. ->castToString($defaultField)->isEmpty()
  288. ->castToString($customField)->isEmpty()
  289. ->if($defaultField->handleEvent(atoum\runner::runStop, $runner))
  290. ->and($customField->handleEvent(atoum\runner::runStop, $runner))
  291. ->then
  292. ->castToString($defaultField)->isEqualTo(sprintf('There are %d failures:', sizeof($fails)) . PHP_EOL .
  293. $class . '::' . $method . '():' . PHP_EOL .
  294. sprintf('In file %s on line %d in case \'%s\', %s failed for data set [%s] of data provider %s: %s', $file, $line, $case, $asserter, $dataSetKey, $dataSetProvider, $fail) . PHP_EOL .
  295. $otherClass . '::' . $otherMethod . '():' . PHP_EOL .
  296. sprintf('In file %s on line %d in case \'%s\', %s failed for data set [%s] of data provider %s: %s', $otherFile, $otherLine, $otherCase, $otherAsserter, $otherDataSetKey, $otherDataSetProvider, $otherFail) . PHP_EOL
  297. )
  298. ->castToString($customField)->isEqualTo(
  299. $titlePrompt .
  300. sprintf(
  301. $locale->_('%s:'),
  302. $titleColorizer->colorize(sprintf($locale->__('There is %d failure', 'There are %d failures', sizeof($fails)), sizeof($fails)))
  303. ) .
  304. PHP_EOL .
  305. $methodPrompt .
  306. sprintf(
  307. $locale->_('%s:'),
  308. $methodColorizer->colorize($class . '::' . $method . '()')
  309. ) .
  310. PHP_EOL .
  311. sprintf($locale->_('In file %s on line %d in case \'%s\', %s failed for data set [%s] of data provider %s: %s'), $file, $line, $case, $asserter, $dataSetKey, $dataSetProvider, $fail) .
  312. PHP_EOL .
  313. $methodPrompt .
  314. sprintf(
  315. $locale->_('%s:'),
  316. $methodColorizer->colorize($otherClass . '::' . $otherMethod . '()')
  317. ) .
  318. PHP_EOL .
  319. sprintf($locale->_('In file %s on line %d in case \'%s\', %s failed for data set [%s] of data provider %s: %s'), $otherFile, $otherLine, $otherCase, $otherAsserter, $otherDataSetKey, $otherDataSetProvider, $otherFail) .
  320. PHP_EOL
  321. )
  322. ;
  323. }
  324. }