PageRenderTime 82ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/units/classes/asserters/string.php

http://github.com/mageekguy/atoum
PHP | 592 lines | 515 code | 77 blank | 0 comment | 0 complexity | eacda056a01f44ae595e4bdb02e03de7 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\asserters;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\asserter,
  6. mageekguy\atoum\tools\diffs,
  7. mageekguy\atoum\tools\variable
  8. ;
  9. require_once __DIR__ . '/../../runner.php';
  10. class string extends atoum\test
  11. {
  12. public function testClass()
  13. {
  14. $this->testedClass->extends('mageekguy\atoum\asserters\variable');
  15. }
  16. public function test__construct()
  17. {
  18. $this
  19. ->given($this->newTestedInstance)
  20. ->then
  21. ->object($this->testedInstance->getGenerator())->isEqualTo(new asserter\generator())
  22. ->object($this->testedInstance->getAnalyzer())->isEqualTo(new variable\analyzer())
  23. ->object($this->testedInstance->getLocale())->isEqualTo(new atoum\locale())
  24. ->variable($this->testedInstance->getValue())->isNull()
  25. ->variable($this->testedInstance->getCharlist())->isNull()
  26. ->boolean($this->testedInstance->wasSet())->isFalse()
  27. ->if($this->newTestedInstance($generator = new asserter\generator(), $analyzer = new variable\analyzer(), $locale = new atoum\locale()))
  28. ->then
  29. ->object($this->testedInstance->getGenerator())->isIdenticalTo($generator)
  30. ->object($this->testedInstance->getAnalyzer())->isIdenticalTo($analyzer)
  31. ->object($this->testedInstance->getLocale())->isIdenticalTo($locale)
  32. ->variable($this->testedInstance->getValue())->isNull()
  33. ->variable($this->testedInstance->getCharlist())->isNull()
  34. ->boolean($this->testedInstance->wasSet())->isFalse()
  35. ;
  36. }
  37. public function test__toString()
  38. {
  39. $this
  40. ->given($this->newTestedInstance
  41. ->setLocale($locale = new \mock\atoum\locale())
  42. )
  43. ->if(
  44. $this->testedInstance->setWith($value = uniqid()),
  45. $this->calling($locale)->_ = $string = uniqid()
  46. )
  47. ->then
  48. ->castToString($this->testedInstance)->isEqualTo($string)
  49. ->mock($locale)->call('_')->withArguments('string(%s) \'%s\'', strlen($value), addcslashes($value, null))->once
  50. ->if($this->testedInstance->setWith($value = "\010" . uniqid() . "\010", $charlist = "\010"))
  51. ->then
  52. ->castToString($this->testedInstance)->isEqualTo($string)
  53. ->mock($locale)->call('_')->withArguments('string(%s) \'%s\'', strlen($value), addcslashes($value, "\010"))->once
  54. ;
  55. }
  56. public function testSetWith()
  57. {
  58. $this
  59. ->given($asserter = $this->newTestedInstance
  60. ->setLocale($locale = new \mock\atoum\locale())
  61. ->setAnalyzer($analyzer = new \mock\atoum\tools\variable\analyzer())
  62. )
  63. ->if(
  64. $this->calling($locale)->_ = $notString = uniqid(),
  65. $this->calling($analyzer)->isString = false,
  66. $this->calling($analyzer)->getTypeOf = $type = uniqid()
  67. )
  68. ->then
  69. ->exception(function() use ($asserter, & $value) { $asserter->setWith($value = rand(- PHP_INT_MAX, PHP_INT_MAX)); })
  70. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  71. ->hasMessage($notString)
  72. ->mock($locale)->call('_')->withArguments('%s is not a string', $type)->once
  73. ->mock($analyzer)->call('getTypeOf')->withArguments($value)->once
  74. ->integer($asserter->getValue())->isEqualTo($value)
  75. ->variable($asserter->getCharlist())->isNull()
  76. ->if(
  77. $this->calling($analyzer)->isString = true
  78. )
  79. ->then
  80. ->object($asserter->setWith($value = uniqid()))->isIdenticalTo($asserter)
  81. ->string($asserter->getValue())->isEqualTo($value)
  82. ->variable($asserter->getCharlist())->isNull()
  83. ->object($asserter->setWith($value = uniqid(), $charlist = "\010"))->isIdenticalTo($asserter)
  84. ->string($asserter->getValue())->isEqualTo($value)
  85. ->string($asserter->getCharlist())->isEqualTo($charlist)
  86. ;
  87. }
  88. public function testIsEqualTo()
  89. {
  90. $this
  91. ->given($asserter = $this->newTestedInstance)
  92. ->then
  93. ->exception(function() use ($asserter) { $asserter->isEqualTo(uniqid()); })
  94. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  95. ->hasMessage('Value is undefined')
  96. ->if(
  97. $asserter
  98. ->setWith($firstString = uniqid())
  99. ->setLocale($locale = new \mock\atoum\locale())
  100. ->setDiff($diff = new \mock\atoum\tools\diffs\variable()),
  101. $this->calling($locale)->_ = $notEqual = uniqid(),
  102. $this->calling($diff)->__toString = $diffValue = uniqid()
  103. )
  104. ->then
  105. ->exception(function() use ($asserter, & $secondString) { $asserter->isEqualTo($secondString = uniqid()); })
  106. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  107. ->hasMessage($notEqual . PHP_EOL . $diffValue)
  108. ->mock($locale)->call('_')->withArguments('strings are not equal')->once
  109. ->mock($diff)
  110. ->call('setExpected')->withArguments($secondString)->once
  111. ->call('setActual')->withArguments($firstString)->once
  112. ->exception(function() use ($asserter, & $secondString, & $failMessage) { $asserter->isEqualTo($secondString = uniqid(), $failMessage = uniqid()); })
  113. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  114. ->hasMessage($failMessage . PHP_EOL . $diffValue)
  115. ->mock($diff)
  116. ->call('setExpected')->withArguments($secondString)->once
  117. ->call('setActual')->withArguments($firstString)->twice
  118. ->object($asserter->isEqualTo($firstString))->isIdenticalTo($asserter)
  119. ;
  120. }
  121. public function testIsEqualToFileContents()
  122. {
  123. $this
  124. ->if($asserter = $this->newTestedInstance)
  125. ->then
  126. ->exception(function() use ($asserter) { $asserter->isEqualToContentsOfFile(uniqid()); })
  127. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  128. ->hasMessage('Value is undefined')
  129. ->if(
  130. $asserter
  131. ->setWith($firstString = uniqid())
  132. ->setLocale($locale = new \mock\atoum\locale())
  133. ->setDiff($diff = new \mock\atoum\tools\diffs\variable()),
  134. $this->calling($locale)->_ = $unableToGetContents = uniqid(),
  135. $this->function->file_get_contents = false
  136. )
  137. ->then
  138. ->exception(function() use ($asserter, & $path) { $asserter->isEqualToContentsOfFile($path = uniqid()); })
  139. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  140. ->hasMessage($unableToGetContents)
  141. ->mock($locale)->call('_')->withArguments('Unable to get contents of file %s', $path)->once
  142. ->if(
  143. $this->calling($diff)->__toString = $diffValue = uniqid(),
  144. $this->function->file_get_contents = $fileContents = uniqid(),
  145. $this->calling($locale)->_ = $notEqual = uniqid()
  146. )
  147. ->then
  148. ->exception(function() use ($asserter, $path) { $asserter->isEqualToContentsOfFile($path); })
  149. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  150. ->hasMessage($notEqual . PHP_EOL . $diffValue)
  151. ->mock($locale)->call('_')->withArguments('string is not equal to contents of file %s', $path)->once
  152. ->mock($diff)
  153. ->call('setExpected')->withArguments($fileContents)->once
  154. ->call('setActual')->withArguments($firstString)->once
  155. ->exception(function() use ($asserter, & $failMessage) { $asserter->isEqualToContentsOfFile(uniqid(), $failMessage = uniqid()); })
  156. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  157. ->hasMessage($failMessage . PHP_EOL . $diffValue)
  158. ->if($this->function->file_get_contents = $firstString)
  159. ->then
  160. ->object($asserter->isEqualToContentsOfFile($path))->isIdenticalTo($asserter)
  161. ;
  162. }
  163. public function testIsEmpty()
  164. {
  165. $this
  166. ->if($asserter = $this->newTestedInstance)
  167. ->then
  168. ->exception(function() use ($asserter) { $asserter->isEmpty(); })
  169. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  170. ->hasMessage('Value is undefined')
  171. ->if(
  172. $asserter
  173. ->setWith($firstString = uniqid())
  174. ->setLocale($locale = new \mock\atoum\locale())
  175. ->setDiff($diff = new \mock\atoum\tools\diffs\variable()),
  176. $this->calling($locale)->_ = $notEmpty = uniqid(),
  177. $this->calling($diff)->__toString = $diffValue = uniqid()
  178. )
  179. ->then
  180. ->exception(function() use ($asserter) { $asserter->isEmpty(); })
  181. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  182. ->hasMessage($notEmpty . PHP_EOL . $diffValue)
  183. ->mock($locale)->call('_')->withArguments('string is not empty')->once
  184. ->mock($diff)
  185. ->call('setExpected')->withArguments('')->once
  186. ->call('setActual')->withArguments($firstString)->once
  187. ->exception(function() use ($asserter) { $asserter->isEmpty; })
  188. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  189. ->hasMessage($notEmpty . PHP_EOL . $diffValue)
  190. ->mock($locale)->call('_')->withArguments('string is not empty')->twice
  191. ->mock($diff)
  192. ->call('setExpected')->withArguments('')->twice
  193. ->call('setActual')->withArguments($firstString)->twice
  194. ->exception(function() use ($asserter, & $failMessage) { $asserter->isEmpty($failMessage = uniqid()); })
  195. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  196. ->hasMessage($failMessage . PHP_EOL . $diffValue)
  197. ->if($asserter->setWith(''))
  198. ->then
  199. ->object($asserter->isEmpty())->isIdenticalTo($asserter)
  200. ;
  201. }
  202. public function testIsNotEmpty()
  203. {
  204. $this
  205. ->if($asserter = $this->newTestedInstance)
  206. ->then
  207. ->exception(function() use ($asserter) { $asserter->isNotEmpty(); })
  208. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  209. ->hasMessage('Value is undefined')
  210. ->if(
  211. $asserter
  212. ->setWith('')
  213. ->setLocale($locale = new \mock\atoum\locale()),
  214. $this->calling($locale)->_ = $isEmpty = uniqid()
  215. )
  216. ->then
  217. ->exception(function() use ($asserter) { $asserter->isNotEmpty(); })
  218. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  219. ->hasMessage($isEmpty)
  220. ->mock($locale)->call('_')->withArguments('string is empty')->once
  221. ->exception(function() use ($asserter) { $asserter->isNotEmpty; })
  222. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  223. ->hasMessage($isEmpty)
  224. ->mock($locale)->call('_')->withArguments('string is empty')->twice
  225. ->exception(function() use ($asserter, & $failMessage) { $asserter->isNotEmpty($failMessage = uniqid()); })
  226. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  227. ->hasMessage($failMessage)
  228. ->if($asserter->setWith(uniqid()))
  229. ->then
  230. ->object($asserter->isNotEmpty())->isIdenticalTo($asserter)
  231. ;
  232. }
  233. public function testHasLength()
  234. {
  235. $this
  236. ->if($asserter = $this->newTestedInstance)
  237. ->then
  238. ->exception(function() use ($asserter) { $asserter->hasLength(rand(0, PHP_INT_MAX)); })
  239. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  240. ->hasMessage('Value is undefined')
  241. ->if(
  242. $asserter
  243. ->setWith('')
  244. ->setLocale($locale = new \mock\atoum\locale()),
  245. $this->calling($locale)->_ = $hasNotLength = uniqid()
  246. )
  247. ->then
  248. ->exception(function() use ($asserter, & $requiredLength) { $asserter->hasLength($requiredLength = rand(1, PHP_INT_MAX)); })
  249. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  250. ->hasMessage($hasNotLength)
  251. ->mock($locale)->call('_')->withArguments('length of %s is not %d', $asserter, $requiredLength)->once
  252. ->exception(function() use ($asserter, & $failMessage) { $asserter->hasLength(rand(1, PHP_INT_MAX), $failMessage = uniqid()); })
  253. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  254. ->hasMessage($failMessage)
  255. ->if($asserter->setWith($string = uniqid()))
  256. ->then
  257. ->object($asserter->hasLength(strlen($string)))->isIdenticalTo($asserter)
  258. ;
  259. }
  260. public function testHasLengthGreaterThan()
  261. {
  262. $this
  263. ->if($asserter = $this->newTestedInstance)
  264. ->then
  265. ->exception(function() use ($asserter) { $asserter->hasLengthGreaterThan(rand(0, PHP_INT_MAX)); })
  266. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  267. ->hasMessage('Value is undefined')
  268. ->if(
  269. $asserter
  270. ->setWith('Chuck Norris')
  271. ->setLocale($locale = new \mock\atoum\locale()),
  272. $this->calling($locale)->_ = $lengthNotGreater = uniqid()
  273. )
  274. ->then
  275. ->exception(function() use ($asserter, & $requiredLength) { $asserter->hasLengthGreaterThan($requiredLength = rand(1, PHP_INT_MAX)); })
  276. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  277. ->hasMessage($lengthNotGreater)
  278. ->mock($locale)->call('_')->withArguments('length of %s is not greater than %d', $asserter, $requiredLength)->once
  279. ->exception(function() use ($asserter, & $failMessage) { $asserter->hasLengthGreaterThan(rand(1, PHP_INT_MAX), $failMessage = uniqid()); })
  280. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  281. ->hasMessage($failMessage)
  282. ->if($asserter->setWith($string = uniqid()))
  283. ->then
  284. ->object($asserter->hasLengthGreaterThan(strlen($string)-1))->isIdenticalTo($asserter)
  285. ;
  286. }
  287. public function testHasLengthLessThan()
  288. {
  289. $this
  290. ->if($asserter = $this->newTestedInstance)
  291. ->then
  292. ->exception(function() use ($asserter) { $asserter->hasLengthLessThan(rand(0, PHP_INT_MAX)); })
  293. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  294. ->hasMessage('Value is undefined')
  295. ->if(
  296. $asserter
  297. ->setWith('Chuck Norris')
  298. ->setLocale($locale = new \mock\atoum\locale()),
  299. $this->calling($locale)->_ = $lengthNotLess = uniqid()
  300. )
  301. ->then
  302. ->exception(function() use ($asserter, & $requiredLength) { $asserter->hasLengthLessThan($requiredLength = 10); })
  303. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  304. ->hasMessage($lengthNotLess)
  305. ->mock($locale)->call('_')->withArguments('length of %s is not less than %d', $asserter, $requiredLength)->once
  306. ->exception(function() use ($asserter, & $failMessage) { $asserter->hasLengthLessThan(10, $failMessage = uniqid()); })
  307. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  308. ->hasMessage($failMessage)
  309. ->if($asserter->setWith($string = uniqid()))
  310. ->then
  311. ->object($asserter->hasLengthLessThan(strlen($string) + 1))->isIdenticalTo($asserter)
  312. ;
  313. }
  314. public function testContains()
  315. {
  316. $this
  317. ->if($asserter = $this->newTestedInstance)
  318. ->then
  319. ->exception(function() use ($asserter) { $asserter->contains(uniqid()); })
  320. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  321. ->hasMessage('Value is undefined')
  322. ->if(
  323. $asserter
  324. ->setWith($string = 'Chuck Norris')
  325. ->setLocale($locale = new \mock\atoum\locale()),
  326. $this->calling($locale)->_ = $notContains = uniqid()
  327. )
  328. ->then
  329. ->exception(function() use ($asserter, & $fragment) { $asserter->contains($fragment = uniqid()); })
  330. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  331. ->hasMessage($notContains)
  332. ->mock($locale)->call('_')->withArguments('%s does not contain %s', $asserter, $fragment)->once
  333. ->exception(function() use ($asserter, & $failMessage) { $asserter->contains(uniqid(), $failMessage = uniqid()); })
  334. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  335. ->hasMessage($failMessage)
  336. ->if($asserter->setWith(uniqid() . $string . uniqid()))
  337. ->then
  338. ->object($asserter->contains($string))->isIdenticalTo($asserter)
  339. ->exception(function() use ($asserter, $string, & $fragment) { $asserter->contains($fragment = strtoupper($string)); })
  340. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  341. ->hasMessage($notContains)
  342. ->mock($locale)->call('_')->withArguments('%s does not contain %s', $asserter, $fragment)->once
  343. ;
  344. }
  345. public function testNotContains()
  346. {
  347. $this
  348. ->if($asserter = $this->newTestedInstance)
  349. ->then
  350. ->exception(function() use ($asserter) { $asserter->notContains(uniqid()); })
  351. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  352. ->hasMessage('Value is undefined')
  353. ->if(
  354. $asserter
  355. ->setWith($string = 'FreeAgent scans the field')
  356. ->setLocale($locale = new \mock\atoum\locale()),
  357. $this->calling($locale)->_ = $contains = uniqid()
  358. )
  359. ->then
  360. ->exception(function() use ($asserter, & $fragment) { $asserter->notContains($fragment = 'Agent'); })
  361. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  362. ->hasMessage($contains)
  363. ->mock($locale)->call('_')->withArguments('%s contains %s', $asserter, $fragment)->once
  364. ->exception(function() use ($asserter, & $failMessage) { $asserter->notContains('Agent', $failMessage = uniqid()); })
  365. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  366. ->hasMessage($failMessage)
  367. ->object($asserter->notContains('agent'))->isIdenticalTo($asserter)
  368. ->object($asserter->notContains(uniqid()))->isIdenticalTo($asserter)
  369. ;
  370. }
  371. public function testStartWith()
  372. {
  373. $this
  374. ->if($asserter = $this->newTestedInstance)
  375. ->then
  376. ->exception(function() use ($asserter) { $asserter->startWith(uniqid()); })
  377. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  378. ->hasMessage('Value is undefined')
  379. ->if(
  380. $asserter
  381. ->setWith('FreeAgent scans the field')
  382. ->setLocale($locale = new \mock\atoum\locale()),
  383. $this->calling($locale)->_ = $notStartWith = uniqid()
  384. )
  385. ->then
  386. ->exception(function() use ($asserter, & $fragment) { $asserter->startWith($fragment = uniqid()); })
  387. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  388. ->hasMessage($notStartWith)
  389. ->mock($locale)->call('_')->withArguments('%s does not start with %s', $asserter, $fragment)->once
  390. ->exception(function() use ($asserter, & $failMessage) { $asserter->startWith(uniqid(), $failMessage = uniqid()); })
  391. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  392. ->hasMessage($failMessage)
  393. ->exception(function() use ($asserter, & $fragment) { $asserter->startWith($fragment = 'free'); })
  394. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  395. ->hasMessage($notStartWith)
  396. ->mock($locale)->call('_')->withArguments('%s does not start with %s', $asserter, $fragment)->once
  397. ->exception(function() use ($asserter, & $fragment) { $asserter->startWith($fragment = 'Free' . uniqid()); })
  398. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  399. ->hasMessage($notStartWith)
  400. ->mock($locale)->call('_')->withArguments('%s does not start with %s', $asserter, $fragment)->once
  401. ->exception(function() use ($asserter, & $fragment) { $asserter->startWith('field'); })
  402. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  403. ->hasMessage($notStartWith)
  404. ->mock($locale)->call('_')->withArguments('%s does not start with %s', $asserter, 'field')->once
  405. ->object($asserter->startWith('Free'))->isIdenticalTo($asserter)
  406. ;
  407. }
  408. public function testNotStartWith()
  409. {
  410. $this
  411. ->if($asserter = $this->newTestedInstance)
  412. ->then
  413. ->exception(function() use ($asserter) { $asserter->notStartWith(uniqid()); })
  414. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  415. ->hasMessage('Value is undefined')
  416. ->if(
  417. $asserter
  418. ->setWith('FreeAgent scans the field')
  419. ->setLocale($locale = new \mock\atoum\locale()),
  420. $this->calling($locale)->_ = $startWith = uniqid()
  421. )
  422. ->then
  423. ->exception(function() use ($asserter, & $fragment) { $asserter->notStartWith($fragment = 'FreeA'); })
  424. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  425. ->hasMessage($startWith)
  426. ->mock($locale)->call('_')->withArguments('%s start with %s', $asserter, $fragment)->once
  427. ->exception(function() use ($asserter, & $failMessage) { $asserter->notStartWith('FreeAgent ', $failMessage = uniqid()); })
  428. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  429. ->hasMessage($failMessage)
  430. ->object($asserter->notStartWith('free'))->isIdenticalTo($asserter)
  431. ->object($asserter->notStartWith(uniqid()))->isIdenticalTo($asserter)
  432. ;
  433. }
  434. public function testEndWith()
  435. {
  436. $this
  437. ->if($asserter = $this->newTestedInstance)
  438. ->then
  439. ->exception(function() use ($asserter) { $asserter->endWith(uniqid()); })
  440. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  441. ->hasMessage('Value is undefined')
  442. ->if(
  443. $asserter
  444. ->setWith('FreeAgent scans the field')
  445. ->setLocale($locale = new \mock\atoum\locale()),
  446. $this->calling($locale)->_ = $notEndWith = uniqid()
  447. )
  448. ->then
  449. ->exception(function() use ($asserter, & $fragment) { $asserter->endWith($fragment = uniqid()); })
  450. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  451. ->hasMessage($notEndWith)
  452. ->mock($locale)->call('_')->withArguments('%s does not end with %s', $asserter, $fragment)->once
  453. ->exception(function() use ($asserter, & $failMessage) { $asserter->endWith(uniqid(), $failMessage = uniqid()); })
  454. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  455. ->hasMessage($failMessage)
  456. ->exception(function() use ($asserter, & $failMessage) { $asserter->endWith('FIELd'); })
  457. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  458. ->hasMessage($notEndWith)
  459. ->mock($locale)->call('_')->withArguments('%s does not end with %s', $asserter, 'FIELd')->once
  460. ->exception(function() use ($asserter, & $fragment) { $asserter->endWith($fragment = uniqid() . ' field'); })
  461. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  462. ->hasMessage($notEndWith)
  463. ->mock($locale)->call('_')->withArguments('%s does not end with %s', $asserter, $fragment)->once
  464. ->object($asserter->endWith('field'))->isIdenticalTo($asserter)
  465. ;
  466. }
  467. public function testNotEndWith()
  468. {
  469. $this
  470. ->if($asserter = $this->newTestedInstance)
  471. ->then
  472. ->exception(function() use ($asserter) { $asserter->notEndWith(uniqid()); })
  473. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  474. ->hasMessage('Value is undefined')
  475. ->if(
  476. $asserter
  477. ->setWith('FreeAgent scans the field')
  478. ->setLocale($locale = new \mock\atoum\locale()),
  479. $this->calling($locale)->_ = $endWith = uniqid()
  480. )
  481. ->then
  482. ->exception(function() use ($asserter, & $fragment) { $asserter->notEndWith($fragment = ' the field'); })
  483. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  484. ->hasMessage($endWith)
  485. ->mock($locale)->call('_')->withArguments('%s end with %s', $asserter, $fragment)->once
  486. ->exception(function() use ($asserter, & $failMessage) { $asserter->notEndWith(' the field', $failMessage = uniqid()); })
  487. ->isInstanceOf('mageekguy\atoum\asserter\exception')
  488. ->hasMessage($failMessage)
  489. ->object($asserter->notEndWith(' THE FIELD'))->isIdenticalTo($asserter)
  490. ->object($asserter->notEndWith(uniqid()))->isIdenticalTo($asserter)
  491. ;
  492. }
  493. public function testLength()
  494. {
  495. $this
  496. ->if($asserter = $this->newTestedInstance)
  497. ->then
  498. ->exception(function() use ($asserter) { $asserter->length; })
  499. ->isInstanceOf('mageekguy\atoum\exceptions\logic')
  500. ->hasMessage('Value is undefined')
  501. ->if($asserter->setWith(''))
  502. ->then
  503. ->object($integer = $asserter->length)
  504. ->isInstanceOf('mageekguy\atoum\asserters\integer')
  505. ->integer($integer->getValue())
  506. ->isEqualTo(0)
  507. ->if($asserter->setWith($string = uniqid()))
  508. ->then
  509. ->object($integer = $asserter->length)
  510. ->isInstanceOf('mageekguy\atoum\asserters\integer')
  511. ->integer($integer->getValue())
  512. ->isEqualTo(strlen($string))
  513. ;
  514. }
  515. }