PageRenderTime 61ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/test/adapter/call.php

https://github.com/Hywan/atoum
PHP | 277 lines | 265 code | 12 blank | 0 comment | 0 complexity | 7dfddd6a6ff1a60945843c4a696bd36a MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\test\adapter;
  3. require_once __DIR__ . '/../../../runner.php';
  4. use mageekguy\atoum;
  5. use mageekguy\atoum\test\adapter\call as testedClass;
  6. use mageekguy\atoum\test\adapter\call\decorator;
  7. class call extends atoum\test
  8. {
  9. public function test__construct()
  10. {
  11. $this
  12. ->if($call = new testedClass())
  13. ->then
  14. ->variable($call->getFunction())->isNull()
  15. ->variable($call->getArguments())->isNull()
  16. ->object($call->getDecorator())->isEqualTo(new decorator())
  17. ->if($call = new testedClass($function = uniqid()))
  18. ->then
  19. ->string($call->getFunction())->isEqualTo($function)
  20. ->variable($call->getArguments())->isNull()
  21. ->object($call->getDecorator())->isEqualTo(new decorator())
  22. ->if($call = new testedClass($function = uniqid(), $arguments = []))
  23. ->then
  24. ->string($call->getFunction())->isEqualTo($function)
  25. ->array($call->getArguments())->isEqualTo($arguments)
  26. ->object($call->getDecorator())->isEqualTo(new decorator())
  27. ->if($call = new testedClass('MD5'))
  28. ->then
  29. ->string($call->getFunction())->isEqualTo('MD5')
  30. ->variable($call->getArguments())->isNull()
  31. ->object($call->getDecorator())->isEqualTo(new decorator())
  32. ->exception(function () {
  33. new testedClass('');
  34. })
  35. ->isInstanceOf(atoum\exceptions\logic\invalidArgument::class)
  36. ->hasMessage('Function must not be empty')
  37. ;
  38. }
  39. public function test__toString()
  40. {
  41. $this
  42. ->if($call = new testedClass())
  43. ->then
  44. ->castToString($call)->isEmpty()
  45. ;
  46. }
  47. public function testIsFullyQualified()
  48. {
  49. $this
  50. ->if($call = new testedClass())
  51. ->then
  52. ->boolean($call->isFullyQualified())->isFalse()
  53. ->if($call = new testedClass(uniqid()))
  54. ->then
  55. ->boolean($call->isFullyQualified())->isFalse()
  56. ->if($call = new testedClass(null, []))
  57. ->then
  58. ->boolean($call->isFullyQualified())->isFalse()
  59. ->if($call = new testedClass(uniqid(), []))
  60. ->then
  61. ->boolean($call->isFullyQualified())->isTrue()
  62. ;
  63. }
  64. public function testSetFunction()
  65. {
  66. $this
  67. ->if($call = new testedClass())
  68. ->then
  69. ->object($call->setFunction($function = uniqid()))->isIdenticalTo($call)
  70. ->string($call->getFunction())->isEqualTo($function)
  71. ->object($call->setFunction('foo'))->isIdenticalTo($call)
  72. ->string($call->getFunction())->isEqualTo('foo')
  73. ->object($call->setFunction('FOo'))->isIdenticalTo($call)
  74. ->string($call->getFunction())->isEqualTo('FOo')
  75. ;
  76. }
  77. public function testSetArguments()
  78. {
  79. $this
  80. ->if($call = new testedClass())
  81. ->then
  82. ->object($call->setArguments($arguments = []))->isIdenticalTo($call)
  83. ->array($call->getArguments())->isEqualTo($arguments)
  84. ;
  85. }
  86. public function testUnsetArguments()
  87. {
  88. $this
  89. ->if($call = new testedClass())
  90. ->then
  91. ->object($call->unsetArguments())->isIdenticalTo($call)
  92. ->variable($call->getArguments())->isNull()
  93. ->if($call->setArguments([]))
  94. ->then
  95. ->object($call->unsetArguments())->isIdenticalTo($call)
  96. ->variable($call->getArguments())->isNull()
  97. ;
  98. }
  99. public function testSetDecorator()
  100. {
  101. $this
  102. ->if($call = new testedClass())
  103. ->then
  104. ->object($call->setDecorator($decorator = new decorator()))->isIdenticalTo($call)
  105. ->object($call->getDecorator())->isIdenticalTo($decorator)
  106. ->object($call->setDecorator())->isIdenticalTo($call)
  107. ->object($call->getDecorator())
  108. ->isNotIdenticalTo($decorator)
  109. ->isEqualTo(new decorator())
  110. ;
  111. }
  112. public function testIsEqualTo()
  113. {
  114. $this
  115. ->if($call1 = new testedClass())
  116. ->and($call2 = new testedClass())
  117. ->then
  118. ->boolean($call1->isEqualTo($call2))->isFalse()
  119. ->boolean($call2->isEqualTo($call1))->isFalse()
  120. ->if($call1 = new testedClass(uniqid()))
  121. ->then
  122. ->boolean($call1->isEqualTo($call2))->isFalse()
  123. ->boolean($call2->isEqualTo($call1))->isFalse()
  124. ->if($call2 = new testedClass(uniqid()))
  125. ->then
  126. ->boolean($call1->isEqualTo($call2))->isFalse()
  127. ->boolean($call2->isEqualTo($call1))->isFalse()
  128. ->if($call1 = new testedClass())
  129. ->then
  130. ->boolean($call1->isEqualTo($call2))->isFalse()
  131. ->boolean($call2->isEqualTo($call1))->isFalse()
  132. ->if($call1 = new testedClass($function = uniqid()))
  133. ->and($call2 = new testedClass($function))
  134. ->then
  135. ->boolean($call1->isEqualTo($call2))->isTrue()
  136. ->boolean($call2->isEqualTo($call1))->isTrue()
  137. ->if($call2 = new testedClass(strtoupper($function)))
  138. ->then
  139. ->boolean($call1->isEqualTo($call2))->isTrue()
  140. ->boolean($call2->isEqualTo($call1))->isTrue()
  141. ->if($call1 = new testedClass($function, []))
  142. ->then
  143. ->boolean($call1->isEqualTo($call2))->isFalse()
  144. ->boolean($call2->isEqualTo($call1))->isTrue()
  145. ->if($call2 = new testedClass($function, []))
  146. ->then
  147. ->boolean($call1->isEqualTo($call2))->isTrue()
  148. ->boolean($call2->isEqualTo($call1))->isTrue()
  149. ->if($call1 = new testedClass($function, [$argument = uniqid()]))
  150. ->then
  151. ->boolean($call1->isEqualTo($call2))->isFalse()
  152. ->boolean($call2->isEqualTo($call1))->isFalse()
  153. ->if($call2 = new testedClass($function, [$argument]))
  154. ->then
  155. ->boolean($call1->isEqualTo($call2))->isTrue()
  156. ->boolean($call2->isEqualTo($call1))->isTrue()
  157. ->if($call1 = new testedClass($function, $arguments = [uniqid(), uniqid()]))
  158. ->then
  159. ->boolean($call1->isEqualTo($call2))->isFalse()
  160. ->boolean($call2->isEqualTo($call1))->isFalse()
  161. ->if($call2 = new testedClass($function, $arguments))
  162. ->then
  163. ->boolean($call1->isEqualTo($call2))->isTrue()
  164. ->boolean($call2->isEqualTo($call1))->isTrue()
  165. ->if($call1 = new testedClass($function, $arguments = [$arg1 = uniqid(), $arg2 = uniqid(), $arg3 = new \mock\phpObject()]))
  166. ->then
  167. ->boolean($call1->isEqualTo($call2))->isFalse()
  168. ->boolean($call2->isEqualTo($call1))->isFalse()
  169. ->if($call2 = new testedClass($function, $arguments))
  170. ->then
  171. ->boolean($call1->isEqualTo($call2))->isTrue()
  172. ->boolean($call2->isEqualTo($call1))->isTrue()
  173. ->if($call2 = new testedClass($function, [$arg1, $arg2, clone $arg3]))
  174. ->then
  175. ->boolean($call1->isEqualTo($call2))->isTrue()
  176. ->boolean($call2->isEqualTo($call1))->isTrue()
  177. ->if($call2 = new testedClass($function, [$arg3, $arg2, $arg1]))
  178. ->then
  179. ->boolean($call1->isEqualTo($call2))->isFalse()
  180. ->boolean($call2->isEqualTo($call1))->isFalse()
  181. ->if($call1 = new testedClass($function = uniqid(), [$arg1 = uniqid(), $arg2 = uniqid(), $arg3 = new \mock\phpObject()]))
  182. ->and($call2 = new testedClass($function, [$arg1, $arg2]))
  183. ->then
  184. ->boolean($call1->isEqualTo($call2))->isFalse()
  185. ->boolean($call2->isEqualTo($call1))->isTrue()
  186. ->if($call1 = new testedClass($function))
  187. ->and($call2 = new testedClass($function, [$object = new \mock\phpObject()]))
  188. ->then
  189. ->boolean($call1->isEqualTo($call2))->isTrue()
  190. ->boolean($call2->isEqualTo($call1))->isFalse()
  191. ;
  192. }
  193. public function testIsIdenticalTo()
  194. {
  195. $this
  196. ->if($call1 = new testedClass())
  197. ->and($call2 = new testedClass())
  198. ->then
  199. ->boolean($call1->isIdenticalTo($call2))->isFalse()
  200. ->boolean($call2->isIdenticalTo($call1))->isFalse()
  201. ->if($call1 = new testedClass(uniqid()))
  202. ->then
  203. ->boolean($call1->isIdenticalTo($call2))->isFalse()
  204. ->boolean($call2->isIdenticalTo($call1))->isFalse()
  205. ->if($call2 = new testedClass(uniqid()))
  206. ->then
  207. ->boolean($call1->isIdenticalTo($call2))->isFalse()
  208. ->boolean($call2->isIdenticalTo($call1))->isFalse()
  209. ->if($call1 = new testedClass())
  210. ->then
  211. ->boolean($call1->isIdenticalTo($call2))->isFalse()
  212. ->boolean($call2->isIdenticalTo($call1))->isFalse()
  213. ->if($call1 = new testedClass($function = uniqid()))
  214. ->and($call2 = new testedClass($function))
  215. ->then
  216. ->boolean($call1->isIdenticalTo($call2))->isTrue()
  217. ->boolean($call2->isIdenticalTo($call1))->isTrue()
  218. ->if($call1 = new testedClass($function, []))
  219. ->then
  220. ->boolean($call1->isIdenticalTo($call2))->isFalse()
  221. ->boolean($call2->isIdenticalTo($call1))->isTrue()
  222. ->if($call2 = new testedClass($function, []))
  223. ->then
  224. ->boolean($call1->isIdenticalTo($call2))->isTrue()
  225. ->boolean($call2->isIdenticalTo($call1))->isTrue()
  226. ->if($call1 = new testedClass($function, [$argument = uniqid()]))
  227. ->then
  228. ->boolean($call1->isIdenticalTo($call2))->isFalse()
  229. ->boolean($call2->isIdenticalTo($call1))->isFalse()
  230. ->if($call2 = new testedClass($function, [$argument]))
  231. ->then
  232. ->boolean($call1->isIdenticalTo($call2))->isTrue()
  233. ->boolean($call2->isIdenticalTo($call1))->isTrue()
  234. ->if($call1 = new testedClass($function, $arguments = [uniqid(), uniqid()]))
  235. ->then
  236. ->boolean($call1->isIdenticalTo($call2))->isFalse()
  237. ->boolean($call2->isIdenticalTo($call1))->isFalse()
  238. ->if($call2 = new testedClass($function, $arguments))
  239. ->then
  240. ->boolean($call1->isIdenticalTo($call2))->isTrue()
  241. ->boolean($call2->isIdenticalTo($call1))->isTrue()
  242. ->if($call1 = new testedClass($function, $arguments = [$arg1 = uniqid(), $arg2 = uniqid(), $arg3 = new \mock\phpObject()]))
  243. ->then
  244. ->boolean($call1->isIdenticalTo($call2))->isFalse()
  245. ->boolean($call2->isIdenticalTo($call1))->isFalse()
  246. ->if($call2 = new testedClass($function, $arguments))
  247. ->then
  248. ->boolean($call1->isIdenticalTo($call2))->isTrue()
  249. ->boolean($call2->isIdenticalTo($call1))->isTrue()
  250. ->if($call2 = new testedClass($function, [$arg1, $arg2, clone $arg3]))
  251. ->then
  252. ->boolean($call1->isIdenticalTo($call2))->isFalse()
  253. ->boolean($call2->isIdenticalTo($call1))->isFalse()
  254. ->if($call2 = new testedClass($function, [$arg3, $arg2, $arg1]))
  255. ->then
  256. ->boolean($call1->isIdenticalTo($call2))->isFalse()
  257. ->boolean($call2->isIdenticalTo($call1))->isFalse()
  258. ->if($call1 = new testedClass($function))
  259. ->and($call2 = new testedClass($function, [$object = new \mock\phpObject()]))
  260. ->then
  261. ->boolean($call1->isIdenticalTo($call2))->isTrue()
  262. ->boolean($call2->isIdenticalTo($call1))->isFalse()
  263. ;
  264. }
  265. }