PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/report/fields/runner/result/notifier.php

http://github.com/mageekguy/atoum
PHP | 221 lines | 203 code | 18 blank | 0 comment | 2 complexity | be719f367e1c1a1d8d31c801a8575eaf MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\report\fields\runner\result;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\locale,
  6. mageekguy\atoum\adapter,
  7. mageekguy\atoum\test
  8. ;
  9. require_once __DIR__ . '/../../../../../runner.php';
  10. class notifier extends atoum\test
  11. {
  12. public function testClass()
  13. {
  14. $this->testedClass->extends('mageekguy\atoum\report\fields\runner\result');
  15. }
  16. public function test__construct()
  17. {
  18. $this
  19. ->if($field = new \mock\mageekguy\atoum\report\fields\runner\result\notifier())
  20. ->then
  21. ->object($field->getLocale())->isEqualTo(new locale())
  22. ->object($field->getAdapter())->isEqualTo(new adapter())
  23. ->variable($field->getTestNumber())->isNull()
  24. ->variable($field->getTestMethodNumber())->isNull()
  25. ->variable($field->getFailNumber())->isNull()
  26. ->variable($field->getErrorNumber())->isNull()
  27. ->variable($field->getExceptionNumber())->isNull()
  28. ->array($field->getEvents())->isEqualTo(array(atoum\runner::runStop))
  29. ->if($adapter = new adapter())
  30. ->and($field = new \mock\mageekguy\atoum\report\fields\runner\result\notifier($adapter))
  31. ->then
  32. ->object($field->getAdapter())->isIdenticalTo($adapter)
  33. ;
  34. }
  35. public function testHandleEvent()
  36. {
  37. $this
  38. ->if($score = new \mock\mageekguy\atoum\runner\score())
  39. ->and($this->calling($score)->getAssertionNumber = $assertionNumber = rand(1, PHP_INT_MAX))
  40. ->and($this->calling($score)->getFailNumber = $failNumber = rand(1, PHP_INT_MAX))
  41. ->and($this->calling($score)->getErrorNumber = $errorNumber = rand(1, PHP_INT_MAX))
  42. ->and($this->calling($score)->getExceptionNumber = $exceptionNumber = rand(1, PHP_INT_MAX))
  43. ->and($runner = new \mock\mageekguy\atoum\runner())
  44. ->and($runner->setScore($score))
  45. ->and($this->calling($runner)->getTestNumber = $testNumber = rand(1, PHP_INT_MAX))
  46. ->and($this->calling($runner)->getTestMethodNumber = $testMethodNumber = rand(1, PHP_INT_MAX))
  47. ->and($field = new \mock\mageekguy\atoum\report\fields\runner\result\notifier())
  48. ->then
  49. ->boolean($field->handleEvent(atoum\runner::runStart, $runner))->isFalse()
  50. ->variable($field->getTestNumber())->isNull()
  51. ->variable($field->getTestMethodNumber())->isNull()
  52. ->variable($field->getAssertionNumber())->isNull()
  53. ->variable($field->getFailNumber())->isNull()
  54. ->variable($field->getErrorNumber())->isNull()
  55. ->variable($field->getExceptionNumber())->isNull()
  56. ->boolean($field->handleEvent(atoum\runner::runStop, $runner))->isTrue()
  57. ->integer($field->getTestNumber())->isEqualTo($testNumber)
  58. ->integer($field->getTestMethodNumber())->isEqualTo($testMethodNumber)
  59. ->integer($field->getAssertionNumber())->isEqualTo($assertionNumber)
  60. ->integer($field->getFailNumber())->isEqualTo($failNumber)
  61. ->integer($field->getErrorNumber())->isEqualTo($errorNumber)
  62. ->integer($field->getExceptionNumber())->isEqualTo($exceptionNumber)
  63. ;
  64. }
  65. public function testNotify()
  66. {
  67. $this
  68. ->if($score = new \mock\mageekguy\atoum\score())
  69. ->and($runner = new \mock\mageekguy\atoum\runner())
  70. ->and($this->calling($runner)->getScore = $score)
  71. ->and($locale = new \mock\mageekguy\atoum\locale())
  72. ->and($this->calling($locale)->_ = function ($string) use (& $noTestRunningString, & $successString, & $failureString) {
  73. switch ($string)
  74. {
  75. case '%s %s %s %s %s':
  76. return $successString = uniqid();
  77. case '%s %s %s %s %s %s %s %s':
  78. return $failureString = uniqid();
  79. default:
  80. return uniqid();
  81. }
  82. }
  83. )
  84. ->and($this->calling($locale)->__ = function($singularString, $pluralString, $number) use (& $testString, & $testMethodString, & $testVoidMethodString, & $testSkippedMethodString, & $assertionString, & $errorString, & $exceptionString) {
  85. switch ($singularString)
  86. {
  87. case '%s test':
  88. return $testString = uniqid();
  89. case '%s method':
  90. return $testMethodString = uniqid();
  91. case '%s void method':
  92. return $testVoidMethodString = uniqid();
  93. case '%s skipped method':
  94. return $testSkippedMethodString = uniqid();
  95. case '%s assertion':
  96. return $assertionString = uniqid();
  97. case '%s error':
  98. return $errorString = uniqid();
  99. case '%s exception':
  100. return $exceptionString = uniqid();
  101. default:
  102. return uniqid();
  103. }
  104. }
  105. )
  106. ->assert('Success with one test, one method and one assertion, no fail, no error, no exception')
  107. ->and($this->calling($runner)->getTestNumber = 1)
  108. ->and($this->calling($runner)->getTestMethodNumber = 1)
  109. ->and($this->calling($score)->getAssertionNumber = 1)
  110. ->and($this->calling($score)->getFailNumber = 0)
  111. ->and($this->calling($score)->getErrorNumber = 0)
  112. ->and($this->calling($score)->getExceptionNumber = 0)
  113. ->and($adapter = new test\adapter())
  114. ->and($adapter->system = function() use (& $output) { return $output = uniqid(); })
  115. ->and($field = new \mock\mageekguy\atoum\report\fields\runner\result\notifier($adapter))
  116. ->and($field->setLocale($locale))
  117. ->and($field->handleEvent(atoum\runner::runStop, $runner))
  118. ->then
  119. ->castToString($field)->isEqualTo($output . PHP_EOL)
  120. ->mock($locale)
  121. ->call('_')->withArguments('%s %s %s %s %s')
  122. ->call('__')->withArguments('%s test', '%s tests', 1)->once()
  123. ->call('__')->withArguments('%s/%s method', '%s/%s methods', 1)->once()
  124. ->call('__')->withArguments('%s skipped method', '%s skipped methods', 0)->once()
  125. ->call('__')->withArguments('%s assertion', '%s assertions', 1)->once()
  126. ->assert('Success with several tests, several methods and several assertions, no fail, no error, no exception')
  127. ->if($this->calling($runner)->getTestNumber = $testNumber = rand(2, PHP_INT_MAX))
  128. ->and($this->calling($runner)->getTestMethodNumber = $testMethodNumber = rand(2, PHP_INT_MAX))
  129. ->and($this->calling($score)->getAssertionNumber = $assertionNumber = rand(2, PHP_INT_MAX))
  130. ->and($field = new \mock\mageekguy\atoum\report\fields\runner\result\notifier($adapter))
  131. ->and($field->setLocale($locale))
  132. ->and($field->handleEvent(atoum\runner::runStop, $runner))
  133. ->then
  134. ->castToString($field)->isEqualTo($output . PHP_EOL)
  135. ->mock($locale)
  136. ->call('_')->withArguments('%s %s %s %s %s')->once()
  137. ->call('__')->withArguments('%s test', '%s tests', $testNumber)->once()
  138. ->call('__')->withArguments('%s/%s method', '%s/%s methods', $testMethodNumber)->once()
  139. ->call('__')->withArguments('%s void method', '%s void methods', 0)->once()
  140. ->call('__')->withArguments('%s skipped method', '%s skipped methods', 0)->once()
  141. ->call('__')->withArguments('%s assertion', '%s assertions', $assertionNumber)->once()
  142. ->assert('Failure with several tests, several methods and several assertions, one fail, one error, one exception')
  143. ->if($this->calling($score)->getFailNumber = 1)
  144. ->and($this->calling($score)->getErrorNumber = 1)
  145. ->and($this->calling($score)->getExceptionNumber = 1)
  146. ->and($this->calling($score)->getUncompletedMethodNumber = 1)
  147. ->and($field = new \mock\mageekguy\atoum\report\fields\runner\result\notifier($adapter))
  148. ->and($field->setLocale($locale))
  149. ->and($field->handleEvent(atoum\runner::runStop, $runner))
  150. ->then
  151. ->castToString($field)->isEqualTo($output . PHP_EOL)
  152. ->mock($locale)
  153. ->call('_')->withArguments('%s %s %s %s %s %s %s %s')
  154. ->call('__')->withArguments('%s test', '%s tests', $testNumber)->once()
  155. ->call('__')->withArguments('%s/%s method', '%s/%s methods', $testMethodNumber)->once()
  156. ->call('__')->withArguments('%s skipped method', '%s skipped methods', 0)->once()
  157. ->call('__')->withArguments('%s uncompleted method', '%s uncompleted methods', 1)->once()
  158. ->call('__')->withArguments('%s failure', '%s failures', 1)->once()
  159. ->call('__')->withArguments('%s error', '%s errors', 1)->once()
  160. ->call('__')->withArguments('%s exception', '%s exceptions', 1)->once()
  161. ->assert('Failure with several tests, several methods and several assertions, several fails, several errors, several exceptions')
  162. ->if($this->calling($score)->getFailNumber = $failNumber = rand(2, PHP_INT_MAX))
  163. ->and($this->calling($score)->getErrorNumber = $errorNumber = rand(2, PHP_INT_MAX))
  164. ->and($this->calling($score)->getExceptionNumber = $exceptionNumber = rand(2, PHP_INT_MAX))
  165. ->and($this->calling($score)->getUncompletedMethodNumber = $uncompletedTestNumber = rand(2, PHP_INT_MAX))
  166. ->and($field = new \mock\mageekguy\atoum\report\fields\runner\result\notifier($adapter))
  167. ->and($field->setLocale($locale))
  168. ->and($field->handleEvent(atoum\runner::runStop, $runner))
  169. ->then
  170. ->castToString($field)->isEqualTo($output . PHP_EOL)
  171. ->mock($locale)
  172. ->call('_')->withArguments('%s %s %s %s %s %s %s %s')
  173. ->call('__')->withArguments('%s test', '%s tests', $testNumber)->once()
  174. ->call('__')->withArguments('%s/%s method', '%s/%s methods', $testMethodNumber)->once()
  175. ->call('__')->withArguments('%s failure', '%s failures', $failNumber)->once()
  176. ->call('__')->withArguments('%s error', '%s errors', $errorNumber)->once()
  177. ->call('__')->withArguments('%s exception', '%s exceptions', $exceptionNumber)->once()
  178. ;
  179. }
  180. public function testSetAdapter()
  181. {
  182. $this
  183. ->if($field = new \mock\mageekguy\atoum\report\fields\runner\result\notifier())
  184. ->then
  185. ->object($field->setAdapter($adapter = new atoum\adapter()))->isIdenticalTo($field)
  186. ->object($field->getAdapter())->isIdenticalTo($adapter)
  187. ->object($field->setAdapter())->isIdenticalTo($field)
  188. ->object($field->getAdapter())
  189. ->isNotIdenticalTo($adapter)
  190. ->isEqualTo(new atoum\adapter())
  191. ;
  192. }
  193. public function testSend()
  194. {
  195. $this
  196. ->if($adapter = new test\adapter())
  197. ->and($adapter->system = function() use (& $output) { return $output = uniqid(); })
  198. ->and($field = new \mock\mageekguy\atoum\report\fields\runner\result\notifier($adapter))
  199. ->then
  200. ->string($field->send(uniqid(), uniqid(), true))->isEqualTo($output)
  201. ;
  202. }
  203. }