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

/tests/units/classes/asserters/variable.php

http://github.com/mageekguy/atoum
PHP | 626 lines | 558 code | 68 blank | 0 comment | 0 complexity | 54801d3415ba9bde21314fd2b7327fde MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\asserters;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\tools,
  6. mageekguy\atoum\asserter,
  7. mageekguy\atoum\tools\diffs
  8. ;
  9. require_once __DIR__ . '/../../runner.php';
  10. class variable extends atoum\test
  11. {
  12. public function testClass()
  13. {
  14. $this->testedClass->extends('mageekguy\atoum\asserter');
  15. }
  16. public function test__construct()
  17. {
  18. $this
  19. ->if($this->newTestedInstance)
  20. ->then
  21. ->object($this->testedInstance->getGenerator())->isEqualTo(new atoum\asserter\generator())
  22. ->object($this->testedInstance->getAnalyzer())->isEqualTo(new atoum\tools\variable\analyzer())
  23. ->object($this->testedInstance->getLocale())->isEqualTo(new atoum\locale())
  24. ->object($this->testedInstance->getDiff())->isEqualTo(new diffs\variable())
  25. ->variable($this->testedInstance->getValue())->isNull()
  26. ->boolean($this->testedInstance->wasSet())->isFalse
  27. ->if($this->newTestedInstance($generator = new asserter\generator(), $analyzer = new tools\variable\analyzer(), $locale = new atoum\locale()))
  28. ->then
  29. ->object($this->testedInstance->getGenerator())->isIdenticalTo($generator)
  30. ->object($this->testedInstance->getLocale())->isIdenticalTo($locale)
  31. ->object($this->testedInstance->getAnalyzer())->isEqualTo(new atoum\tools\variable\analyzer())
  32. ->object($this->testedInstance->getDiff())->isEqualTo(new diffs\variable())
  33. ->variable($this->testedInstance->getValue())->isNull()
  34. ->boolean($this->testedInstance->wasSet())->isFalse
  35. ;
  36. }
  37. public function testSetDiff()
  38. {
  39. $this
  40. ->if($this->newTestedInstance)
  41. ->then
  42. ->object($this->testedInstance->setDiff($diff = new diffs\variable()))->isTestedInstance
  43. ->object($this->testedInstance->getDiff())->isIdenticalTo($diff)
  44. ->object($this->testedInstance->setDiff())->isTestedInstance
  45. ->object($this->testedInstance->getDiff())
  46. ->isNotIdenticalTo($diff)
  47. ->isEqualTo(new diffs\variable())
  48. ;
  49. }
  50. public function test__get()
  51. {
  52. $this
  53. ->given($this->newTestedInstance($generator = new \mock\atoum\asserter\generator()))
  54. ->if($this->calling($generator)->__get = $asserterInstance = new \mock\atoum\asserter())
  55. ->then
  56. ->object($this->testedInstance->{$asserterClass = uniqid()})->isIdenticalTo($asserterInstance)
  57. ->mock($generator)->call('__get')->withArguments($asserterClass)->once
  58. ;
  59. }
  60. public function testReset()
  61. {
  62. $this
  63. ->given($this->newTestedInstance)
  64. ->if($this->testedInstance->setWith(uniqid()))
  65. ->then
  66. ->object($this->testedInstance->reset())->isTestedInstance
  67. ->variable($this->testedInstance->getValue())->isNull()
  68. ->boolean($this->testedInstance->wasSet())->isFalse
  69. ->boolean($this->testedInstance->isSetByReference())->isFalse
  70. ->if(
  71. $reference = uniqid(), // Mandatory because "Only variables should be passed by reference"
  72. $this->testedInstance->setByReferenceWith($reference)
  73. )
  74. ->then
  75. ->object($this->testedInstance->reset())->isTestedInstance
  76. ->variable($this->testedInstance->getValue())->isNull()
  77. ->boolean($this->testedInstance->wasSet())->isFalse
  78. ->boolean($this->testedInstance->isSetByReference())->isFalse
  79. ;
  80. }
  81. public function testSetWith()
  82. {
  83. $this
  84. ->given($this->newTestedInstance)
  85. ->if($value = uniqid())
  86. ->then
  87. ->object($this->testedInstance->setWith($value))->isTestedInstance
  88. ->variable($this->testedInstance->getValue())->isIdenticalTo($value)
  89. ->boolean($this->testedInstance->isSetByReference())->isFalse
  90. ;
  91. }
  92. public function testSetByReferenceWith()
  93. {
  94. $this
  95. ->given($this->newTestedInstance)
  96. ->if($value = uniqid())
  97. ->then
  98. ->object($this->testedInstance->setByReferenceWith($value))->isTestedInstance
  99. ->variable($this->testedInstance->getValue())->isIdenticalTo($value)
  100. ->boolean($this->testedInstance->isSetByReference())->isTrue
  101. ;
  102. }
  103. public function testIsSetByReference()
  104. {
  105. $this
  106. ->given($this->newTestedInstance)
  107. ->then
  108. ->boolean($this->testedInstance->isSetByReference())->isFalse
  109. ->if($this->testedInstance->setWith(uniqid()))
  110. ->then
  111. ->boolean($this->testedInstance->isSetByReference())->isFalse
  112. ->if(
  113. $value = uniqid(), // Mandatory because "Only variables should be passed by reference"
  114. $this->testedInstance->setByReferenceWith($value)
  115. )
  116. ->then
  117. ->boolean($this->testedInstance->isSetByReference())->isTrue
  118. ;
  119. }
  120. public function testIsEqualTo()
  121. {
  122. $this
  123. ->given(
  124. $asserter = $this->newTestedInstance
  125. ->setLocale($locale = new \mock\atoum\locale())
  126. ->setDiff($diff = new \mock\atoum\tools\diffs\variable())
  127. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  128. )
  129. ->then
  130. ->exception(function() use ($asserter) { $asserter->isEqualTo(rand(- PHP_INT_MAX, PHP_INT_MAX)); })
  131. ->isInstanceOf('logicException')
  132. ->hasMessage('Value is undefined')
  133. ->if($asserter->setWith($value = rand(- PHP_INT_MAX, PHP_INT_MAX)))
  134. ->then
  135. ->object($asserter->isEqualTo($value))->isIdenticalTo($asserter)
  136. ->object($asserter->isEqualTo((string) $value))->isIdenticalTo($asserter)
  137. ->if(
  138. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  139. $this->calling($diff)->__toString = $diffValue = uniqid(),
  140. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  141. )
  142. ->then
  143. ->exception(function() use ($asserter, & $notEqualValue) { $asserter->isEqualTo($notEqualValue = uniqid()); })
  144. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  145. ->hasMessage($localizedMessage . PHP_EOL . $diffValue)
  146. ->mock($locale)->call('_')->withArguments('%s is not equal to %s', $asserter, $type)->once
  147. ->mock($diff)
  148. ->call('setExpected')->withArguments($notEqualValue)->once
  149. ->call('setActual')->withArguments($value)->once
  150. ;
  151. }
  152. public function testIsNotEqualTo()
  153. {
  154. $this
  155. ->given(
  156. $asserter = $this->newTestedInstance
  157. ->setLocale($locale = new \mock\atoum\locale())
  158. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  159. )
  160. ->then
  161. ->exception(function() use ($asserter) { $asserter->isNotEqualTo(rand(- PHP_INT_MAX, PHP_INT_MAX)); })
  162. ->isInstanceOf('logicException')
  163. ->hasMessage('Value is undefined')
  164. ->if($asserter->setWith($value = uniqid()))
  165. ->then
  166. ->object($asserter->isNotEqualTo(uniqid()))->isIdenticalTo($asserter)
  167. ->if(
  168. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  169. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  170. )
  171. ->then
  172. ->exception(function() use ($asserter, $value) { $asserter->isNotEqualTo($value); })
  173. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  174. ->hasMessage($localizedMessage)
  175. ->mock($locale)->call('_')->withArguments('%s is equal to %s', $asserter, $type)->once
  176. ;
  177. }
  178. public function testIsIdenticalTo()
  179. {
  180. $this
  181. ->given(
  182. $asserter = $this->newTestedInstance
  183. ->setLocale($locale = new \mock\atoum\locale())
  184. ->setDiff($diff = new \mock\atoum\tools\diffs\variable())
  185. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  186. )
  187. ->then
  188. ->exception(function() use ($asserter) { $asserter->isIdenticalTo(rand(- PHP_INT_MAX, PHP_INT_MAX)); })
  189. ->isInstanceOf('logicException')
  190. ->hasMessage('Value is undefined')
  191. ->if($asserter->setWith($value = rand(- PHP_INT_MAX, PHP_INT_MAX)))
  192. ->then
  193. ->object($asserter->isIdenticalTo($value))->isIdenticalTo($asserter)
  194. ->if(
  195. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  196. $this->calling($diff)->__toString = $diffValue = uniqid(),
  197. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  198. )
  199. ->then
  200. ->exception(function() use ($asserter, $value, & $notIdenticalValue) { $asserter->isIdenticalTo($notIdenticalValue = (string) $value); })
  201. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  202. ->hasMessage($localizedMessage . PHP_EOL . $diffValue)
  203. ->mock($locale)->call('_')->withArguments('%s is not identical to %s', $asserter, $type)->once
  204. ->mock($diff)
  205. ->call('setExpected')->withArguments($notIdenticalValue)->once
  206. ->call('setActual')->withArguments($value)->once
  207. ->exception(function() use ($asserter, $value, & $notIdenticalValue) { $asserter->isIdenticalTo($notIdenticalValue = uniqid()); })
  208. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  209. ->hasMessage($localizedMessage . PHP_EOL . $diffValue)
  210. ->mock($locale)->call('_')->withArguments('%s is not identical to %s', $asserter, $type)->twice
  211. ->mock($diff)
  212. ->call('setExpected')->withArguments($notIdenticalValue)->once
  213. ->call('setActual')->withArguments($value)->twice
  214. ;
  215. }
  216. public function testIsNotIdenticalTo()
  217. {
  218. $this
  219. ->given(
  220. $asserter = $this->newTestedInstance
  221. ->setLocale($locale = new \mock\atoum\locale())
  222. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  223. )
  224. ->then
  225. ->exception(function() use ($asserter) { $asserter->isNotIdenticalTo(rand(- PHP_INT_MAX, PHP_INT_MAX)); })
  226. ->isInstanceOf('logicException')
  227. ->hasMessage('Value is undefined')
  228. ->if($asserter->setWith($value = rand(- PHP_INT_MAX, PHP_INT_MAX)))
  229. ->then
  230. ->object($asserter->isNotIdenticalTo((string) $value))->isIdenticalTo($asserter)
  231. ->object($asserter->isNotIdenticalTo(uniqid()))->isIdenticalTo($asserter)
  232. ->if(
  233. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  234. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  235. )
  236. ->then
  237. ->exception(function() use ($asserter, $value) { $asserter->isNotIdenticalTo($value); })
  238. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  239. ->hasMessage($localizedMessage)
  240. ->mock($locale)->call('_')->withArguments('%s is identical to %s', $asserter, $type)->once
  241. ;
  242. }
  243. public function testIsNull()
  244. {
  245. $this
  246. ->given(
  247. $asserter = $this->newTestedInstance
  248. ->setLocale($locale = new \mock\atoum\locale())
  249. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  250. )
  251. ->then
  252. ->exception(function() use ($asserter) { $asserter->isNull(); })
  253. ->isInstanceOf('logicException')
  254. ->hasMessage('Value is undefined')
  255. ->exception(function() use ($asserter) { $asserter->isNull; })
  256. ->isInstanceOf('logicException')
  257. ->hasMessage('Value is undefined')
  258. ->if($asserter->setWith(null))
  259. ->then
  260. ->object($asserter->isNull())->isIdenticalTo($asserter)
  261. ->object($asserter->isNull)->isIdenticalTo($asserter)
  262. ->if(
  263. $asserter->setWith(uniqid()),
  264. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  265. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  266. )
  267. ->then
  268. ->exception(function() use ($asserter) { $asserter->isNull(); })
  269. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  270. ->hasMessage($localizedMessage)
  271. ->mock($locale)->call('_')->withArguments('%s is not null', $asserter)->once
  272. ->exception(function() use ($asserter, & $failMessage) { $asserter->isNull($failMessage = uniqid()); })
  273. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  274. ->hasMessage($failMessage)
  275. ->exception(function() use ($asserter) { $asserter->isNull; })
  276. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  277. ->hasMessage($localizedMessage)
  278. ->mock($locale)->call('_')->withArguments('%s is not null', $asserter)->twice
  279. ->if(
  280. $asserter->setWith(''),
  281. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  282. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  283. )
  284. ->then
  285. ->exception(function() use ($asserter) { $asserter->isNull(); })
  286. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  287. ->hasMessage($localizedMessage)
  288. ->mock($locale)->call('_')->withArguments('%s is not null', $asserter)->thrice()
  289. ->exception(function() use ($asserter, & $failMessage) { $asserter->isNull($failMessage = uniqid()); })
  290. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  291. ->hasMessage($failMessage)
  292. ->exception(function() use ($asserter) { $asserter->isNull; })
  293. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  294. ->hasMessage($localizedMessage)
  295. ->mock($locale)->call('_')->withArguments('%s is not null', $asserter)->exactly(4)
  296. ->if(
  297. $asserter->setWith(0),
  298. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  299. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  300. )
  301. ->then
  302. ->exception(function() use ($asserter) { $asserter->isNull(); })
  303. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  304. ->hasMessage($localizedMessage)
  305. ->mock($locale)->call('_')->withArguments('%s is not null', $asserter)->exactly(5)
  306. ->exception(function() use ($asserter, & $failMessage) { $asserter->isNull($failMessage = uniqid()); })
  307. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  308. ->hasMessage($failMessage)
  309. ->exception(function() use ($asserter) { $asserter->isNull; })
  310. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  311. ->hasMessage($localizedMessage)
  312. ->mock($locale)->call('_')->withArguments('%s is not null', $asserter)->exactly(6)
  313. ->if(
  314. $asserter->setWith(false),
  315. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  316. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  317. )
  318. ->then
  319. ->exception(function() use ($asserter) { $asserter->isNull(); })
  320. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  321. ->hasMessage($localizedMessage)
  322. ->mock($locale)->call('_')->withArguments('%s is not null', $asserter)->exactly(7)
  323. ->exception(function() use ($asserter, & $failMessage) { $asserter->isNull($failMessage = uniqid()); })
  324. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  325. ->hasMessage($failMessage)
  326. ->exception(function() use ($asserter) { $asserter->isNull; })
  327. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  328. ->hasMessage($localizedMessage)
  329. ->mock($locale)->call('_')->withArguments('%s is not null', $asserter)->exactly(8)
  330. ;
  331. }
  332. public function testIsNotNull()
  333. {
  334. $this
  335. ->given(
  336. $asserter = $this->newTestedInstance
  337. ->setLocale($locale = new \mock\atoum\locale())
  338. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  339. )
  340. ->then
  341. ->exception(function() use ($asserter) { $asserter->isNotNull(); })
  342. ->isInstanceOf('logicException')
  343. ->hasMessage('Value is undefined')
  344. ->exception(function() use ($asserter) { $asserter->isNotNull; })
  345. ->isInstanceOf('logicException')
  346. ->hasMessage('Value is undefined')
  347. ->if($asserter->setWith(uniqid()))
  348. ->then
  349. ->object($asserter->isNotNull())->isIdenticalTo($asserter)
  350. ->object($asserter->isNotNull)->isIdenticalTo($asserter)
  351. ->if(
  352. $asserter->setWith(null),
  353. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  354. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  355. )
  356. ->then
  357. ->exception(function() use ($asserter) { $asserter->isNotNull(); })
  358. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  359. ->hasMessage($localizedMessage)
  360. ->mock($locale)->call('_')->withArguments('%s is null', $asserter)->once
  361. ->exception(function() use ($asserter) { $asserter->isNotNull; })
  362. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  363. ->hasMessage($localizedMessage)
  364. ->mock($locale)->call('_')->withArguments('%s is null', $asserter)->twice
  365. ->exception(function() use ($asserter, & $failMessage) { $asserter->isNotNull($failMessage = uniqid()); })
  366. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  367. ->hasMessage($failMessage)
  368. ;
  369. }
  370. public function testIsReferenceTo()
  371. {
  372. $this
  373. ->given(
  374. $asserter = $this->newTestedInstance
  375. ->setLocale($locale = new \mock\atoum\locale())
  376. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  377. )
  378. ->then
  379. ->exception(function() use ($asserter) { $value = uniqid(); $asserter->isReferenceTo($value); })
  380. ->isInstanceOf('logicException')
  381. ->hasMessage('Value is undefined')
  382. ->if($asserter->setWith($value = uniqid()))
  383. ->then
  384. ->exception(function() use ($asserter) { $value = uniqid(); $asserter->isReferenceTo($value); })
  385. ->isInstanceOf('logicException')
  386. ->hasMessage('Value is not set by reference')
  387. ->if(
  388. $asserter->setByReferenceWith($value),
  389. $reference = & $value,
  390. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  391. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  392. )
  393. ->then
  394. ->object($asserter->isReferenceTo($reference))->isIdenticalTo($asserter)
  395. ->exception(function() use ($asserter, & $notReference) { $notReference = uniqid(); $asserter->isReferenceTo($notReference); })
  396. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  397. ->hasMessage($localizedMessage)
  398. ->mock($locale)->call('_')->withArguments('%s is not a reference to %s', $asserter, $type)->once
  399. ->if($asserter->setByReferenceWith($value = new \exception()))
  400. ->then
  401. ->object($asserter->isReferenceTo($reference))->isIdenticalTo($asserter)
  402. ->exception(function() use ($asserter, & $notReference) { $notReference = new \exception(); $asserter->isReferenceTo($notReference); })
  403. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  404. ->hasMessage($localizedMessage)
  405. ->mock($locale)->call('_')->withArguments('%s is not a reference to %s', $asserter, $type)->twice
  406. ->exception(function() use ($asserter, & $notReference, & $failMessage) { $notReference = new \exception(); $asserter->isReferenceTo($notReference, $failMessage = uniqid()); })
  407. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  408. ->hasMessage($failMessage)
  409. ;
  410. }
  411. public function testIsNotFalse()
  412. {
  413. $this
  414. ->given(
  415. $asserter = $this->newTestedInstance
  416. ->setLocale($locale = new \mock\atoum\locale())
  417. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  418. )
  419. ->then
  420. ->exception(function() use ($asserter) { $asserter->isNotFalse(); })
  421. ->isInstanceOf('logicException')
  422. ->hasMessage('Value is undefined')
  423. ->exception(function() use ($asserter) { $asserter->isNotFalse; })
  424. ->isInstanceOf('logicException')
  425. ->hasMessage('Value is undefined')
  426. ->if($asserter->setWith(uniqid()))
  427. ->then
  428. ->object($asserter->isNotFalse())->isIdenticalTo($asserter)
  429. ->object($asserter->isNotFalse)->isIdenticalTo($asserter)
  430. ->if(
  431. $asserter->setWith(false),
  432. $this->calling($locale)->_ = $localizedMessage = uniqid()
  433. )
  434. ->then
  435. ->exception(function() use ($asserter) { $asserter->isNotFalse(); })
  436. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  437. ->hasMessage($localizedMessage)
  438. ->mock($locale)->call('_')->withArguments('%s is false', $asserter)->atLeastOnce()
  439. ->exception(function() use ($asserter) { $asserter->isNotFalse; })
  440. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  441. ->hasMessage($localizedMessage)
  442. ->mock($locale)->call('_')->withArguments('%s is false', $asserter)->atLeastOnce()
  443. ->exception(function() use ($asserter, & $failMessage) { $asserter->isNotFalse($failMessage = uniqid()); })
  444. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  445. ->hasMessage($failMessage)
  446. ;
  447. }
  448. public function testIsNotTrue()
  449. {
  450. $this
  451. ->given(
  452. $asserter = $this->newTestedInstance
  453. ->setLocale($locale = new \mock\atoum\locale())
  454. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  455. )
  456. ->then
  457. ->exception(function() use ($asserter) { $asserter->isNotTrue(); })
  458. ->isInstanceOf('logicException')
  459. ->hasMessage('Value is undefined')
  460. ->exception(function() use ($asserter) { $asserter->isNotTrue; })
  461. ->isInstanceOf('logicException')
  462. ->hasMessage('Value is undefined')
  463. ->if($asserter->setWith(uniqid()))
  464. ->then
  465. ->object($asserter->isNotTrue())->isIdenticalTo($asserter)
  466. ->object($asserter->isNotTrue)->isIdenticalTo($asserter)
  467. ->if(
  468. $asserter->setWith(true),
  469. $this->calling($locale)->_ = $localizedMessage = uniqid()
  470. )
  471. ->then
  472. ->exception(function() use ($asserter) { $asserter->isNotTrue(); })
  473. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  474. ->hasMessage($localizedMessage)
  475. ->mock($locale)->call('_')->withArguments('%s is true', $asserter)->atLeastOnce()
  476. ->exception(function() use ($asserter) { $asserter->isNotTrue; })
  477. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  478. ->hasMessage($localizedMessage)
  479. ->mock($locale)->call('_')->withArguments('%s is true', $asserter)->atLeastOnce()
  480. ->exception(function() use ($asserter, & $failMessage) { $asserter->isNotTrue($failMessage = uniqid()); })
  481. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  482. ->hasMessage($failMessage)
  483. ;
  484. }
  485. public function testIsCallable()
  486. {
  487. $this
  488. ->given(
  489. $asserter = $this->newTestedInstance
  490. ->setLocale($locale = new \mock\atoum\locale())
  491. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  492. )
  493. ->then
  494. ->exception(function() use ($asserter) { $asserter->isCallable(); })
  495. ->isInstanceOf('logicException')
  496. ->hasMessage('Value is undefined')
  497. ->exception(function() use ($asserter) { $asserter->isCallable; })
  498. ->isInstanceOf('logicException')
  499. ->hasMessage('Value is undefined')
  500. ->if($asserter->setWith(function() {}))
  501. ->then
  502. ->object($asserter->isCallable())->isIdenticalTo($asserter)
  503. ->object($asserter->isCallable)->isIdenticalTo($asserter)
  504. ->if(
  505. $asserter->setWith(uniqid()),
  506. $this->calling($locale)->_ = $localizedMessage = uniqid()
  507. )
  508. ->then
  509. ->exception(function() use ($asserter) { $asserter->isCallable(); })
  510. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  511. ->hasMessage($localizedMessage)
  512. ->mock($locale)->call('_')->withArguments('%s is not callable', $asserter)->atLeastOnce()
  513. ->exception(function() use ($asserter) { $asserter->isCallable; })
  514. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  515. ->hasMessage($localizedMessage)
  516. ->mock($locale)->call('_')->withArguments('%s is not callable', $asserter)->atLeastOnce()
  517. ->exception(function() use ($asserter, & $failMessage) { $asserter->isCallable($failMessage = uniqid()); })
  518. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  519. ->hasMessage($failMessage)
  520. ;
  521. }
  522. public function testIsNotCallable()
  523. {
  524. $this
  525. ->given(
  526. $asserter = $this->newTestedInstance
  527. ->setLocale($locale = new \mock\atoum\locale())
  528. )
  529. ->then
  530. ->exception(function() use ($asserter) { $asserter->isNotCallable(); })
  531. ->isInstanceOf('logicException')
  532. ->hasMessage('Value is undefined')
  533. ->exception(function() use ($asserter) { $asserter->isNotCallable; })
  534. ->isInstanceOf('logicException')
  535. ->hasMessage('Value is undefined')
  536. ->if($asserter->setWith(uniqid()))
  537. ->then
  538. ->object($asserter->isNotCallable())->isIdenticalTo($asserter)
  539. ->object($asserter->isNotCallable)->isIdenticalTo($asserter)
  540. ->if(
  541. $asserter->setWith(function() {}),
  542. $this->calling($locale)->_ = $localizedMessage = uniqid()
  543. )
  544. ->then
  545. ->exception(function() use ($asserter) { $asserter->isNotCallable(); })
  546. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  547. ->hasMessage($localizedMessage)
  548. ->mock($locale)->call('_')->withArguments('%s is callable', $asserter)->atLeastOnce()
  549. ->exception(function() use ($asserter) { $asserter->isNotCallable; })
  550. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  551. ->hasMessage($localizedMessage)
  552. ->mock($locale)->call('_')->withArguments('%s is callable', $asserter)->atLeastOnce()
  553. ->exception(function() use ($asserter, & $message) { $asserter->isNotCallable($message = uniqid()); })
  554. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  555. ->hasMessage($message)
  556. ;
  557. }
  558. }