PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/report/fields/test/run/cli.php

https://github.com/agallou/atoum
PHP | 192 lines | 183 code | 9 blank | 0 comment | 0 complexity | afba3f780bce2ca5f4126754703a7177 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\report\fields\test\run;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\mock,
  6. mageekguy\atoum\locale,
  7. mageekguy\atoum\test\adapter,
  8. mageekguy\atoum\cli\prompt,
  9. mageekguy\atoum\cli\colorizer,
  10. mageekguy\atoum\report\fields\test
  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\test\run');
  18. }
  19. public function test__construct()
  20. {
  21. $this
  22. ->if($field = new test\run\cli())
  23. ->then
  24. ->object($field->getPrompt())->isEqualTo(new prompt())
  25. ->object($field->getColorizer())->isEqualTo(new colorizer())
  26. ->object($field->getLocale())->isEqualTo(new locale())
  27. ->variable($field->getTestClass())->isNull()
  28. ;
  29. }
  30. public function testSetPrompt()
  31. {
  32. $this
  33. ->if($field = new test\run\cli())
  34. ->then
  35. ->object($field->setPrompt($prompt = new prompt()))->isIdenticalTo($field)
  36. ->object($field->getPrompt())->isIdenticalTo($prompt)
  37. ->object($field->setPrompt())->isIdenticalTo($field)
  38. ->object($field->getPrompt())
  39. ->isNotIdenticalTo($prompt)
  40. ->isEqualTo(new prompt())
  41. ;
  42. }
  43. public function testSetColorizer()
  44. {
  45. $this
  46. ->if($field = new test\run\cli())
  47. ->then
  48. ->object($field->setColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  49. ->object($field->getColorizer())->isIdenticalTo($colorizer)
  50. ->object($field->setColorizer())->isIdenticalTo($field)
  51. ->object($field->getColorizer())
  52. ->isNotIdenticalTo($colorizer)
  53. ->isEqualTo(new colorizer())
  54. ;
  55. }
  56. public function testHandleEvent()
  57. {
  58. $this
  59. ->if($field = new test\run\cli())
  60. ->and($adapter = new adapter())
  61. ->and($adapter->class_exists = true)
  62. ->and($testController = new mock\controller())
  63. ->and($testController->getTestedClassName = uniqid())
  64. ->and($test = new \mock\mageekguy\atoum\test($adapter))
  65. ->then
  66. ->boolean($field->handleEvent(atoum\test::runStop, $test))->isFalse()
  67. ->variable($field->getTestClass())->isNull()
  68. ->boolean($field->handleEvent(atoum\test::beforeSetUp, $test))->isFalse()
  69. ->variable($field->getTestClass())->isNull()
  70. ->boolean($field->handleEvent(atoum\test::afterSetUp, $test))->isFalse()
  71. ->variable($field->getTestClass())->isNull()
  72. ->boolean($field->handleEvent(atoum\test::beforeTestMethod, $test))->isFalse()
  73. ->variable($field->getTestClass())->isNull()
  74. ->boolean($field->handleEvent(atoum\test::fail, $test))->isFalse()
  75. ->variable($field->getTestClass())->isNull()
  76. ->boolean($field->handleEvent(atoum\test::error, $test))->isFalse()
  77. ->variable($field->getTestClass())->isNull()
  78. ->boolean($field->handleEvent(atoum\test::exception, $test))->isFalse()
  79. ->variable($field->getTestClass())->isNull()
  80. ->boolean($field->handleEvent(atoum\test::success, $test))->isFalse()
  81. ->variable($field->getTestClass())->isNull()
  82. ->boolean($field->handleEvent(atoum\test::afterTestMethod, $test))->isFalse()
  83. ->variable($field->getTestClass())->isNull()
  84. ->boolean($field->handleEvent(atoum\test::beforeTearDown, $test))->isFalse()
  85. ->variable($field->getTestClass())->isNull()
  86. ->boolean($field->handleEvent(atoum\test::afterTearDown, $test))->isFalse()
  87. ->variable($field->getTestClass())->isNull()
  88. ->boolean($field->handleEvent(atoum\test::runStart, $test))->isTrue()
  89. ->string($field->getTestClass())->isEqualTo($test->getClass())
  90. ;
  91. }
  92. public function test__toString()
  93. {
  94. $this
  95. ->if($adapter = new adapter())
  96. ->and($adapter->class_exists = true)
  97. ->and($testController = new mock\controller())
  98. ->and($testController->getTestedClassName = uniqid())
  99. ->and($test = new \mock\mageekguy\atoum\test($adapter))
  100. ->and($defaultField = new test\run\cli())
  101. ->then
  102. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  103. ->if($defaultField->handleEvent(atoum\test::runStop, $test))
  104. ->then
  105. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  106. ->if($defaultField->handleEvent(atoum\test::beforeSetUp, $test))
  107. ->then
  108. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  109. ->if($defaultField->handleEvent(atoum\test::afterSetUp, $test))
  110. ->then
  111. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  112. ->if($defaultField->handleEvent(atoum\test::beforeTestMethod, $test))
  113. ->then
  114. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  115. ->if($defaultField->handleEvent(atoum\test::fail, $test))
  116. ->then
  117. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  118. ->if($defaultField->handleEvent(atoum\test::error, $test))
  119. ->then
  120. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  121. ->if($defaultField->handleEvent(atoum\test::exception, $test))
  122. ->then
  123. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  124. ->if($defaultField->handleEvent(atoum\test::success, $test))
  125. ->then
  126. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  127. ->if($defaultField->handleEvent(atoum\test::afterTestMethod, $test))
  128. ->then
  129. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  130. ->if($defaultField->handleEvent(atoum\test::beforeTearDown, $test))
  131. ->then
  132. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  133. ->if($defaultField->handleEvent(atoum\test::afterTearDown, $test))
  134. ->then
  135. ->castToString($defaultField)->isEqualTo('There is currently no test running.' . PHP_EOL)
  136. ->if($defaultField->handleEvent(atoum\test::runStart, $test))
  137. ->then
  138. ->castToString($defaultField)->isEqualTo(sprintf('%s...', $test->getClass()) . PHP_EOL)
  139. ->if($customField = new test\run\cli())
  140. ->and($customField->setPrompt($prompt = new prompt(uniqid())))
  141. ->and($customField->setColorizer($colorizer = new colorizer(uniqid(), uniqid())))
  142. ->and($customField->setLocale($locale = new locale()))
  143. ->then
  144. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  145. ->if($customField->handleEvent(atoum\test::runStop, $test))
  146. ->then
  147. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  148. ->if($customField->handleEvent(atoum\test::beforeSetUp, $test))
  149. ->then
  150. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  151. ->if($customField->handleEvent(atoum\test::afterSetUp, $test))
  152. ->then
  153. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  154. ->if($customField->handleEvent(atoum\test::beforeTestMethod, $test))
  155. ->then
  156. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  157. ->if($customField->handleEvent(atoum\test::fail, $test))
  158. ->then
  159. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  160. ->if($customField->handleEvent(atoum\test::error, $test))
  161. ->then
  162. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  163. ->if($customField->handleEvent(atoum\test::exception, $test))
  164. ->then
  165. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  166. ->if($customField->handleEvent(atoum\test::success, $test))
  167. ->then
  168. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  169. ->if($customField->handleEvent(atoum\test::afterTestMethod, $test))
  170. ->then
  171. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  172. ->if($customField->handleEvent(atoum\test::beforeTearDown, $test))
  173. ->then
  174. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  175. ->if($customField->handleEvent(atoum\test::afterTearDown, $test))
  176. ->then
  177. ->castToString($customField)->isEqualTo($prompt . $colorizer->colorize($locale->_('There is currently no test running.')) . PHP_EOL)
  178. ->if($customField->handleEvent(atoum\test::runStart, $test))
  179. ->then
  180. ->castToString($customField)->isEqualTo($prompt . sprintf($locale->_('%s...'), $colorizer->colorize($test->getClass())) . PHP_EOL)
  181. ;
  182. }
  183. }