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

/tests/units/classes/test/assertion/manager.php

http://github.com/mageekguy/atoum
PHP | 214 lines | 185 code | 29 blank | 0 comment | 0 complexity | cd60cc6e508163116284301eb28d4357 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\test\assertion;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\test\assertion
  6. ;
  7. require_once __DIR__ . '/../../../runner.php';
  8. class manager extends atoum\test
  9. {
  10. public function test__get()
  11. {
  12. $this
  13. ->given($assertionManager = $this->newTestedInstance)
  14. ->then
  15. ->exception(function() use ($assertionManager, & $event) {
  16. $assertionManager->{$event = uniqid()};
  17. }
  18. )
  19. ->isInstanceOf('mageekguy\atoum\test\assertion\manager\exception')
  20. ->hasMessage('There is no handler defined for \'' . $event . '\'')
  21. ->if($this->testedInstance->setDefaultHandler(function() use (& $defaultReturn) { return ($defaultReturn = uniqid()); }))
  22. ->then
  23. ->string($this->testedInstance->{uniqid()})->isEqualTo($defaultReturn)
  24. ->if($this->testedInstance->setHandler($event = uniqid(), function() use (& $eventReturn) { return ($eventReturn = uniqid()); }))
  25. ->then
  26. ->string($this->testedInstance->{uniqid()})->isEqualTo($defaultReturn)
  27. ->string($this->testedInstance->{$event})->isEqualTo($eventReturn)
  28. ->if($this->testedInstance->setMethodHandler($methodEvent = uniqid(), function() use (& $methodReturn) { return ($methodReturn = uniqid()); }))
  29. ->then
  30. ->string($this->testedInstance->{uniqid()})->isEqualTo($defaultReturn)
  31. ->string($this->testedInstance->{$event})->isEqualTo($eventReturn)
  32. ->string($this->testedInstance->{$methodEvent})->isEqualTo($defaultReturn)
  33. ->if($this->testedInstance->setPropertyHandler($propertyEvent = uniqid(), function() use (& $propertyReturn) { return ($propertyReturn = uniqid()); }))
  34. ->then
  35. ->string($this->testedInstance->{uniqid()})->isEqualTo($defaultReturn)
  36. ->string($this->testedInstance->{$event})->isEqualTo($eventReturn)
  37. ->string($this->testedInstance->{$methodEvent})->isEqualTo($defaultReturn)
  38. ->string($this->testedInstance->{$propertyEvent})->isEqualTo($propertyReturn)
  39. ;
  40. }
  41. public function test__set()
  42. {
  43. $this
  44. ->given($this->newTestedInstance)
  45. ->if($this->testedInstance->{$event = uniqid()} = function() use (& $return) { return ($return = uniqid()); })
  46. ->then
  47. ->string($this->testedInstance->invokeMethodHandler($event))->isEqualTo($return)
  48. ->string($this->testedInstance->invokePropertyHandler($event))->isEqualTo($return)
  49. ;
  50. }
  51. public function test__call()
  52. {
  53. $this
  54. ->given($assertionManager = $this->newTestedInstance)
  55. ->then
  56. ->exception(function() use ($assertionManager, & $event) {
  57. $assertionManager->{$event = uniqid()}();
  58. }
  59. )
  60. ->isInstanceOf('mageekguy\atoum\test\assertion\manager\exception')
  61. ->hasMessage('There is no handler defined for \'' . $event . '\'')
  62. ->if($this->testedInstance->setDefaultHandler(function($event, $defaultArg) { return $defaultArg; }))
  63. ->then
  64. ->array($this->testedInstance->{uniqid()}($arg = uniqid()))->isEqualTo(array($arg))
  65. ->if($this->testedInstance->setHandler($event, function($arg) { return $arg; }))
  66. ->then
  67. ->array($this->testedInstance->{uniqid()}($arg = uniqid()))->isEqualTo(array($arg))
  68. ->string($this->testedInstance->{$event}($eventArg = uniqid()))->isEqualTo($eventArg)
  69. ->if($this->testedInstance->setMethodHandler($methodEvent = uniqid(), function() use (& $methodReturn) { return ($methodReturn = uniqid()); }))
  70. ->then
  71. ->array($this->testedInstance->{uniqid()}($arg = uniqid()))->isEqualTo(array($arg))
  72. ->string($this->testedInstance->{$event}($eventArg = uniqid()))->isEqualTo($eventArg)
  73. ->string($this->testedInstance->{$methodEvent}())->isEqualTo($methodReturn)
  74. ->if($this->testedInstance->setPropertyHandler($propertyEvent = uniqid(), function() use (& $propertyReturn) { return ($propertyReturn = uniqid()); }))
  75. ->then
  76. ->array($this->testedInstance->{uniqid()}($arg = uniqid()))->isEqualTo(array($arg))
  77. ->string($this->testedInstance->{$event}($eventArg = uniqid()))->isEqualTo($eventArg)
  78. ->string($this->testedInstance->{$methodEvent}())->isEqualTo($methodReturn)
  79. ->array($this->testedInstance->{$propertyEvent}($arg = uniqid()))->isEqualTo(array($arg))
  80. ;
  81. }
  82. public function testSetAliaser()
  83. {
  84. $this
  85. ->given($this->newTestedInstance)
  86. ->then
  87. ->object($this->testedInstance->setAliaser($aliaser = new assertion\aliaser()))->isTestedInstance
  88. ->object($this->testedInstance->getAliaser())->isIdenticalTo($aliaser)
  89. ->object($this->testedInstance->setAliaser())->isTestedInstance
  90. ->object($this->testedInstance->getAliaser())
  91. ->isEqualTo(new assertion\aliaser())
  92. ->isNotIdenticalTo($aliaser)
  93. ;
  94. }
  95. public function testSetHandler()
  96. {
  97. $this
  98. ->given($this->newTestedInstance)
  99. ->then
  100. ->object($this->testedInstance->setHandler('foo', function() use (& $return) { return ($return = uniqid()); }))->isTestedInstance
  101. ->string($this->testedInstance->invokeMethodHandler('foo'))->isEqualTo($return)
  102. ->string($this->testedInstance->invokeMethodHandler('FoO'))->isEqualTo($return)
  103. ->string($this->testedInstance->invokePropertyHandler('foo'))->isEqualTo($return)
  104. ->string($this->testedInstance->invokePropertyHandler('fOO'))->isEqualTo($return)
  105. ->object($this->testedInstance->setHandler('BAR', function() use (& $otherReturn) { return ($otherReturn = uniqid()); }))->isTestedInstance
  106. ->string($this->testedInstance->invokeMethodHandler('foo'))->isEqualTo($return)
  107. ->string($this->testedInstance->invokeMethodHandler('FoO'))->isEqualTo($return)
  108. ->string($this->testedInstance->invokePropertyHandler('foo'))->isEqualTo($return)
  109. ->string($this->testedInstance->invokePropertyHandler('fOO'))->isEqualTo($return)
  110. ->string($this->testedInstance->invokeMethodHandler('BAR'))->isEqualTo($otherReturn)
  111. ->string($this->testedInstance->invokeMethodHandler('BaR'))->isEqualTo($otherReturn)
  112. ->string($this->testedInstance->invokePropertyHandler('BAR'))->isEqualTo($otherReturn)
  113. ->string($this->testedInstance->invokePropertyHandler('baR'))->isEqualTo($otherReturn)
  114. ;
  115. }
  116. public function testSetPropertyHandler()
  117. {
  118. $this
  119. ->given($assertionManager = $this->newTestedInstance)
  120. ->then
  121. ->object($this->testedInstance->setPropertyHandler('foo', function() use (& $return) { return ($return = uniqid()); }))->isTestedInstance
  122. ->string($this->testedInstance->invokePropertyHandler('foo'))->isEqualTo($return)
  123. ->string($this->testedInstance->invokePropertyHandler('FoO'))->isEqualTo($return)
  124. ->object($this->testedInstance->setPropertyHandler('BAR', function() use (& $otherReturn) { return ($otherReturn = uniqid()); }))->isTestedInstance
  125. ->string($this->testedInstance->invokePropertyHandler('foo'))->isEqualTo($return)
  126. ->string($this->testedInstance->invokePropertyHandler('fOo'))->isEqualTo($return)
  127. ->string($this->testedInstance->invokePropertyHandler('BAR'))->isEqualTo($otherReturn)
  128. ->string($this->testedInstance->invokePropertyHandler('bar'))->isEqualTo($otherReturn)
  129. ->exception(function() use ($assertionManager) {
  130. $assertionManager->invokeMethodHandler('foo');
  131. }
  132. )
  133. ->isInstanceOf('mageekguy\atoum\test\assertion\manager\exception')
  134. ->hasMessage('There is no handler defined for \'foo\'')
  135. ;
  136. }
  137. public function testSetMethodHandler()
  138. {
  139. $this
  140. ->given($assertionManager = $this->newTestedInstance)
  141. ->then
  142. ->object($this->testedInstance->setMethodHandler('foo', function() use (& $return) { return ($return = uniqid()); }))->isTestedInstance
  143. ->string($this->testedInstance->invokeMethodHandler('foo'))->isEqualTo($return)
  144. ->string($this->testedInstance->invokeMethodHandler('FoO'))->isEqualTo($return)
  145. ->object($this->testedInstance->setMethodHandler('BAR', function() use (& $otherReturn) { return ($otherReturn = uniqid()); }))->isTestedInstance
  146. ->string($this->testedInstance->invokeMethodHandler('foo'))->isEqualTo($return)
  147. ->string($this->testedInstance->invokeMethodHandler('fOo'))->isEqualTo($return)
  148. ->string($this->testedInstance->invokeMethodHandler('BAR'))->isEqualTo($otherReturn)
  149. ->string($this->testedInstance->invokeMethodHandler('bAR'))->isEqualTo($otherReturn)
  150. ->exception(function() use ($assertionManager) {
  151. $assertionManager->invokePropertyHandler('foo');
  152. }
  153. )
  154. ->isInstanceOf('mageekguy\atoum\test\assertion\manager\exception')
  155. ->hasMessage('There is no handler defined for \'foo\'')
  156. ;
  157. }
  158. public function testSetDefaultHandler()
  159. {
  160. $this
  161. ->given($this->newTestedInstance)
  162. ->then
  163. ->object($this->testedInstance->setDefaultHandler($handler = function() {}))->isTestedInstance
  164. ;
  165. }
  166. public function testInvokeMethodHandler()
  167. {
  168. $this
  169. ->given($assertionManager = $this->newTestedInstance)
  170. ->then
  171. ->exception(function() use ($assertionManager, & $event) {
  172. $assertionManager->invokeMethodHandler($event = uniqid());
  173. }
  174. )
  175. ->isInstanceOf('mageekguy\atoum\test\assertion\manager\exception')
  176. ->hasMessage('There is no handler defined for \'' . $event . '\'')
  177. ->if($this->testedInstance->setDefaultHandler(function($event, $arg) { return $arg; }))
  178. ->then
  179. ->array($this->testedInstance->invokeMethodHandler(uniqid(), array($defaultArg = uniqid())))->isEqualTo(array($defaultArg))
  180. ->if($this->testedInstance->setMethodHandler($event = uniqid(), function($eventArg) { return $eventArg; }))
  181. ->then
  182. ->string($this->testedInstance->invokeMethodHandler($event, array($eventArg = uniqid())))->isEqualTo($eventArg)
  183. ;
  184. }
  185. }