PageRenderTime 73ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/asserters/phpArray.php

http://github.com/mageekguy/atoum
PHP | 1207 lines | 1059 code | 148 blank | 0 comment | 0 complexity | c84f816fa144154baa272773f85619a3 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. namespace mageekguy\atoum\tests\units\asserters;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\asserter,
  6. mageekguy\atoum\tools\variable
  7. ;
  8. require_once __DIR__ . '/../../runner.php';
  9. class phpArray extends atoum\test
  10. {
  11. public function testClass()
  12. {
  13. $this->testedClass
  14. ->extends('mageekguy\atoum\asserters\variable')
  15. ->implements('arrayAccess')
  16. ;
  17. }
  18. public function test__construct()
  19. {
  20. $this
  21. ->if($this->newTestedInstance())
  22. ->then
  23. ->object($this->testedInstance->getGenerator())->isEqualTo(new atoum\asserter\generator())
  24. ->object($this->testedInstance->getAnalyzer())->isEqualTo(new variable\analyzer())
  25. ->object($this->testedInstance->getLocale())->isEqualTo(new atoum\locale())
  26. ->variable($this->testedInstance->getValue())->isNull()
  27. ->boolean($this->testedInstance->wasSet())->isFalse()
  28. ->variable($this->testedInstance->getKey())->isNull()
  29. ->variable($this->testedInstance->getInnerAsserter())->isNull()
  30. ->variable($this->testedInstance->getInnerValue())->isNull()
  31. ->if($this->newTestedInstance($generator = new asserter\generator(), $analyzer = new variable\analyzer(), $locale = new atoum\locale()))
  32. ->then
  33. ->object($this->testedInstance->getGenerator())->isIdenticalTo($generator)
  34. ->object($this->testedInstance->getAnalyzer())->isIdenticalTo($analyzer)
  35. ->object($this->testedInstance->getLocale())->isIdenticalTo($locale)
  36. ->variable($this->testedInstance->getValue())->isNull()
  37. ->boolean($this->testedInstance->wasSet())->isFalse()
  38. ->variable($this->testedInstance->getKey())->isNull()
  39. ->variable($this->testedInstance->getInnerAsserter())->isNull()
  40. ->variable($this->testedInstance->getInnerValue())->isNull()
  41. ;
  42. }
  43. public function test__get()
  44. {
  45. $this
  46. ->given($this->newTestedInstance($generator = new \mock\mageekguy\atoum\asserter\generator()))
  47. ->then
  48. ->object($this->testedInstance->object)->isTestedInstance
  49. ->object($this->testedInstance->getInnerAsserter())->isEqualTo($generator->object)
  50. ->object($this->testedInstance->object->string)->isTestedInstance
  51. ->object($this->testedInstance->getInnerAsserter())->isEqualTo($generator->string)
  52. ->object($this->testedInstance->error)->isInstanceOf($generator->error)
  53. ->variable($this->testedInstance->getInnerAsserter())->isNull()
  54. ->if($this->testedInstance->setWith(array(
  55. 0 => array(
  56. 0 => array(
  57. 1 => array('foo', 'bar')
  58. ),
  59. 1 => array(1, new \mock\object())
  60. ),
  61. 1 => 'foobar'
  62. )
  63. )
  64. )
  65. ->then
  66. ->object($this->testedInstance->phpArray[0][0][1]->isEqualTo(array('foo', 'bar')))->isTestedInstance
  67. ->object($this->testedInstance->string[1]->isEqualTo('foobar'))->isTestedInstance
  68. ->given($this->newTestedInstance->setWith(array($array1 = array('foo', 'bar'), $array2 = array(1, new \mock\object()))))
  69. ->then
  70. ->object($this->testedInstance->phpArray[0]->string[0]->isEqualTo('foo'))->isInstanceOf('mageekguy\atoum\asserters\phpArray')
  71. ->object($this->testedInstance->phpArray[1]->isEqualTo($array2))->isInstanceOf('mageekguy\atoum\asserters\phpArray')
  72. ;
  73. }
  74. public function testReset()
  75. {
  76. $this
  77. ->given($this->newTestedInstance)
  78. ->then
  79. ->object($this->testedInstance->reset())->isTestedInstance
  80. ->variable($this->testedInstance->getValue())->isNull()
  81. ->boolean($this->testedInstance->wasSet())->isFalse()
  82. ->boolean($this->testedInstance->isSetByReference())->isFalse()
  83. ->variable($this->testedInstance->getKey())->isNull()
  84. ->variable($this->testedInstance->getInnerAsserter())->isNull()
  85. ->variable($this->testedInstance->getInnerValue())->isNull()
  86. ->if($this->testedInstance->setWith(array()))
  87. ->then
  88. ->object($this->testedInstance->reset())->isTestedInstance
  89. ->variable($this->testedInstance->getValue())->isNull()
  90. ->boolean($this->testedInstance->wasSet())->isFalse()
  91. ->boolean($this->testedInstance->isSetByReference())->isFalse()
  92. ->variable($this->testedInstance->getKey())->isNull()
  93. ->variable($this->testedInstance->getInnerAsserter())->isNull()
  94. ->variable($this->testedInstance->getInnerValue())->isNull()
  95. ->if(
  96. $reference = range(1, 5),
  97. $this->testedInstance->setByReferenceWith($reference)
  98. )
  99. ->then
  100. ->object($this->testedInstance->reset())->isTestedInstance
  101. ->variable($this->testedInstance->getValue())->isNull()
  102. ->boolean($this->testedInstance->wasSet())->isFalse()
  103. ->boolean($this->testedInstance->isSetByReference())->isFalse()
  104. ->variable($this->testedInstance->getKey())->isNull()
  105. ->variable($this->testedInstance->getInnerAsserter())->isNull()
  106. ->variable($this->testedInstance->getInnerValue())->isNull()
  107. ->if($this->testedInstance->object)
  108. ->then
  109. ->object($this->testedInstance->reset())->isTestedInstance
  110. ->variable($this->testedInstance->getValue())->isNull()
  111. ->boolean($this->testedInstance->wasSet())->isFalse()
  112. ->boolean($this->testedInstance->isSetByReference())->isFalse()
  113. ->variable($this->testedInstance->getKey())->isNull()
  114. ->variable($this->testedInstance->getInnerAsserter())->isNull()
  115. ->variable($this->testedInstance->getInnerValue())->isNull()
  116. ->if(
  117. $this->testedInstance->setWith(range(1, 5)),
  118. $this->testedInstance->atKey(2)
  119. )
  120. ->then
  121. ->object($this->testedInstance->reset())->isTestedInstance
  122. ->variable($this->testedInstance->getValue())->isNull()
  123. ->boolean($this->testedInstance->wasSet())->isFalse()
  124. ->boolean($this->testedInstance->isSetByReference())->isFalse()
  125. ->variable($this->testedInstance->getKey())->isNull()
  126. ->variable($this->testedInstance->getInnerAsserter())->isNull()
  127. ->variable($this->testedInstance->getInnerValue())->isNull()
  128. ;
  129. }
  130. public function testSetWith()
  131. {
  132. $this
  133. ->given($asserter = $this->newTestedInstance
  134. ->setLocale($locale = new \mock\atoum\locale())
  135. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  136. )
  137. ->if(
  138. $this->calling($locale)->_ = $notAnArray = uniqid(),
  139. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  140. )
  141. ->then
  142. ->exception(function() use ($asserter, & $value) { $asserter->setWith($value = uniqid()); })
  143. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  144. ->hasMessage($notAnArray)
  145. ->mock($locale)->call('_')->withArguments('%s is not an array', $type)->once
  146. ->object($asserter->setWith($value = array()))->isIdenticalTo($asserter)
  147. ->array($asserter->getValue())->isEqualTo($value)
  148. ->variable($asserter->getKey())->isNull()
  149. ->variable($asserter->getInnerAsserter())->isNull()
  150. ->variable($asserter->getInnerValue())->isNull()
  151. ->boolean($asserter->isSetByReference())->isFalse()
  152. ->if($asserter->object)
  153. ->then
  154. ->variable($innerAsserter = $asserter->getInnerAsserter())->isNotNull()
  155. ->object($objectAsserter = $asserter->setWith($object = new \mock\object()))->isIdenticalTo($innerAsserter)
  156. ->object($objectAsserter->getValue())->isIdenticalTo($object)
  157. ->variable($asserter->getValue())->isNull()
  158. ->boolean($asserter->wasSet())->isFalse()
  159. ->boolean($asserter->isSetByReference())->isFalse()
  160. ->variable($asserter->getKey())->isNull()
  161. ->variable($asserter->getInnerAsserter())->isNull()
  162. ->variable($asserter->getInnerValue())->isNull()
  163. ;
  164. }
  165. public function testOffsetGet()
  166. {
  167. $this
  168. ->given($asserter = $this->newTestedInstance
  169. ->setLocale($locale = new \mock\atoum\locale())
  170. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  171. )
  172. ->then
  173. ->exception(function() use ($asserter) { $asserter[2]; })
  174. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  175. ->hasMessage('Array is undefined')
  176. ->if(
  177. $this->calling($locale)->_ = $notAnArray = uniqid(),
  178. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  179. $asserter->setWith(array(1, 2, $object = new \mock\object(), clone $object))
  180. )
  181. ->then
  182. ->exception(function() use ($asserter, & $value) { $asserter[2]; })
  183. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  184. ->hasMessage($notAnArray)
  185. ->mock($locale)->call('_')->withArguments('Value %s at key %s is not an array', $type, 2)->once
  186. ->if($asserter->setWith(array(1, 2, $object = new \mock\object(), clone $object)))
  187. ->then
  188. ->object($asserter->object[2]->isIdenticalTo($object))->isIdenticalTo($asserter)
  189. ->object($asserter->object[2]->isIdenticalTo($object))->isIdenticalTo($asserter)
  190. ->object($asserter->object[3]->isCloneOf($object))->isIdenticalTo($asserter)
  191. ->object($asserter->object[2])->isIdenticalTo($asserter)
  192. ->given($asserter = $this->newTestedInstance
  193. ->setLocale($locale)
  194. ->setAnalyzer($analyzer)
  195. )
  196. ->if($asserter->setWith($array = array($integer = rand(1, PHP_INT_MAX), 2, $innerArray = array(3, 4, 5, $object))))
  197. ->then
  198. ->object($asserter[2])
  199. ->isIdenticalTo($asserter)
  200. ->array($asserter->getValue())->isEqualTo($innerArray)
  201. ->if($asserter->setWith($array))
  202. ->then
  203. ->object($asserter->integer[0]->isEqualTo($integer))->isIdenticalTo($asserter)
  204. ->object($asserter->object[2][3]->isIdenticalTo($object))->isIdenticalTo($asserter)
  205. ->object($asserter->object[2][3]->isIdenticalTo($object)->integer[0]->isEqualTo($integer))->isIdenticalTo($asserter)
  206. ->object($asserter->object[2][3]->isIdenticalTo($object)->integer($integer)->isEqualTo($integer))
  207. ->isNotIdenticalTo($asserter)
  208. ->isInstanceOf('mageekguy\atoum\asserters\integer')
  209. ->if(
  210. $this->calling($locale)->_ = $unknownKey = uniqid(),
  211. $this->calling($analyzer)->getTypeOf = function($value) use ($innerArray, & $innerArrayType, & $keyType) { return ($innerArray === $value ? ($innerArrayType = uniqid()) : ($keyType = uniqid())); }
  212. )
  213. ->then
  214. ->exception(function() use ($asserter) { $asserter->object[2][4]; })
  215. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  216. ->hasMessage($unknownKey)
  217. ->mock($locale)->call('_')->withArguments('%s has no key %s', $innerArrayType, $keyType)->once
  218. ;
  219. }
  220. public function testOffsetSet()
  221. {
  222. $this
  223. ->given($asserter = $this->newTestedInstance)
  224. ->then
  225. ->exception(function() use ($asserter) { $asserter[rand(0, PHP_INT_MAX)] = rand(0, PHP_INT_MAX); })
  226. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  227. ->hasMessage('Tested array is read only')
  228. ;
  229. }
  230. public function testOffsetUnset()
  231. {
  232. $this
  233. ->given($asserter = $this->newTestedInstance)
  234. ->then
  235. ->exception(function() use ($asserter) { unset($asserter[rand(0, PHP_INT_MAX)]); })
  236. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  237. ->hasMessage('Array is read only')
  238. ;
  239. }
  240. public function testOffsetExists()
  241. {
  242. $this
  243. ->given($asserter = $this->newTestedInstance)
  244. ->then
  245. ->boolean(isset($asserter[rand(0, PHP_INT_MAX)]))->isFalse()
  246. ->if($asserter->setWith(array()))
  247. ->then
  248. ->boolean(isset($asserter[rand(0, PHP_INT_MAX)]))->isFalse()
  249. ->if($asserter->setWith(array(uniqid())))
  250. ->then
  251. ->boolean(isset($asserter[0]))->isTrue()
  252. ->boolean(isset($asserter[rand(1, PHP_INT_MAX)]))->isFalse()
  253. ->if($asserter->setWith(array($key = uniqid() => uniqid())))
  254. ->then
  255. ->boolean(isset($asserter[$key]))->isTrue()
  256. ->boolean(isset($asserter[0]))->isFalse()
  257. ->boolean(isset($asserter[rand(1, PHP_INT_MAX)]))->isFalse()
  258. ;
  259. }
  260. public function testHasSize()
  261. {
  262. $this
  263. ->given($asserter = $this->newTestedInstance
  264. ->setLocale($locale = new \mock\atoum\locale())
  265. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  266. )
  267. ->then
  268. ->exception(function() use ($asserter) { $asserter->hasSize(rand(0, PHP_INT_MAX)); })
  269. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  270. ->hasMessage('Array is undefined')
  271. ->if(
  272. $this->calling($locale)->_ = $badSize = uniqid(),
  273. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  274. $asserter->setWith(array())
  275. )
  276. ->then
  277. ->exception(function() use ($asserter, & $size) { $asserter->hasSize($size = rand(1, PHP_INT_MAX)); })
  278. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  279. ->hasMessage($badSize)
  280. ->mock($locale)->call('_')->withArguments('%s has size %d, expected size %d', $asserter, 0, $size)->once
  281. ->exception(function() use ($asserter, & $failMessage) { $asserter->hasSize(rand(1, PHP_INT_MAX), $failMessage = uniqid()); })
  282. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  283. ->hasMessage($failMessage)
  284. ->object($asserter->hasSize(0))->isIdenticalTo($asserter)
  285. ->if($asserter->setWith(range(1, 5)))
  286. ->then
  287. ->object($asserter->hasSize(5))->isIdenticalTo($asserter)
  288. ;
  289. }
  290. public function testIsEmpty()
  291. {
  292. $this
  293. ->given($asserter = $this->newTestedInstance
  294. ->setLocale($locale = new \mock\atoum\locale())
  295. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  296. )
  297. ->then
  298. ->exception(function() use ($asserter) { $asserter->isEmpty(); })
  299. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  300. ->hasMessage('Array is undefined')
  301. ->if(
  302. $this->calling($locale)->_ = $notEmpty = uniqid(),
  303. $asserter->setWith(array(uniqid()))
  304. )
  305. ->then
  306. ->exception(function() use ($asserter) { $asserter->isEmpty(); })
  307. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  308. ->hasMessage($notEmpty)
  309. ->mock($locale)->call('_')->withArguments('%s is not empty', $asserter)->once
  310. ->exception(function() use ($asserter) { $asserter->isEmpty; })
  311. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  312. ->hasMessage($notEmpty)
  313. ->mock($locale)->call('_')->withArguments('%s is not empty', $asserter)->twice
  314. ->exception(function() use ($asserter, & $failMessage) { $asserter->isEmpty($failMessage = uniqid()); })
  315. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  316. ->hasMessage($failMessage)
  317. ->if($asserter->setWith(array()))
  318. ->then
  319. ->object($asserter->isEmpty())->isIdenticalTo($asserter)
  320. ;
  321. }
  322. public function testIsNotEmpty()
  323. {
  324. $this
  325. ->given($asserter = $this->newTestedInstance
  326. ->setLocale($locale = new \mock\atoum\locale())
  327. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  328. )
  329. ->then
  330. ->exception(function() use ($asserter) { $asserter->isNotEmpty(); })
  331. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  332. ->hasMessage('Array is undefined')
  333. ->if(
  334. $this->calling($locale)->_ = $isEmpty = uniqid(),
  335. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  336. $asserter->setWith(array())
  337. )
  338. ->then
  339. ->exception(function() use ($asserter) { $asserter->isNotEmpty(); })
  340. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  341. ->hasMessage($isEmpty)
  342. ->mock($locale)->call('_')->withArguments('%s is empty', $asserter)->once
  343. ->exception(function() use ($asserter, & $failMessage) { $asserter->isNotEmpty($failMessage = uniqid()); })
  344. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  345. ->hasMessage($failMessage)
  346. ->if($asserter->setWith(array(uniqid())))
  347. ->then
  348. ->object($asserter->isNotEmpty())->isIdenticalTo($asserter)
  349. ;
  350. }
  351. public function testAtKey()
  352. {
  353. $this
  354. ->given($asserter = $this->newTestedInstance
  355. ->setLocale($locale = new \mock\atoum\locale())
  356. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  357. )
  358. ->then
  359. ->exception(function() use ($asserter) { $asserter->atKey(uniqid()); })
  360. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  361. ->hasMessage('Array is undefined')
  362. ->if($asserter->setWith(array(uniqid(), uniqid(), $data = rand(1, PHP_INT_MAX), uniqid(), uniqid())))
  363. ->object($asserter->atKey(0))->isIdenticalTo($asserter)
  364. ->object($asserter->atKey('0'))->isIdenticalTo($asserter)
  365. ->object($asserter->atKey(1))->isIdenticalTo($asserter)
  366. ->object($asserter->atKey(2))->isIdenticalTo($asserter)
  367. ->object($asserter->atKey(3))->isIdenticalTo($asserter)
  368. ->object($asserter->atKey(4))->isIdenticalTo($asserter)
  369. ->if(
  370. $this->calling($locale)->_ = $unknownKey = uniqid(),
  371. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  372. )
  373. ->then
  374. ->exception(function() use ($asserter, & $key) { $asserter->atKey($key = rand(5, PHP_INT_MAX)); })
  375. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  376. ->hasMessage($unknownKey)
  377. ->mock($locale)->call('_')->withArguments('%s has no key %s', $asserter, $type)->once
  378. ->mock($analyzer)->call('getTypeOf')->withArguments($key)->once
  379. ->exception(function() use ($asserter, & $failMessage) { $asserter->atKey(rand(5, PHP_INT_MAX), $failMessage = uniqid()); })
  380. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  381. ->hasMessage($failMessage)
  382. ;
  383. }
  384. public function testContains()
  385. {
  386. $this
  387. ->given($asserter = $this->newTestedInstance
  388. ->setLocale($locale = new \mock\atoum\locale())
  389. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  390. )
  391. ->then
  392. ->exception(function() use ($asserter) { $asserter->contains(uniqid()); })
  393. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  394. ->hasMessage('Array is undefined')
  395. ->if(
  396. $this->calling($locale)->_ = $notInArray = uniqid(),
  397. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  398. $asserter->setWith(array(uniqid(), uniqid(), $data = rand(1, PHP_INT_MAX), uniqid(), uniqid()))
  399. )
  400. ->then
  401. ->exception(function() use ($asserter, & $unknownValue) { $asserter->contains($unknownValue = uniqid()); })
  402. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  403. ->hasMessage($notInArray)
  404. ->mock($locale)->call('_')->withArguments('%s does not contain %s', $asserter, $type)->once
  405. ->mock($analyzer)->call('getTypeOf')->withArguments($unknownValue)->once
  406. ->exception(function() use ($asserter, & $failMessage) { $asserter->contains(uniqid(), $failMessage = uniqid()); })
  407. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  408. ->hasMessage($failMessage)
  409. ->object($asserter->contains($data))->isIdenticalTo($asserter)
  410. ->object($asserter->contains((string) $data))->isIdenticalTo($asserter)
  411. ->if(
  412. $this->calling($locale)->_ = $notInArrayAtKey = uniqid(),
  413. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  414. $asserter->setWith(array(uniqid(), uniqid(), $data = rand(1, PHP_INT_MAX), uniqid(), uniqid()))
  415. )
  416. ->then
  417. ->exception(function() use ($asserter, $data) { $asserter->atKey(0)->contains($data); })
  418. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  419. ->hasMessage($notInArrayAtKey)
  420. ->object($asserter->contains($data))->isIdenticalTo($asserter)
  421. ->object($asserter->atKey(2)->contains($data))->isIdenticalTo($asserter)
  422. ->exception(function() use ($asserter, & $failMessage) { $asserter->atKey(0)->contains(uniqid(), $failMessage = uniqid()); })
  423. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  424. ->hasMessage($failMessage)
  425. ;
  426. }
  427. public function testStrictlyContains()
  428. {
  429. $this
  430. ->given($asserter = $this->newTestedInstance
  431. ->setLocale($locale = new \mock\atoum\locale())
  432. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  433. )
  434. ->then
  435. ->exception(function() use ($asserter) { $asserter->strictlyContains(uniqid()); })
  436. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  437. ->hasMessage('Array is undefined')
  438. ->if(
  439. $this->calling($locale)->_ = $notInArray = uniqid(),
  440. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  441. $asserter->setWith(array(1, 2, 3, 4, 5, '3'))
  442. )
  443. ->then
  444. ->exception(function() use ($asserter) {$asserter->strictlyContains('1'); })
  445. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  446. ->hasMessage($notInArray)
  447. ->mock($locale)->call('_')->withArguments('%s does not strictly contain %s', $asserter, $type)->once
  448. ->mock($analyzer)->call('getTypeOf')->withArguments('1')->once
  449. ->exception(function() use ($asserter, & $failMessage) {$asserter->strictlyContains('1', $failMessage = uniqid()); })
  450. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  451. ->hasMessage($failMessage)
  452. ->object($asserter->strictlyContains(1))->isIdenticalTo($asserter)
  453. ->if($this->calling($analyzer)->getTypeOf = function($value) use (& $notInArrayType, & $keyType) { return ($value === 2 ? ($notInArrayType = uniqid()) : ($keyType = uniqid())); })
  454. ->then
  455. ->exception(function() use ($asserter) { $asserter->atKey(0)->strictlyContains(2); })
  456. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  457. ->hasMessage($notInArray)
  458. ->mock($locale)->call('_')->withArguments('%s does not strictly contain %s at key %s', $asserter, $notInArrayType, $keyType)->once
  459. ->mock($analyzer)->call('getTypeOf')->withArguments(2)->once
  460. ->exception(function() use ($asserter, & $failMessage) { $asserter->atKey(0)->strictlyContains(2, $failMessage = uniqid()); })
  461. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  462. ->hasMessage($failMessage)
  463. ;
  464. }
  465. public function testNotContains()
  466. {
  467. $this
  468. ->given($asserter = $this->newTestedInstance
  469. ->setLocale($locale = new \mock\atoum\locale())
  470. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  471. )
  472. ->then
  473. ->exception(function() use ($asserter) { $asserter->notContains(uniqid()); })
  474. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  475. ->hasMessage('Array is undefined')
  476. ->if($asserter->setWith(array(uniqid(), uniqid(), $isInArray = uniqid(), uniqid(), uniqid())))
  477. ->then
  478. ->object($asserter->notContains(uniqid()))->isIdenticalTo($asserter)
  479. ->if(
  480. $this->calling($locale)->_ = $inArray = uniqid(),
  481. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  482. )
  483. ->then
  484. ->exception(function() use ($asserter, $isInArray) { $asserter->notContains($isInArray); })
  485. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  486. ->hasMessage($inArray)
  487. ->mock($locale)->call('_')->withArguments('%s contains %s', $asserter, $type)->once
  488. ->mock($analyzer)->call('getTypeOf')->withArguments($isInArray)->once
  489. ->exception(function() use ($asserter, $isInArray, & $failMessage) { $asserter->notContains($isInArray, $failMessage = uniqid()); })
  490. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  491. ->hasMessage($failMessage)
  492. ->object($asserter->atKey(0)->notContains($inArray))->isIdenticalTo($asserter)
  493. ->object($asserter->atKey(1)->notContains($inArray))->isIdenticalTo($asserter)
  494. ->object($asserter->atKey(3)->notContains($inArray))->isIdenticalTo($asserter)
  495. ->object($asserter->atKey(4)->notContains($inArray))->isIdenticalTo($asserter)
  496. ->if(
  497. $this->calling($locale)->_ = $inArray = uniqid(),
  498. $this->calling($analyzer)->getTypeOf = function($value) use ($isInArray, & $isInArrayType, & $keyType) { return ($isInArray === $value ? ($isInArrayType = uniqid()) : ($keyType = uniqid())); }
  499. )
  500. ->then
  501. ->exception(function() use ($asserter, $isInArray) { $asserter->atKey(2)->notContains($isInArray); })
  502. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  503. ->hasMessage($inArray)
  504. ->mock($locale)->call('_')->withArguments('%s contains %s at key %s', $asserter, $isInArrayType, $keyType)->once
  505. ->mock($analyzer)
  506. ->call('getTypeOf')
  507. ->withArguments($isInArray)->twice
  508. ->withArguments(2)->once
  509. ->exception(function() use ($asserter, $isInArray, & $failMessage) { $asserter->atKey(2)->notContains($isInArray, $failMessage = 'FAIL'); })
  510. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  511. ->hasMessage($failMessage)
  512. ;
  513. }
  514. public function testStrictlyNotContains()
  515. {
  516. $this
  517. ->given($asserter = $this->newTestedInstance
  518. ->setLocale($locale = new \mock\atoum\locale())
  519. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  520. )
  521. ->then
  522. ->exception(function() use ($asserter) { $asserter->strictlyNotContains(uniqid()); })
  523. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  524. ->hasMessage('Array is undefined')
  525. ->if(
  526. $this->calling($locale)->_ = $strictlyNotInArray = uniqid(),
  527. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  528. $asserter->setWith(array(1, 2, 3, 4, 5, '6'))
  529. )
  530. ->then
  531. ->exception(function() use ($asserter) {$asserter->strictlyNotContains(1); })
  532. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  533. ->hasMessage($strictlyNotInArray)
  534. ->mock($locale)->call('_')->withArguments('%s strictly contains %s', $asserter, $type)->once
  535. ->mock($analyzer)->call('getTypeOf')->withArguments(1)->once
  536. ->exception(function() use ($asserter, & $failMessage) {$asserter->strictlyNotContains(1, $failMessage = uniqid()); })
  537. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  538. ->hasMessage($failMessage)
  539. ->object($asserter->strictlyNotContains('1'))->isIdenticalTo($asserter)
  540. ->object($asserter->atKey(1)->strictlyNotContains(1))->isIdenticalTo($asserter)
  541. ->object($asserter->atKey(2)->strictlyNotContains(1))->isIdenticalTo($asserter)
  542. ->object($asserter->atKey(3)->strictlyNotContains(1))->isIdenticalTo($asserter)
  543. ->object($asserter->atKey(4)->strictlyNotContains(1))->isIdenticalTo($asserter)
  544. ->if($this->calling($analyzer)->getTypeOf = function($value) use (& $strictlyNotInArrayType, & $keyType) { return ($value === 1 ? ($strictlyNotInArrayType = uniqid()) : ($keyType = uniqid())); })
  545. ->then
  546. ->exception(function() use ($asserter) { $asserter->atKey(0)->strictlyNotContains(1); })
  547. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  548. ->hasMessage($strictlyNotInArray)
  549. ->mock($locale)->call('_')->withArguments('%s strictly contains %s at key %s', $asserter, $strictlyNotInArrayType, $keyType)->once
  550. ->mock($analyzer)->call('getTypeOf')->withArguments(0)->once
  551. ;
  552. }
  553. public function testContainsValues()
  554. {
  555. $this
  556. ->given($asserter = $this->newTestedInstance
  557. ->setLocale($locale = new \mock\atoum\locale())
  558. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  559. )
  560. ->then
  561. ->exception(function() use ($asserter) { $asserter->containsValues(array(6)); })
  562. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  563. ->hasMessage('Array is undefined')
  564. ->if(
  565. $this->calling($locale)->_ = $notContainsValues = uniqid(),
  566. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  567. $asserter->setWith(array(1, 2, 3, 4, 5))
  568. )
  569. ->then
  570. ->exception(function() use ($asserter) { $asserter->containsValues(array(6)); })
  571. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  572. ->hasMessage($notContainsValues)
  573. ->mock($locale)->call('_')->withArguments('%s does not contain values %s', $asserter, $type)->once
  574. ->mock($analyzer)->call('getTypeOf')->withArguments(array(6))->once
  575. ->exception(function() use ($asserter, & $failMessage) { $asserter->containsValues(array(6), $failMessage = uniqid()); })
  576. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  577. ->hasMessage($failMessage)
  578. ->object($asserter->containsValues(array(1)))->isIdenticalTo($asserter)
  579. ->object($asserter->containsValues(array('1')))->isIdenticalTo($asserter)
  580. ->object($asserter->containsValues(array(1, 2, 4)))->isIdenticalTo($asserter)
  581. ->object($asserter->containsValues(array('1', 2, '4')))->isIdenticalTo($asserter)
  582. ;
  583. }
  584. public function testStrictlyContainsValues()
  585. {
  586. $this
  587. ->given($asserter = $this->newTestedInstance
  588. ->setLocale($locale = new \mock\atoum\locale())
  589. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  590. )
  591. ->then
  592. ->exception(function() use ($asserter) { $asserter->strictlyContainsValues(array(6)); })
  593. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  594. ->hasMessage('Array is undefined')
  595. ->if(
  596. $this->calling($locale)->_ = $strictlyNotContainsValues = uniqid(),
  597. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  598. $asserter->setWith(array(1, 2, 3, 4, 5))
  599. )
  600. ->then
  601. ->exception(function() use ($asserter) { $asserter->strictlyContainsValues(array(1, '5')); })
  602. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  603. ->hasMessage($strictlyNotContainsValues)
  604. ->mock($locale)->call('_')->withArguments('%s does not contain strictly values %s', $asserter, $type)->once
  605. ->mock($analyzer)->call('getTypeOf')->withArguments(array('5'))->once
  606. ->exception(function() use ($asserter, & $failMessage) { $asserter->strictlyContainsValues(array('5'), $failMessage = uniqid()); })
  607. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  608. ->hasMessage($failMessage)
  609. ->object($asserter->strictlyContainsValues(array(1)))->isIdenticalTo($asserter)
  610. ->object($asserter->strictlyContainsValues(array(1, 2)))->isIdenticalTo($asserter)
  611. ->object($asserter->strictlyContainsValues(array(1, 2, 3)))->isIdenticalTo($asserter)
  612. ->object($asserter->strictlyContainsValues(array(1, 2, 3, 4)))->isIdenticalTo($asserter)
  613. ->object($asserter->strictlyContainsValues(array(1, 2, 3, 4, 5)))->isIdenticalTo($asserter)
  614. ;
  615. }
  616. public function testNotContainsValues()
  617. {
  618. $this
  619. ->given($asserter = $this->newTestedInstance
  620. ->setLocale($locale = new \mock\atoum\locale())
  621. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  622. )
  623. ->then
  624. ->exception(function() use ($asserter) { $asserter->notContainsValues(array(1, 6)); })
  625. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  626. ->hasMessage('Array is undefined')
  627. ->if(
  628. $this->calling($locale)->_ = $containsValues = uniqid(),
  629. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  630. $asserter->setWith(array(1, 2, 3, 4, 5))
  631. )
  632. ->then
  633. ->exception(function() use ($asserter) { $asserter->notContainsValues(array(1, 6)); })
  634. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  635. ->hasMessage($containsValues)
  636. ->mock($locale)->call('_')->withArguments('%s contains values %s', $asserter, $type)->once
  637. ->mock($analyzer)->call('getTypeOf')->withArguments(array(1))->once
  638. ->exception(function() use ($asserter, & $failMessage) { $asserter->notContainsValues(array(1, 6), $failMessage = uniqid()); })
  639. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  640. ->hasMessage($failMessage)
  641. ->object($asserter->notContainsValues(array(6)))->isIdenticalTo($asserter)
  642. ->object($asserter->notContainsValues(array('6')))->isIdenticalTo($asserter)
  643. ->object($asserter->notContainsValues(array(6, 7)))->isIdenticalTo($asserter)
  644. ->object($asserter->notContainsValues(array('6', '7')))->isIdenticalTo($asserter)
  645. ->object($asserter->notContainsValues(array(6, 7, 8)))->isIdenticalTo($asserter)
  646. ->object($asserter->notContainsValues(array('6', 7, '8')))->isIdenticalTo($asserter)
  647. ;
  648. }
  649. public function testStrictlyNotContainsValues()
  650. {
  651. $this
  652. ->given($asserter = $this->newTestedInstance
  653. ->setLocale($locale = new \mock\atoum\locale())
  654. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  655. )
  656. ->then
  657. ->exception(function() use ($asserter) { $asserter->strictlyNotContainsValues(array(1, 6)); })
  658. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  659. ->hasMessage('Array is undefined')
  660. ->if(
  661. $this->calling($locale)->_ = $containsStrictlyValues = uniqid(),
  662. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  663. $asserter->setWith(array(1, 2, 3, 4, 5))
  664. )
  665. ->then
  666. ->exception(function() use ($asserter) { $asserter->strictlyNotContainsValues(array(1, '2', '4')); })
  667. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  668. ->hasMessage($containsStrictlyValues)
  669. ->mock($locale)->call('_')->withArguments('%s contains strictly values %s', $asserter, $type)->once
  670. ->mock($analyzer)->call('getTypeOf')->withArguments(array(1))->once
  671. ->exception(function() use ($asserter, & $failMessage) { $asserter->strictlyNotContainsValues(array(1), $failMessage = uniqid()); })
  672. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  673. ->hasMessage($failMessage)
  674. ->object($asserter->strictlyNotContainsValues(array('1')))->isIdenticalTo($asserter)
  675. ->object($asserter->strictlyNotContainsValues(array('1', '2')))->isIdenticalTo($asserter)
  676. ->object($asserter->strictlyNotContainsValues(array('1', '2', '3')))->isIdenticalTo($asserter)
  677. ->object($asserter->strictlyNotContainsValues(array('1', '2', '3', '4')))->isIdenticalTo($asserter)
  678. ->object($asserter->strictlyNotContainsValues(array('1', '2', '3', '4', '5')))->isIdenticalTo($asserter)
  679. ->object($asserter->strictlyNotContainsValues(array('6', '7')))->isIdenticalTo($asserter)
  680. ;
  681. }
  682. public function testHasKey()
  683. {
  684. $this
  685. ->given($asserter = $this->newTestedInstance
  686. ->setLocale($locale = new \mock\atoum\locale())
  687. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  688. )
  689. ->then
  690. ->exception(function() use ($asserter) { $asserter->hasKey(rand(0, PHP_INT_MAX)); })
  691. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  692. ->hasMessage('Array is undefined')
  693. ->if(
  694. $this->calling($locale)->_ = $notHasKey = uniqid(),
  695. $this->calling($analyzer)->getTypeOf = $type = uniqid(),
  696. $asserter->setWith(array())
  697. )
  698. ->then
  699. ->exception(function() use ($asserter, & $key) { $asserter->hasKey($key = rand(1, PHP_INT_MAX)); })
  700. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  701. ->hasMessage($notHasKey)
  702. ->mock($locale)->call('_')->withArguments('%s has no key %s', $asserter, $type)->once
  703. ->mock($analyzer)->call('getTypeOf')->withArguments($key)->once
  704. ->exception(function() use ($asserter, & $key, & $failMessage) { $asserter->hasKey($key = rand(1, PHP_INT_MAX), $failMessage = uniqid()); })
  705. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  706. ->hasMessage($failMessage)
  707. ->if($asserter->setWith(array(uniqid(), uniqid(), uniqid(), uniqid(), uniqid(), '5' => uniqid())))
  708. ->then
  709. ->object($asserter->hasKey(0))->isIdenticalTo($asserter)
  710. ->object($asserter->hasKey(1))->isIdenticalTo($asserter)
  711. ->object($asserter->hasKey(2))->isIdenticalTo($asserter)
  712. ->object($asserter->hasKey(3))->isIdenticalTo($asserter)
  713. ->object($asserter->hasKey(4))->isIdenticalTo($asserter)
  714. ->object($asserter->hasKey(5))->isIdenticalTo($asserter)
  715. ->object($asserter->hasKey('5'))->isIdenticalTo($asserter)
  716. ;
  717. }
  718. public function testNotHasKey()
  719. {
  720. $this
  721. ->given($asserter = $this->newTestedInstance
  722. ->setLocale($locale = new \mock\atoum\locale())
  723. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  724. )
  725. ->then
  726. ->exception(function() use ($asserter) { $asserter->notHasKey(rand(0, PHP_INT_MAX)); })
  727. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  728. ->hasMessage('Array is undefined')
  729. ->if($asserter->setWith(array()))
  730. ->then
  731. ->object($asserter->notHasKey(rand(-PHP_INT_MAX, PHP_INT_MAX)))->isIdenticalTo($asserter)
  732. ->object($asserter->notHasKey(uniqid()))->isIdenticalTo($asserter)
  733. ->if(
  734. $this->calling($locale)->_ = $hasKey = uniqid(),
  735. $this->calling($analyzer)->getTypeOf = $keyType = uniqid(),
  736. $asserter->setWith(array(uniqid(), uniqid(), uniqid(), uniqid(), uniqid()))
  737. )
  738. ->then
  739. ->exception(function() use ($asserter) { $asserter->notHasKey(0); })
  740. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  741. ->hasMessage($hasKey)
  742. ->mock($locale)->call('_')->withArguments('%s has key %s', $asserter, $keyType)->once
  743. ->mock($analyzer)->call('getTypeOf')->withArguments(0)->once
  744. ->exception(function() use ($asserter) { $asserter->notHasKey('0'); })
  745. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  746. ->hasMessage($hasKey)
  747. ->mock($locale)->call('_')->withArguments('%s has key %s', $asserter, $keyType)->twice
  748. ->mock($analyzer)->call('getTypeOf')->withIdenticalArguments('0')->once
  749. ;
  750. }
  751. public function testNotHasKeys()
  752. {
  753. $this
  754. ->given($asserter = $this->newTestedInstance
  755. ->setLocale($locale = new \mock\atoum\locale())
  756. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  757. )
  758. ->then
  759. ->exception(function() use ($asserter) { $asserter->notHasKeys(array(rand(0, PHP_INT_MAX))); })
  760. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  761. ->hasMessage('Array is undefined')
  762. ->if($asserter->setWith(array()))
  763. ->then
  764. ->object($asserter->notHasKeys(range(1, 5)))->isIdenticalTo($asserter)
  765. ->object($asserter->notHasKeys(array(uniqid(), uniqid())))->isIdenticalTo($asserter)
  766. ->if(
  767. $this->calling($locale)->_ = $hasKeys = uniqid(),
  768. $this->calling($analyzer)->getTypeOf = $keysType = uniqid(),
  769. $asserter->setWith(array(uniqid(), uniqid(), uniqid(), uniqid(), uniqid()))
  770. )
  771. ->then
  772. ->exception(function() use ($asserter) { $asserter->notHasKeys(array(0, 'premier', '2')); })
  773. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  774. ->hasMessage($hasKeys)
  775. ->mock($locale)->call('_')->withArguments('%s has keys %s', $asserter, $keysType)->once
  776. ->mock($analyzer)->call('getTypeOf')->withIdenticalArguments(array(0 => 0, 2 => '2'))->once
  777. ->exception(function() use ($asserter, & $failMessage) { $asserter->notHasKeys(array(0, 'premier', 2), $failMessage = uniqid()); })
  778. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  779. ->hasMessage($failMessage)
  780. ->object($asserter->notHasKeys(array(5, '6')))->isIdenticalTo($asserter)
  781. ;
  782. }
  783. public function testHasKeys()
  784. {
  785. $this
  786. ->given($asserter = $this->newTestedInstance
  787. ->setLocale($locale = new \mock\atoum\locale())
  788. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  789. )
  790. ->then
  791. ->exception(function() use ($asserter) { $asserter->hasKeys(array(rand(0, PHP_INT_MAX))); })
  792. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  793. ->hasMessage('Array is undefined')
  794. ->if(
  795. $this->calling($locale)->_ = $notHasKeys = uniqid(),
  796. $this->calling($analyzer)->getTypeOf = $keysType = uniqid(),
  797. $asserter->setWith(array())
  798. )
  799. ->then
  800. ->exception(function() use ($asserter) { $asserter->hasKeys(array(0, 1, 2)); })
  801. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  802. ->hasMessage($notHasKeys)
  803. ->mock($locale)->call('_')->withArguments('%s has no keys %s', $asserter, $keysType)->once
  804. ->mock($analyzer)->call('getTypeOf')->withIdenticalArguments(array(0, 1, 2))->once
  805. ->exception(function() use ($asserter, & $failMessage) { $asserter->hasKeys(array(0), $failMessage = uniqid()); })
  806. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  807. ->hasMessage($failMessage)
  808. ->if($asserter->setWith(array(uniqid(), uniqid(), uniqid(), uniqid(), uniqid())))
  809. ->then
  810. ->exception(function() use ($asserter) { $asserter->hasKeys(array(0, 'first', 2, 'second')); })
  811. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  812. ->hasMessage($notHasKeys)
  813. ->mock($locale)->call('_')->withArguments('%s has no keys %s', $asserter, $keysType)->twice
  814. ->mock($analyzer)->call('getTypeOf')->withIdenticalArguments(array(1 => 'first', 3 => 'second'))->once
  815. ->object($asserter->hasKeys(array(0, 2, 4)))->isIdenticalTo($asserter)
  816. ;
  817. }
  818. public function testKeys()
  819. {
  820. $this
  821. ->given($asserter = $this->newTestedInstance)
  822. ->then
  823. ->exception(function() use ($asserter) { $asserter->keys; })
  824. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  825. ->hasMessage('Array is undefined')
  826. ->if($asserter->setWith(array()))
  827. ->then
  828. ->object($array = $asserter->keys)->isInstanceOf('mageekguy\atoum\asserters\phpArray')
  829. ->array($array->getValue())->isEqualTo(array())
  830. ->if($asserter->setWith(array($key1 = uniqid() => uniqid(), $key2 = uniqid() => uniqid())))
  831. ->then
  832. ->object($array = $asserter->keys)->isInstanceOf('mageekguy\atoum\asserters\phpArray')
  833. ->array($array->getValue())->isEqualTo(array($key1, $key2))
  834. ;
  835. }
  836. public function testSize()
  837. {
  838. $this
  839. ->given($asserter = $this->newTestedInstance)
  840. ->then
  841. ->exception(function() use ($asserter) { $asserter->size; })
  842. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  843. ->hasMessage('Array is undefined')
  844. ->if($asserter->setWith(array()))
  845. ->then
  846. ->object($integer = $asserter->size)->isInstanceOf('mageekguy\atoum\asserters\integer')
  847. ->integer($integer->getValue())->isEqualTo(0)
  848. ->if($asserter->setWith(array(uniqid(), uniqid())))
  849. ->then
  850. ->object($integer = $asserter->size)->isInstanceOf('mageekguy\atoum\asserters\integer')
  851. ->integer($integer->getValue())->isEqualTo(2)
  852. ;
  853. }
  854. public function testIsEqualTo()
  855. {
  856. $this
  857. ->given($asserter = $this->newTestedInstance
  858. ->setLocale($locale = new \mock\atoum\locale())
  859. ->setDiff($diff = new \mock\atoum\tools\diffs\variable())
  860. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  861. ->setGenerator($generator = new \mock\atoum\asserter\generator())
  862. )
  863. ->then
  864. ->exception(function() use ($asserter) { $asserter->isEqualTo(array()); })
  865. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  866. ->hasMessage('Array is undefined')
  867. ->if($asserter->setWith(array()))
  868. ->then
  869. ->object($asserter->isEqualTo(array()))->isIdenticalTo($asserter)
  870. ->if($asserter->setWith($array = range(1, 5)))
  871. ->then
  872. ->object($asserter->isEqualTo($array))->isIdenticalTo($asserter)
  873. ->if(
  874. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  875. $this->calling($diff)->__toString = $diffValue = uniqid(),
  876. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  877. )
  878. ->then
  879. ->exception(function() use ($asserter, & $notEqualValue) { $asserter->isEqualTo($notEqualValue = uniqid()); })
  880. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  881. ->hasMessage($localizedMessage . PHP_EOL . $diffValue)
  882. ->mock($locale)->call('_')->withArguments('%s is not equal to %s', $asserter, $type)->once
  883. ->mock($analyzer)->call('getTypeOf')->withArguments($notEqualValue)->once
  884. ->object($asserter->isEqualTo($array))->isIdenticalTo($asserter)
  885. ->given(
  886. $this->calling($generator)->__get = $integerAsserter = new \mock\atoum\asserters\integer(),
  887. $this->calling($integerAsserter)->isEqualTo->throw = $exception = new \exception(uniqid())
  888. )
  889. ->if($asserter->integer)
  890. ->then
  891. ->exception(function() use ($asserter, & $notEqualValue) { $asserter->isEqualTo($notEqualValue = uniqid()); })
  892. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  893. ->hasMessage($localizedMessage . PHP_EOL . $diffValue)
  894. ->mock($locale)->call('_')->withArguments('%s is not equal to %s', $asserter, $type)->twice
  895. ->mock($analyzer)->call('getTypeOf')->withArguments($notEqualValue)->once
  896. ->mock($integerAsserter)->call('isEqualTo')->never
  897. ->if($asserter->integer[2])
  898. ->then
  899. ->exception(function() use ($asserter, & $expectedValue) { $asserter->isEqualTo($expectedValue = rand(4, PHP_INT_MAX)); })
  900. ->isIdenticalTo($exception)
  901. ->mock($integerAsserter)->call('isEqualTo')->withArguments($expectedValue)->once
  902. ->if($this->method($integerAsserter)->isEqualTo->isFluent())
  903. ->then
  904. ->object($asserter->isEqualTo(3))->isIdenticalTo($asserter)
  905. ->mock($integerAsserter)->call('isEqualTo')->withArguments(3)->once
  906. ;
  907. }
  908. public function testIsNotEqualTo()
  909. {
  910. $this
  911. ->given($asserter = $this->newTestedInstance
  912. ->setLocale($locale = new \mock\atoum\locale())
  913. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  914. ->setGenerator($generator = new \mock\atoum\asserter\generator())
  915. )
  916. ->then
  917. ->exception(function() use ($asserter) { $asserter->isNotEqualTo(array()); })
  918. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  919. ->hasMessage('Array is undefined')
  920. ->if($asserter->setWith(array()))
  921. ->then
  922. ->object($asserter->isNotEqualTo(range(1, 2)))->isIdenticalTo($asserter)
  923. ->if(
  924. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  925. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  926. )
  927. ->then
  928. ->exception(function() use ($asserter) { $asserter->isNotEqualTo(array()); })
  929. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  930. ->hasMessage($localizedMessage)
  931. ->mock($locale)->call('_')->withArguments('%s is equal to %s', $asserter, $type)->once
  932. ->mock($analyzer)->call('getTypeOf')->withArguments(array())->once
  933. ->if($asserter->setWith($array = range(1, 5)))
  934. ->then
  935. ->object($asserter->isNotEqualTo(array()))->isIdenticalTo($asserter)
  936. ->exception(function() use ($asserter, $array) { $asserter->isNotEqualTo($array); })
  937. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  938. ->hasMessage($localizedMessage)
  939. ->mock($locale)->call('_')->withArguments('%s is equal to %s', $asserter, $type)->twice
  940. ->mock($analyzer)->call('getTypeOf')->withArguments($array)->once
  941. ->given(
  942. $this->calling($generator)->__get = $integerAsserter = new \mock\atoum\asserters\integer(),
  943. $this->calling($integerAsserter)->isNotEqualTo->throw = $exception = new \exception(uniqid())
  944. )
  945. ->if($asserter->integer)
  946. ->then
  947. ->object($asserter->isNotEqualTo(array()))->isIdenticalTo($asserter)
  948. ->exception(function() use ($asserter, $array) { $asserter->isNotEqualTo($array); })
  949. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  950. ->hasMessage($localizedMessage)
  951. ->mock($locale)->call('_')->withArguments('%s is equal to %s', $asserter, $type)->thrice
  952. ->mock($analyzer)->call('getTypeOf')->withArguments($array)->twice
  953. ->mock($integerAsserter)->call('isNotIdenticalTo')->never
  954. ->if($asserter->integer[2])
  955. ->then
  956. ->exception(function() use ($asserter, & $expectedValue) { $asserter->isNotEqualTo($expectedValue = rand(4, PHP_INT_MAX)); })
  957. ->isIdenticalTo($exception)
  958. ->mock($integerAsserter)->call('isNotEqualTo')->withArguments($expectedValue)->once
  959. ->if($this->method($integerAsserter)->isNotEqualTo->isFluent())
  960. ->then
  961. ->object($asserter->isNotEqualTo(3))->isIdenticalTo($asserter)
  962. ->mock($integerAsserter)->call('isNotEqualTo')->withArguments(3)->once
  963. ;
  964. }
  965. public function testIsIdenticalTo()
  966. {
  967. $this
  968. ->given($asserter = $this->newTestedInstance
  969. ->setLocale($locale = new \mock\atoum\locale())
  970. ->setDiff($diff = new \mock\atoum\tools\diffs\variable())
  971. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  972. ->setGenerator($generator = new \mock\atoum\asserter\generator())
  973. )
  974. ->then
  975. ->exception(function() use ($asserter) { $asserter->isIdenticalTo(new \mock\object()); })
  976. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  977. ->hasMessage('Array is undefined')
  978. ->if($asserter->setWith(array($object = new \mock\object(), 2)))
  979. ->then
  980. ->object($asserter->isIdenticalTo(array($object, 2)))->isIdenticalTo($asserter)
  981. ->if(
  982. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  983. $this->calling($diff)->__toString = $diffValue = uniqid(),
  984. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  985. )
  986. ->then
  987. ->exception(function() use ($asserter, & $notIdenticalValue) { $asserter->isIdenticalTo($notIdenticalValue = uniqid()); })
  988. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  989. ->hasMessage($localizedMessage . PHP_EOL . $diffValue)
  990. ->mock($locale)->call('_')->withArguments('%s is not identical to %s', $asserter, $type)->once
  991. ->mock($analyzer)->call('getTypeOf')->withArguments($notIdenticalValue)->once
  992. ->given(
  993. $this->calling($generator)->__get = $integerAsserter = new \mock\atoum\asserters\integer(),
  994. $this->calling($integerAsserter)->isIdenticalTo->throw = $exception = new \exception(uniqid())
  995. )
  996. ->if($asserter->integer)
  997. ->then
  998. ->object($asserter->isIdenticalTo(array($object, 2)))->isIdenticalTo($asserter)
  999. ->exception(function() use ($asserter, & $notIdenticalValue) { $asserter->isIdenticalTo($notIdenticalValue = uniqid()); })
  1000. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  1001. ->hasMessage($localizedMessage . PHP_EOL . $diffValue)
  1002. ->mock($locale)->call('_')->withArguments('%s is not identical to %s', $asserter, $type)->twice
  1003. ->mock($analyzer)->call('getTypeOf')->withArguments($notIdenticalValue)->once
  1004. ->if($asserter->integer[1])
  1005. ->then
  1006. ->exception(function() use ($asserter, & $expectedValue) { $asserter->isIdenticalTo($expectedValue = rand(4, PHP_INT_MAX)); })
  1007. ->isIdenticalTo($exception)
  1008. ->mock($integerAsserter)->call('isIdenticalTo')->withArguments($expectedValue)->once
  1009. ->if($this->method($integerAsserter)->isIdenticalTo->isFluent())
  1010. ->then
  1011. ->object($asserter->isEqualTo(2))->isIdenticalTo($asserter)
  1012. ->mock($integerAsserter)->call('isIdenticalTo')->withArguments($expectedValue)->once
  1013. ;
  1014. }
  1015. public function testIsNotIdenticalTo()
  1016. {
  1017. $this
  1018. ->given($asserter = $this->newTestedInstance
  1019. ->setLocale($locale = new \mock\atoum\locale())
  1020. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  1021. ->setGenerator($generator = new \mock\atoum\asserter\generator())
  1022. )
  1023. ->then
  1024. ->exception(function() use ($asserter) { $asserter->isNotIdenticalTo(new \mock\object()); })
  1025. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  1026. ->hasMessage('Array is undefined')
  1027. ->if($asserter->setWith($array = array(1, 2)))
  1028. ->then
  1029. ->object($asserter->isNotIdenticalTo(array('1', 2)))->isIdenticalTo($asserter)
  1030. ->if(
  1031. $this->calling($locale)->_ = $localizedMessage = uniqid(),
  1032. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  1033. )
  1034. ->then
  1035. ->exception(function() use ($asserter, $array) { $asserter->isNotIdenticalTo($array); })
  1036. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  1037. ->hasMessage($localizedMessage)
  1038. ->mock($locale)->call('_')->withArguments('%s is identical to %s', $asserter, $type)->once
  1039. ->mock($analyzer)->call('getTypeOf')->withArguments($array)->once
  1040. ->given(
  1041. $this->calling($generator)->__get = $integerAsserter = new \mock\atoum\asserters\integer(),
  1042. $this->calling($integerAsserter)->isNotIdenticalTo->throw = $exception = new \exception(uniqid())
  1043. )
  1044. ->if($asserter->integer)
  1045. -

Large files files are truncated, but you can click here to view the full file