PageRenderTime 56ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/units/classes/asserters/mock.php

http://github.com/mageekguy/atoum
PHP | 1069 lines | 919 code | 150 blank | 0 comment | 0 complexity | 9f5c2c4cbe26e35db9dfacea2c7ed6ad MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\asserters;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\php,
  6. mageekguy\atoum\test,
  7. mageekguy\atoum\asserter,
  8. mageekguy\atoum\tools\variable,
  9. mageekguy\atoum\test\adapter\call\decorators
  10. ;
  11. require_once __DIR__ . '/../../runner.php';
  12. class dummy
  13. {
  14. public function foo($arg) {}
  15. public function bar($arg) {}
  16. public function fooWithSeveralArguments($arg1, $arg2, $arg3, $arg4, $arg5) {}
  17. }
  18. class mock extends atoum\test
  19. {
  20. public function testClass()
  21. {
  22. $this->testedClass->extends('mageekguy\atoum\asserter');
  23. }
  24. public function test__construct()
  25. {
  26. $this
  27. ->then
  28. ->if($this->newTestedInstance)
  29. ->object($this->testedInstance->getGenerator())->isEqualTo(new asserter\generator())
  30. ->object($this->testedInstance->getAnalyzer())->isEqualTo(new variable\analyzer())
  31. ->object($this->testedInstance->getLocale())->isEqualTo(new atoum\locale())
  32. ->object($this->testedInstance->getCall())->isEqualTo(new test\adapter\call())
  33. ->variable($this->testedInstance->getAdapter())->isNull
  34. ->variable($this->testedInstance->getLastAssertionFile())->isNull
  35. ->variable($this->testedInstance->getLastAssertionLine())->isNull
  36. ->if($this->newTestedInstance($generator = new asserter\generator(), $analyzer = new variable\analyzer(), $locale = new atoum\locale()))
  37. ->then
  38. ->object($this->testedInstance->getGenerator())->isIdenticalTo($generator)
  39. ->object($this->testedInstance->getAnalyzer())->isIdenticalTo($analyzer)
  40. ->object($this->testedInstance->getLocale())->isIdenticalTo($locale)
  41. ->object($this->testedInstance->getCall())->isEqualTo(new test\adapter\call())
  42. ->variable($this->testedInstance->getAdapter())->isNull
  43. ->variable($this->testedInstance->getLastAssertionFile())->isNull
  44. ->variable($this->testedInstance->getLastAssertionLine())->isNull
  45. ;
  46. }
  47. public function testReset()
  48. {
  49. $this
  50. ->given(
  51. $mockController = new \mock\mageekguy\atoum\mock\controller(),
  52. $asserter = $this->newTestedInstance
  53. )
  54. ->then
  55. ->object($asserter->reset())->isIdenticalTo($asserter)
  56. ->variable($asserter->getAdapter())->isNull()
  57. ->if(
  58. $asserter->setWith($mock = new \mock\mageekguy\atoum\score()),
  59. $mock->setMockController($mockController),
  60. $this->resetMock($mockController)
  61. )
  62. ->then
  63. ->object($asserter->reset())->isIdenticalTo($asserter)
  64. ->object($asserter->getAdapter())->isIdenticalTo($mock->getMockController())
  65. ->mock($mockController)->call('resetCalls')->once();
  66. }
  67. public function testSetWith()
  68. {
  69. $this
  70. ->given($asserter = $this->newTestedInstance)
  71. ->if($asserter
  72. ->setLocale($locale = new \mock\atoum\locale())
  73. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer()),
  74. $this->calling($locale)->_ = $notMock = uniqid(),
  75. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  76. )
  77. ->then
  78. ->exception(function() use ($asserter, & $mock) { $asserter->setWith($mock = uniqid()); })
  79. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  80. ->hasMessage($notMock)
  81. ->mock($locale)->call('_')->withArguments('%s is not a mock', $type)->once
  82. ->mock($analyzer)->call('getTypeOf')->withArguments($mock)->once
  83. ->object($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\mock()))->isIdenticalTo($asserter)
  84. ->object($asserter->getAdapter())->isIdenticalTo($mock->getMockController())
  85. ;
  86. }
  87. public function testWasCalled()
  88. {
  89. $this
  90. ->if($asserter = $this->newTestedInstance)
  91. ->then
  92. ->exception(function() use ($asserter) { $asserter->wasCalled(); })
  93. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  94. ->hasMessage('Mock is undefined')
  95. ->if($asserter
  96. ->setWith($mock = new \mock\foo($controller = new \mock\atoum\mock\controller()))
  97. ->setLocale($locale = new \mock\atoum\locale()),
  98. $this->calling($locale)->_ = $wasNotCalled = uniqid(),
  99. $this->calling($controller)->getCallsNumber = 0,
  100. $this->calling($controller)->getMockClass = $mockClass = uniqid()
  101. )
  102. ->then
  103. ->exception(function() use ($asserter) { $asserter->wasCalled(); })
  104. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  105. ->hasMessage($wasNotCalled)
  106. ->mock($locale)->call('_')->withArguments('%s is not called', $mockClass)->once
  107. ->exception(function() use ($asserter) { $asserter->wasCalled; })
  108. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  109. ->hasMessage($wasNotCalled)
  110. ->mock($locale)->call('_')->withArguments('%s is not called', $mockClass)->twice
  111. ->exception(function() use ($asserter, & $failMessage) { $asserter->wasCalled($failMessage = uniqid()); })
  112. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  113. ->hasMessage($failMessage)
  114. ->if($this->calling($controller)->getCallsNumber = rand(1, PHP_INT_MAX))
  115. ->then
  116. ->object($asserter->wasCalled())->isIdenticalTo($asserter)
  117. ->object($asserter->wasCalled)->isIdenticalTo($asserter)
  118. ;
  119. }
  120. public function testHasReceivedSomeMessage()
  121. {
  122. $this
  123. ->if($asserter = $this->newTestedInstance)
  124. ->then
  125. ->exception(function() use ($asserter) { $asserter->hasReceivedSomeMessage(); })
  126. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  127. ->hasMessage('Mock is undefined')
  128. ->if($asserter
  129. ->setWith($mock = new \mock\foo($controller = new \mock\atoum\mock\controller()))
  130. ->setLocale($locale = new \mock\atoum\locale()),
  131. $this->calling($locale)->_ = $didNotReceiveAnyMessage = uniqid(),
  132. $this->calling($controller)->getCallsNumber = 0,
  133. $this->calling($controller)->getMockClass = $mockClass = uniqid()
  134. )
  135. ->then
  136. ->exception(function() use ($asserter) { $asserter->hasReceivedSomeMessage(); })
  137. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  138. ->hasMessage($didNotReceiveAnyMessage)
  139. ->mock($locale)->call('_')->withArguments('%s did not receive any message', $mockClass)->once
  140. ->exception(function() use ($asserter) { $asserter->hasReceivedSomeMessage; })
  141. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  142. ->hasMessage($didNotReceiveAnyMessage)
  143. ->mock($locale)->call('_')->withArguments('%s did not receive any message', $mockClass)->twice
  144. ->exception(function() use ($asserter, & $failMessage) { $asserter->hasReceivedSomeMessage($failMessage = uniqid()); })
  145. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  146. ->hasMessage($failMessage)
  147. ->if($this->calling($controller)->getCallsNumber = rand(1, PHP_INT_MAX))
  148. ->then
  149. ->object($asserter->hasReceivedSomeMessage())->isIdenticalTo($asserter)
  150. ->object($asserter->hasReceivedSomeMessage)->isIdenticalTo($asserter)
  151. ;
  152. }
  153. public function testWasNotCalled()
  154. {
  155. $this
  156. ->if($asserter = $this->newTestedInstance)
  157. ->then
  158. ->exception(function() use ($asserter) { $asserter->wasNotCalled(); })
  159. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  160. ->hasMessage('Mock is undefined')
  161. ->if($asserter
  162. ->setWith($mock = new \mock\foo($controller = new \mock\atoum\mock\controller()))
  163. ->setLocale($locale = new \mock\atoum\locale()),
  164. $this->calling($locale)->_ = $wasCalled = uniqid(),
  165. $this->calling($controller)->getCallsNumber = rand(1, PHP_INT_MAX),
  166. $this->calling($controller)->getMockClass = $mockClass = uniqid()
  167. )
  168. ->then
  169. ->exception(function() use ($asserter) { $asserter->wasNotCalled(); })
  170. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  171. ->hasMessage($wasCalled)
  172. ->mock($locale)->call('_')->withArguments('%s is called', $mockClass)->once
  173. ->exception(function() use ($asserter) { $asserter->wasNotCalled; })
  174. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  175. ->hasMessage($wasCalled)
  176. ->mock($locale)->call('_')->withArguments('%s is called', $mockClass)->twice
  177. ->exception(function() use ($asserter, & $failMessage) { $asserter->wasNotCalled($failMessage = uniqid()); })
  178. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  179. ->hasMessage($failMessage)
  180. ->if($this->calling($controller)->getCallsNumber = 0)
  181. ->then
  182. ->object($asserter->wasNotCalled())->isIdenticalTo($asserter)
  183. ->object($asserter->wasNotCalled)->isIdenticalTo($asserter)
  184. ;
  185. }
  186. public function testDidNotReceiveAnyMessage()
  187. {
  188. $this
  189. ->if($asserter = $this->newTestedInstance)
  190. ->then
  191. ->exception(function() use ($asserter) { $asserter->didNotReceiveAnyMessage(); })
  192. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  193. ->hasMessage('Mock is undefined')
  194. ->if($asserter
  195. ->setWith($mock = new \mock\foo($controller = new \mock\atoum\mock\controller()))
  196. ->setLocale($locale = new \mock\atoum\locale()),
  197. $this->calling($locale)->_ = $hasReceivedMessage = uniqid(),
  198. $this->calling($controller)->getCallsNumber = rand(1, PHP_INT_MAX),
  199. $this->calling($controller)->getMockClass = $mockClass = uniqid()
  200. )
  201. ->then
  202. ->exception(function() use ($asserter) { $asserter->didNotReceiveAnyMessage(); })
  203. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  204. ->hasMessage($hasReceivedMessage)
  205. ->mock($locale)->call('_')->withArguments('%s receive some message', $mockClass)->once
  206. ->exception(function() use ($asserter) { $asserter->didNotReceiveAnyMessage; })
  207. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  208. ->hasMessage($hasReceivedMessage)
  209. ->mock($locale)->call('_')->withArguments('%s receive some message', $mockClass)->twice
  210. ->exception(function() use ($asserter, & $failMessage) { $asserter->didNotReceiveAnyMessage($failMessage = uniqid()); })
  211. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  212. ->hasMessage($failMessage)
  213. ->if($this->calling($controller)->getCallsNumber = 0)
  214. ->then
  215. ->object($asserter->didNotReceiveAnyMessage())->isIdenticalTo($asserter)
  216. ->object($asserter->didNotReceiveAnyMessage)->isIdenticalTo($asserter)
  217. ;
  218. }
  219. public function testCall()
  220. {
  221. $this
  222. ->given($asserter = $this->newTestedInstance)
  223. ->then
  224. ->exception(function() use ($asserter) { $asserter->call(uniqid()); })
  225. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  226. ->hasMessage('Mock is undefined')
  227. ->given(
  228. $asserter->setManager($manager = new \mock\atoum\asserters\adapter\call\manager()),
  229. $mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()),
  230. $this->calling($mockController)->getMockClass = $mockClass = uniqid()
  231. )
  232. ->if($asserter->setWith($mock))
  233. ->then
  234. ->object($asserter->call($function = uniqid()))->isIdenticalTo($asserter)
  235. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  236. ->integer($asserter->getLastAssertionLine())->isEqualTo(__LINE__ - 2)
  237. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, null, new decorators\addClass($mockClass)))
  238. ->array($asserter->getBefore())->isEmpty
  239. ->array($asserter->getAfter())->isEmpty
  240. ->mock($manager)->call('add')->withArguments($asserter)->once
  241. ->object($asserter->call($otherFunction = uniqid()))->isIdenticalTo($asserter)
  242. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  243. ->integer($asserter->getLastAssertionLine())->isEqualTo(__LINE__ - 2)
  244. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($otherFunction, null, new decorators\addClass($mockClass)))
  245. ->array($asserter->getBefore())->isEmpty
  246. ->array($asserter->getAfter())->isEmpty
  247. ->mock($manager)->call('add')->withArguments($asserter)->twice
  248. ;
  249. }
  250. public function testReceive()
  251. {
  252. $this
  253. ->given($asserter = $this->newTestedInstance)
  254. ->then
  255. ->exception(function() use ($asserter) { $asserter->receive(uniqid()); })
  256. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  257. ->hasMessage('Mock is undefined')
  258. ->given(
  259. $asserter->setManager($manager = new \mock\atoum\asserters\adapter\call\manager()),
  260. $mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()),
  261. $this->calling($mockController)->getMockClass = $mockClass = uniqid()
  262. )
  263. ->if($asserter->setWith($mock))
  264. ->then
  265. ->object($asserter->receive($function = uniqid()))->isIdenticalTo($asserter)
  266. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  267. ->integer($asserter->getLastAssertionLine())->isEqualTo(__LINE__ - 2)
  268. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, null, new decorators\addClass($mockClass)))
  269. ->array($asserter->getBefore())->isEmpty
  270. ->array($asserter->getAfter())->isEmpty
  271. ->mock($manager)->receive('add')->withArguments($asserter)->once
  272. ->object($asserter->receive($otherFunction = uniqid()))->isIdenticalTo($asserter)
  273. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  274. ->integer($asserter->getLastAssertionLine())->isEqualTo(__LINE__ - 2)
  275. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($otherFunction, null, new decorators\addClass($mockClass)))
  276. ->array($asserter->getBefore())->isEmpty
  277. ->array($asserter->getAfter())->isEmpty
  278. ->mock($manager)->receive('add')->withArguments($asserter)->twice
  279. ;
  280. }
  281. public function testWithArguments()
  282. {
  283. $this
  284. ->given($asserter = $this->newTestedInstance)
  285. ->then
  286. ->exception(function() use ($asserter) { $asserter->withArguments(); })
  287. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  288. ->hasMessage('Mock is undefined')
  289. ->given(
  290. $mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()),
  291. $this->calling($mockController)->getMockClass = $mockClass = uniqid()
  292. )
  293. ->if($asserter->setWith($mock))
  294. ->then
  295. ->exception(function() use ($asserter) { $asserter->withArguments(); })
  296. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  297. ->hasMessage('Call is undefined')
  298. ->if(
  299. $asserter->setManager($manager = new \mock\atoum\asserters\adapter\call\manager()),
  300. $asserter->call($function = uniqid())
  301. )
  302. ->then
  303. ->object($asserter->withArguments())->isIdenticalTo($asserter)
  304. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  305. ->integer($asserter->getLastAssertionLine())->isEqualTo(__LINE__ - 2)
  306. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, array(), new decorators\addClass($mockClass)))
  307. ->array($asserter->getBefore())->isEmpty
  308. ->array($asserter->getAfter())->isEmpty
  309. ->mock($manager)->call('add')->withArguments($asserter)->once
  310. ->object($asserter->withArguments($arg1 = uniqid()))->isIdenticalTo($asserter)
  311. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  312. ->integer($asserter->getLastAssertionLine())->isEqualTo(__LINE__ - 2)
  313. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, array($arg1), new decorators\addClass($mockClass)))
  314. ->array($asserter->getBefore())->isEmpty
  315. ->array($asserter->getAfter())->isEmpty
  316. ->mock($manager)->call('add')->withArguments($asserter)->once
  317. ->object($asserter->withArguments($arg1 = uniqid(), $arg2 = uniqid()))->isIdenticalTo($asserter)
  318. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  319. ->integer($asserter->getLastAssertionLine())->isEqualTo($line = __LINE__ - 2)
  320. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, array($arg1, $arg2), new decorators\addClass($mockClass)))
  321. ->array($asserter->getBefore())->isEmpty
  322. ->array($asserter->getAfter())->isEmpty
  323. ->mock($manager)->call('add')->withArguments($asserter)->once
  324. ;
  325. }
  326. public function testWithAtLeastArguments()
  327. {
  328. $this
  329. ->given($asserter = $this->newTestedInstance)
  330. ->then
  331. ->exception(function() use ($asserter) { $asserter->withAtLeastArguments(array(uniqid())); })
  332. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  333. ->hasMessage('Mock is undefined')
  334. ->given(
  335. $mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()),
  336. $this->calling($mockController)->getMockClass = $mockClass = uniqid()
  337. )
  338. ->if($asserter->setWith($mock))
  339. ->then
  340. ->exception(function() use ($asserter) { $asserter->withAtLeastArguments(array(uniqid())); })
  341. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  342. ->hasMessage('Call is undefined')
  343. ->if(
  344. $asserter->setManager($manager = new \mock\atoum\asserters\adapter\call\manager()),
  345. $asserter->call($function = uniqid())
  346. )
  347. ->then
  348. ->object($asserter->withAtLeastArguments($arguments = array(1 => uniqid())))->isIdenticalTo($asserter)
  349. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  350. ->integer($asserter->getLastAssertionLine())->isEqualTo($line = __LINE__ - 2)
  351. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, $arguments, new decorators\addClass($mockClass)))
  352. ->array($asserter->getBefore())->isEmpty
  353. ->array($asserter->getAfter())->isEmpty
  354. ->mock($manager)->call('add')->withArguments($asserter)->once
  355. ->object($asserter->disableEvaluationChecking()->withAtLeastArguments($arguments = array(2 => uniqid(), 5 => uniqid())))->isIdenticalTo($asserter)
  356. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  357. ->integer($asserter->getLastAssertionLine())->isEqualTo($line = __LINE__ - 2)
  358. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, $arguments, new decorators\addClass($mockClass)))
  359. ->array($asserter->getBefore())->isEmpty
  360. ->array($asserter->getAfter())->isEmpty
  361. ->mock($manager)->call('add')->withArguments($asserter)->once
  362. ;
  363. }
  364. public function testWithAnyArguments()
  365. {
  366. $this
  367. ->given($asserter = $this->newTestedInstance)
  368. ->then
  369. ->exception(function() use ($asserter) { $asserter->withAnyArguments(); })
  370. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  371. ->hasMessage('Mock is undefined')
  372. ->exception(function() use ($asserter) { $asserter->withAnyArguments; })
  373. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  374. ->hasMessage('Mock is undefined')
  375. ->exception(function() use ($asserter) { $asserter->WITHaNYaRGUMENts; })
  376. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  377. ->hasMessage('Mock is undefined')
  378. ->given(
  379. $mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()),
  380. $this->calling($mockController)->getMockClass = $mockClass = uniqid()
  381. )
  382. ->if($asserter->setWith($mock))
  383. ->then
  384. ->exception(function() use ($asserter) { $asserter->withAnyArguments(); })
  385. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  386. ->hasMessage('Call is undefined')
  387. ->exception(function() use ($asserter) { $asserter->withAnyArguments; })
  388. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  389. ->hasMessage('Call is undefined')
  390. ->exception(function() use ($asserter) { $asserter->wITHaNYArguments; })
  391. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  392. ->hasMessage('Call is undefined')
  393. ->if(
  394. $asserter->setManager($manager = new \mock\atoum\asserters\adapter\call\manager()),
  395. $asserter->call($function = uniqid())
  396. )
  397. ->then
  398. ->object($asserter->withAnyArguments())->isIdenticalTo($asserter)
  399. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  400. ->integer($asserter->getLastAssertionLine())->isEqualTo($line = __LINE__ - 2)
  401. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, null, new decorators\addClass($mockClass)))
  402. ->array($asserter->getBefore())->isEmpty
  403. ->array($asserter->getAfter())->isEmpty
  404. ->mock($manager)->call('add')->withArguments($asserter)->once
  405. ->object($asserter->withAnyArguments)->isIdenticalTo($asserter)
  406. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  407. ->integer($asserter->getLastAssertionLine())->isEqualTo($line = __LINE__ - 2)
  408. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, null, new decorators\addClass($mockClass)))
  409. ->array($asserter->getBefore())->isEmpty
  410. ->array($asserter->getAfter())->isEmpty
  411. ->mock($manager)->call('add')->withArguments($asserter)->once
  412. ->if($asserter->withArguments(uniqid()))
  413. ->then
  414. ->object($asserter->withAnyArguments())->isIdenticalTo($asserter)
  415. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  416. ->integer($asserter->getLastAssertionLine())->isEqualTo($line = __LINE__ - 2)
  417. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, null, new decorators\addClass($mockClass)))
  418. ->array($asserter->getBefore())->isEmpty
  419. ->array($asserter->getAfter())->isEmpty
  420. ->mock($manager)->call('add')->withArguments($asserter)->once
  421. ->if($asserter->withArguments(uniqid()))
  422. ->then
  423. ->object($asserter->withAnyArguments)->isIdenticalTo($asserter)
  424. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  425. ->integer($asserter->getLastAssertionLine())->isEqualTo($line = __LINE__ - 2)
  426. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, null, new decorators\addClass($mockClass)))
  427. ->array($asserter->getBefore())->isEmpty
  428. ->array($asserter->getAfter())->isEmpty
  429. ->mock($manager)->call('add')->withArguments($asserter)->once
  430. ;
  431. }
  432. public function testWithoutAnyArgument()
  433. {
  434. $this
  435. ->given($asserter = $this->newTestedInstance)
  436. ->then
  437. ->exception(function() use ($asserter) { $asserter->withoutAnyArgument(); })
  438. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  439. ->hasMessage('Mock is undefined')
  440. ->exception(function() use ($asserter) { $asserter->withoutAnyArgument; })
  441. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  442. ->hasMessage('Mock is undefined')
  443. ->exception(function() use ($asserter) { $asserter->witHOUTaNYaRGument; })
  444. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  445. ->hasMessage('Mock is undefined')
  446. ->given(
  447. $mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()),
  448. $this->calling($mockController)->getMockClass = $mockClass = uniqid()
  449. )
  450. ->if($asserter->setWith($mock))
  451. ->then
  452. ->exception(function() use ($asserter) { $asserter->withoutAnyArgument(); })
  453. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  454. ->hasMessage('Call is undefined')
  455. ->exception(function() use ($asserter) { $asserter->withoutAnyArgument; })
  456. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  457. ->hasMessage('Call is undefined')
  458. ->exception(function() use ($asserter) { $asserter->withoUTaNyArgumENT; })
  459. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  460. ->hasMessage('Call is undefined')
  461. ->if(
  462. $asserter->setManager($manager = new \mock\atoum\asserters\adapter\call\manager()),
  463. $asserter->call($function = uniqid())
  464. )
  465. ->then
  466. ->object($asserter->withoutAnyArgument())->isIdenticalTo($asserter)
  467. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  468. ->integer($asserter->getLastAssertionLine())->isEqualTo($line = __LINE__ - 2)
  469. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, array(), new decorators\addClass($mockClass)))
  470. ->array($asserter->getBefore())->isEmpty
  471. ->array($asserter->getAfter())->isEmpty
  472. ->mock($manager)->call('add')->withArguments($asserter)->once
  473. ->object($asserter->withoutAnyArgument)->isIdenticalTo($asserter)
  474. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  475. ->integer($asserter->getLastAssertionLine())->isEqualTo($line = __LINE__ - 2)
  476. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, array(), new decorators\addClass($mockClass)))
  477. ->array($asserter->getBefore())->isEmpty
  478. ->array($asserter->getAfter())->isEmpty
  479. ->mock($manager)->call('add')->withArguments($asserter)->once
  480. ->object($asserter->wITHOUTaNYaRGument)->isIdenticalTo($asserter)
  481. ->string($asserter->getLastAssertionFile())->isEqualTo(__FILE__)
  482. ->integer($asserter->getLastAssertionLine())->isEqualTo($line = __LINE__ - 2)
  483. ->object($asserter->getCall())->isEqualTo(new test\adapter\call($function, array(), new decorators\addClass($mockClass)))
  484. ->array($asserter->getBefore())->isEmpty
  485. ->array($asserter->getAfter())->isEmpty
  486. ->mock($manager)->call('add')->withArguments($asserter)->once
  487. ;
  488. }
  489. public function testNever()
  490. {
  491. $this
  492. ->given($asserter = $this->newTestedInstance)
  493. ->then
  494. ->exception(function() use ($asserter) { $asserter->never(); })
  495. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  496. ->hasMessage('Mock is undefined')
  497. ->exception(function() use ($asserter) { $asserter->never; })
  498. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  499. ->hasMessage('Mock is undefined')
  500. ->exception(function() use ($asserter) { $asserter->NEVEr; })
  501. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  502. ->hasMessage('Mock is undefined')
  503. ->given($mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()))
  504. ->if($asserter->setWith($mock))
  505. ->then
  506. ->exception(function() use ($asserter) { $asserter->never(); })
  507. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  508. ->hasMessage('Call is undefined')
  509. ->exception(function() use ($asserter) { $asserter->never; })
  510. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  511. ->hasMessage('Call is undefined')
  512. ->exception(function() use ($asserter) { $asserter->nEVER; })
  513. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  514. ->hasMessage('Call is undefined')
  515. ->if(
  516. $asserter
  517. ->call(uniqid())
  518. ->setCall($call = new \mock\atoum\test\adapter\call())
  519. ->setLocale($locale = new \mock\atoum\locale()),
  520. $this->calling($mockController)->getCalls = $calls = new \mock\atoum\test\adapter\calls(),
  521. $this->calling($calls)->count = $number = rand(1, PHP_INT_MAX),
  522. $this->calling($call)->__toString = $callAsString = uniqid(),
  523. $this->calling($locale)->__ = $notCalled = uniqid()
  524. )
  525. ->then
  526. ->exception(function() use ($asserter) { $asserter->never(); })
  527. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  528. ->hasMessage($notCalled)
  529. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 0)->once
  530. ->exception(function() use ($asserter, & $failMessage) { $asserter->once($failMessage = uniqid()); })
  531. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  532. ->hasMessage($failMessage)
  533. ->exception(function() use ($asserter) { $asserter->never; })
  534. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  535. ->hasMessage($notCalled)
  536. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 0)->twice
  537. ->exception(function() use ($asserter) { $asserter->nEVER; })
  538. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  539. ->hasMessage($notCalled)
  540. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 0)->thrice
  541. ->if($this->calling($calls)->count = 0)
  542. ->then
  543. ->object($this->testedInstance->never())->isTestedInstance
  544. ->object($this->testedInstance->never)->isTestedInstance
  545. ->object($this->testedInstance->nEVer)->isTestedInstance
  546. ;
  547. }
  548. public function testOnce()
  549. {
  550. $this
  551. ->given($asserter = $this->newTestedInstance)
  552. ->then
  553. ->exception(function() use ($asserter) { $asserter->once(); })
  554. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  555. ->hasMessage('Mock is undefined')
  556. ->exception(function() use ($asserter) { $asserter->once; })
  557. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  558. ->hasMessage('Mock is undefined')
  559. ->exception(function() use ($asserter) { $asserter->oNCE; })
  560. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  561. ->hasMessage('Mock is undefined')
  562. ->given($mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()))
  563. ->if($asserter->setWith($mock))
  564. ->then
  565. ->exception(function() use ($asserter) { $asserter->once(); })
  566. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  567. ->hasMessage('Call is undefined')
  568. ->exception(function() use ($asserter) { $asserter->once; })
  569. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  570. ->hasMessage('Call is undefined')
  571. ->exception(function() use ($asserter) { $asserter->oNCE; })
  572. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  573. ->hasMessage('Call is undefined')
  574. ->if(
  575. $asserter
  576. ->call(uniqid())
  577. ->setCall($call = new \mock\atoum\test\adapter\call())
  578. ->setLocale($locale = new \mock\atoum\locale()),
  579. $this->calling($mockController)->getCalls = $calls = new \mock\atoum\test\adapter\calls(),
  580. $this->calling($calls)->count = 0,
  581. $this->calling($call)->__toString = $callAsString = uniqid(),
  582. $this->calling($locale)->__ = $notCalled = uniqid()
  583. )
  584. ->then
  585. ->exception(function() use ($asserter) { $asserter->once(); })
  586. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  587. ->hasMessage($notCalled)
  588. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', 0, $callAsString, 0, 1)->once
  589. ->exception(function() use ($asserter, & $failMessage) { $asserter->once($failMessage = uniqid()); })
  590. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  591. ->hasMessage($failMessage)
  592. ->exception(function() use ($asserter) { $asserter->once; })
  593. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  594. ->hasMessage($notCalled)
  595. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', 0, $callAsString, 0, 1)->twice
  596. ->exception(function() use ($asserter) { $asserter->oNCE; })
  597. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  598. ->hasMessage($notCalled)
  599. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', 0, $callAsString, 0, 1)->thrice
  600. ->if($this->calling($calls)->count = $number = rand(2, PHP_INT_MAX))
  601. ->then
  602. ->exception(function() use ($asserter) { $asserter->once(); })
  603. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  604. ->hasMessage($notCalled)
  605. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 1)->once
  606. ->exception(function() use ($asserter, & $failMessage) { $asserter->once($failMessage = uniqid()); })
  607. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  608. ->hasMessage($failMessage)
  609. ->exception(function() use ($asserter) { $asserter->once; })
  610. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  611. ->hasMessage($notCalled)
  612. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 1)->twice
  613. ->exception(function() use ($asserter) { $asserter->oNCE; })
  614. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  615. ->hasMessage($notCalled)
  616. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 1)->thrice
  617. ->if($this->calling($calls)->count = 1)
  618. ->then
  619. ->object($this->testedInstance->once())->isTestedInstance
  620. ->object($this->testedInstance->once)->isTestedInstance
  621. ->object($this->testedInstance->oNCE)->isTestedInstance
  622. ;
  623. }
  624. public function testTwice()
  625. {
  626. $this
  627. ->given($asserter = $this->newTestedInstance)
  628. ->then
  629. ->exception(function() use ($asserter) { $asserter->twice(); })
  630. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  631. ->hasMessage('Mock is undefined')
  632. ->exception(function() use ($asserter) { $asserter->twice; })
  633. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  634. ->hasMessage('Mock is undefined')
  635. ->exception(function() use ($asserter) { $asserter->tWICe; })
  636. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  637. ->hasMessage('Mock is undefined')
  638. ->given($mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()))
  639. ->if($asserter->setWith($mock))
  640. ->then
  641. ->exception(function() use ($asserter) { $asserter->twice(); })
  642. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  643. ->hasMessage('Call is undefined')
  644. ->exception(function() use ($asserter) { $asserter->twice; })
  645. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  646. ->hasMessage('Call is undefined')
  647. ->exception(function() use ($asserter) { $asserter->TWICe; })
  648. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  649. ->hasMessage('Call is undefined')
  650. ->if(
  651. $asserter
  652. ->call(uniqid())
  653. ->setCall($call = new \mock\atoum\test\adapter\call())
  654. ->setLocale($locale = new \mock\atoum\locale()),
  655. $this->calling($mockController)->getCalls = $calls = new \mock\atoum\test\adapter\calls(),
  656. $this->calling($calls)->count = 0,
  657. $this->calling($call)->__toString = $callAsString = uniqid(),
  658. $this->calling($locale)->__ = $notCalled = uniqid()
  659. )
  660. ->then
  661. ->exception(function() use ($asserter) { $asserter->twice(); })
  662. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  663. ->hasMessage($notCalled)
  664. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', 0, $callAsString, 0, 2)->once
  665. ->exception(function() use ($asserter, & $failMessage) { $asserter->twice($failMessage = uniqid()); })
  666. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  667. ->hasMessage($failMessage)
  668. ->exception(function() use ($asserter) { $asserter->twice; })
  669. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  670. ->hasMessage($notCalled)
  671. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', 0, $callAsString, 0, 2)->twice
  672. ->exception(function() use ($asserter) { $asserter->tWiCE; })
  673. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  674. ->hasMessage($notCalled)
  675. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', 0, $callAsString, 0, 2)->thrice
  676. ->if($this->calling($calls)->count = $number = rand(3, PHP_INT_MAX))
  677. ->then
  678. ->exception(function() use ($asserter) { $asserter->twice(); })
  679. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  680. ->hasMessage($notCalled)
  681. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 2)->once
  682. ->exception(function() use ($asserter, & $failMessage) { $asserter->twice($failMessage = uniqid()); })
  683. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  684. ->hasMessage($failMessage)
  685. ->exception(function() use ($asserter) { $asserter->twice; })
  686. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  687. ->hasMessage($notCalled)
  688. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 2)->twice
  689. ->exception(function() use ($asserter) { $asserter->tWICE; })
  690. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  691. ->hasMessage($notCalled)
  692. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 2)->thrice
  693. ->if($this->calling($calls)->count = $number = 1)
  694. ->then
  695. ->exception(function() use ($asserter) { $asserter->twice(); })
  696. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  697. ->hasMessage($notCalled)
  698. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, 1, 2)->once
  699. ->exception(function() use ($asserter, & $failMessage) { $asserter->twice($failMessage = uniqid()); })
  700. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  701. ->hasMessage($failMessage)
  702. ->exception(function() use ($asserter) { $asserter->twice; })
  703. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  704. ->hasMessage($notCalled)
  705. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, 1, 2)->twice
  706. ->exception(function() use ($asserter) { $asserter->tWICE; })
  707. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  708. ->hasMessage($notCalled)
  709. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, 1, 2)->thrice
  710. ->if($this->calling($calls)->count = 2)
  711. ->then
  712. ->object($this->testedInstance->twice())->isTestedInstance
  713. ->object($this->testedInstance->twice)->isTestedInstance
  714. ->object($this->testedInstance->tWICE)->isTestedInstance
  715. ;
  716. }
  717. public function testThrice()
  718. {
  719. $this
  720. ->given($asserter = $this->newTestedInstance)
  721. ->then
  722. ->exception(function() use ($asserter) { $asserter->thrice(); })
  723. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  724. ->hasMessage('Mock is undefined')
  725. ->exception(function() use ($asserter) { $asserter->thrice; })
  726. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  727. ->hasMessage('Mock is undefined')
  728. ->exception(function() use ($asserter) { $asserter->tHRICe; })
  729. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  730. ->hasMessage('Mock is undefined')
  731. ->given($mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()))
  732. ->if($asserter->setWith($mock))
  733. ->then
  734. ->exception(function() use ($asserter) { $asserter->thrice(); })
  735. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  736. ->hasMessage('Call is undefined')
  737. ->exception(function() use ($asserter) { $asserter->thrice; })
  738. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  739. ->hasMessage('Call is undefined')
  740. ->exception(function() use ($asserter) { $asserter->THRICe; })
  741. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  742. ->hasMessage('Call is undefined')
  743. ->if(
  744. $asserter
  745. ->call(uniqid())
  746. ->setCall($call = new \mock\atoum\test\adapter\call())
  747. ->setLocale($locale = new \mock\atoum\locale()),
  748. $this->calling($mockController)->getCalls = $calls = new \mock\atoum\test\adapter\calls(),
  749. $this->calling($calls)->count = 0,
  750. $this->calling($call)->__toString = $callAsString = uniqid(),
  751. $this->calling($locale)->__ = $notCalled = uniqid()
  752. )
  753. ->then
  754. ->exception(function() use ($asserter) { $asserter->thrice(); })
  755. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  756. ->hasMessage($notCalled)
  757. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', 0, $callAsString, 0, 3)->once
  758. ->exception(function() use ($asserter, & $failMessage) { $asserter->thrice($failMessage = uniqid()); })
  759. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  760. ->hasMessage($failMessage)
  761. ->exception(function() use ($asserter) { $asserter->thrice; })
  762. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  763. ->hasMessage($notCalled)
  764. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', 0, $callAsString, 0, 3)->twice
  765. ->exception(function() use ($asserter) { $asserter->tHRICE; })
  766. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  767. ->hasMessage($notCalled)
  768. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', 0, $callAsString, 0, 3)->thrice
  769. ->if($this->calling($calls)->count = $number = rand(4, PHP_INT_MAX))
  770. ->then
  771. ->exception(function() use ($asserter) { $asserter->thrice(); })
  772. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  773. ->hasMessage($notCalled)
  774. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 3)->once
  775. ->exception(function() use ($asserter, & $failMessage) { $asserter->thrice($failMessage = uniqid()); })
  776. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  777. ->hasMessage($failMessage)
  778. ->exception(function() use ($asserter) { $asserter->thrice; })
  779. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  780. ->hasMessage($notCalled)
  781. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 3)->twice
  782. ->exception(function() use ($asserter) { $asserter->tHRICe; })
  783. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  784. ->hasMessage($notCalled)
  785. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 3)->thrice
  786. ->if($this->calling($calls)->count = $number = rand(1, 2))
  787. ->then
  788. ->exception(function() use ($asserter) { $asserter->thrice(); })
  789. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  790. ->hasMessage($notCalled)
  791. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 3)->once
  792. ->exception(function() use ($asserter, & $failMessage) { $asserter->thrice($failMessage = uniqid()); })
  793. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  794. ->hasMessage($failMessage)
  795. ->exception(function() use ($asserter) { $asserter->thrice; })
  796. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  797. ->hasMessage($notCalled)
  798. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 3)->twice
  799. ->exception(function() use ($asserter) { $asserter->tHRICe; })
  800. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  801. ->hasMessage($notCalled)
  802. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $number, $callAsString, $number, 3)->thrice
  803. ->if($this->calling($calls)->count = 3)
  804. ->then
  805. ->object($this->testedInstance->thrice())->isTestedInstance
  806. ->object($this->testedInstance->thrice)->isTestedInstance
  807. ->object($this->testedInstance->thRICE)->isTestedInstance
  808. ;
  809. }
  810. public function testAtLeastOnce()
  811. {
  812. $this
  813. ->given($asserter = $this->newTestedInstance)
  814. ->then
  815. ->exception(function() use ($asserter) { $asserter->atLeastOnce(); })
  816. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  817. ->hasMessage('Mock is undefined')
  818. ->exception(function() use ($asserter) { $asserter->atLeastOnce; })
  819. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  820. ->hasMessage('Mock is undefined')
  821. ->exception(function() use ($asserter) { $asserter->ATlEASToNCe; })
  822. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  823. ->hasMessage('Mock is undefined')
  824. ->given($mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()))
  825. ->if($asserter->setWith($mock))
  826. ->then
  827. ->exception(function() use ($asserter) { $asserter->atLeastOnce(); })
  828. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  829. ->hasMessage('Call is undefined')
  830. ->exception(function() use ($asserter) { $asserter->atLeastOnce; })
  831. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  832. ->hasMessage('Call is undefined')
  833. ->exception(function() use ($asserter) { $asserter->ATlEASToNCe; })
  834. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  835. ->hasMessage('Call is undefined')
  836. ->if(
  837. $asserter
  838. ->call(uniqid())
  839. ->setCall($call = new \mock\atoum\test\adapter\call())
  840. ->setLocale($locale = new \mock\atoum\locale()),
  841. $this->calling($mockController)->getCalls = $calls = new \mock\atoum\test\adapter\calls(),
  842. $this->calling($calls)->count = 0,
  843. $this->calling($call)->__toString = $callAsString = uniqid(),
  844. $this->calling($locale)->_ = $notCalled = uniqid()
  845. )
  846. ->then
  847. ->exception(function() use ($asserter) { $asserter->atLeastOnce(); })
  848. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  849. ->hasMessage($notCalled)
  850. ->mock($locale)->call('_')->withArguments('%s is called 0 time', $callAsString)->once
  851. ->exception(function() use ($asserter) { $asserter->atLeastOnce; })
  852. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  853. ->hasMessage($notCalled)
  854. ->mock($locale)->call('_')->withArguments('%s is called 0 time', $callAsString)->twice
  855. ->exception(function() use ($asserter) { $asserter->atLEASToNCE; })
  856. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  857. ->hasMessage($notCalled)
  858. ->mock($locale)->call('_')->withArguments('%s is called 0 time', $callAsString)->thrice
  859. ->exception(function() use ($asserter, & $failMessage) { $asserter->atLeastOnce($failMessage = uniqid()); })
  860. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  861. ->hasMessage($failMessage)
  862. ->if($this->calling($calls)->count = rand(1, PHP_INT_MAX))
  863. ->then
  864. ->object($this->testedInstance->atLeastOnce())->isTestedInstance
  865. ->object($this->testedInstance->atLeastOnce)->isTestedInstance
  866. ->object($this->testedInstance->atLEASToNCe)->isTestedInstance
  867. ;
  868. }
  869. public function testExactly()
  870. {
  871. $this
  872. ->given($asserter = $this->newTestedInstance)
  873. ->then
  874. ->exception(function() use ($asserter) { $asserter->exactly(rand(0, PHP_INT_MAX)); })
  875. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  876. ->hasMessage('Mock is undefined')
  877. ->given($mock = new \mock\foo($mockController = new \mock\atoum\mock\controller()))
  878. ->if($asserter->setWith($mock))
  879. ->then
  880. ->exception(function() use ($asserter) { $asserter->exactly(rand(0, PHP_INT_MAX)); })
  881. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  882. ->hasMessage('Call is undefined')
  883. ->if(
  884. $asserter
  885. ->call(uniqid())
  886. ->setCall($call = new \mock\atoum\test\adapter\call())
  887. ->setLocale($locale = new \mock\atoum\locale()),
  888. $this->calling($mockController)->getCalls = $calls = new \mock\atoum\test\adapter\calls(),
  889. $this->calling($calls)->count = 0,
  890. $this->calling($call)->__toString = $callAsString = uniqid(),
  891. $this->calling($locale)->__ = $notCalled = uniqid()
  892. )
  893. ->then
  894. ->exception(function() use ($asserter, & $callNumber) { $asserter->exactly($callNumber = rand(1, PHP_INT_MAX)); })
  895. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  896. ->hasMessage($notCalled)
  897. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', 0, $callAsString, 0, $callNumber)->once
  898. ->exception(function() use ($asserter, & $callNumber, & $failMessage) { $asserter->exactly($callNumber = rand(1, PHP_INT_MAX), $failMessage = uniqid()); })
  899. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  900. ->hasMessage($failMessage)
  901. ->object($this->testedInstance->exactly(0))->isTestedInstance
  902. ->if(
  903. $this->calling($calls)->count = $count = rand(1, PHP_INT_MAX),
  904. $this->calling($mockController)->getCallsEqualTo = $callsEqualTo = new \mock\atoum\test\adapter\calls(),
  905. $this->calling($callsEqualTo)->count = $count,
  906. $this->calling($callsEqualTo)->__toString = $callsEqualToAsString = uniqid()
  907. )
  908. ->then
  909. ->exception(function() use ($asserter) { $asserter->exactly(0); })
  910. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  911. ->hasMessage($notCalled . PHP_EOL . $callsEqualToAsString)
  912. ->mock($locale)->call('__')->withArguments('%s is called %d time instead of %d', '%s is called %d times instead of %d', $count, $callAsString, $count, 0)->once
  913. ->exception(function() use ($asserter, & $failMessage) { $asserter->exactly(0, $failMessage = uniqid()); })
  914. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  915. ->hasMessage($failMessage)
  916. ->object($this->testedInstance->exactly($count))->isTestedInstance
  917. ;
  918. }
  919. }