PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/score.php

http://github.com/mageekguy/atoum
PHP | 1189 lines | 1155 code | 34 blank | 0 comment | 0 complexity | 8db694386f4e93302adef690d180f0e0 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\exceptions
  6. ;
  7. require_once __DIR__ . '/../runner.php';
  8. class score extends atoum\test
  9. {
  10. public function test__construct()
  11. {
  12. $this
  13. ->if($score = new atoum\score())
  14. ->then
  15. ->integer($score->getPassNumber())->isZero()
  16. ->array($score->getFailAssertions())->isEmpty()
  17. ->array($score->getExceptions())->isEmpty()
  18. ->array($score->getErrors())->isEmpty()
  19. ->array($score->getOutputs())->isEmpty()
  20. ->array($score->getDurations())->isEmpty()
  21. ->array($score->getMemoryUsages())->isEmpty()
  22. ->array($score->getUncompletedMethods())->isEmpty()
  23. ->array($score->getSkippedMethods())->isEmpty()
  24. ->object($score->getCoverage())->isInstanceOf('mageekguy\atoum\score\coverage')
  25. ->and($score = new atoum\score($coverage = new atoum\score\coverage()))
  26. ->then
  27. ->integer($score->getPassNumber())->isZero()
  28. ->array($score->getFailAssertions())->isEmpty()
  29. ->array($score->getExceptions())->isEmpty()
  30. ->array($score->getErrors())->isEmpty()
  31. ->array($score->getOutputs())->isEmpty()
  32. ->array($score->getDurations())->isEmpty()
  33. ->array($score->getMemoryUsages())->isEmpty()
  34. ->array($score->getUncompletedMethods())->isEmpty()
  35. ->array($score->getSkippedMethods())->isEmpty()
  36. ->object($score->getCoverage())->isIdenticalTo($coverage)
  37. ;
  38. }
  39. public function testAddException()
  40. {
  41. $this
  42. ->if($score = new atoum\score())
  43. ->then
  44. ->object($score->addException($file = uniqid(), $class = uniqid(), $method = uniqid(), $line = rand(1, PHP_INT_MAX), $exception = new \exception()))->isIdenticalTo($score)
  45. ->array($score->getExceptions())->isEqualTo(array(
  46. array(
  47. 'case' => null,
  48. 'dataSetKey' => null,
  49. 'dataSetProvider' => null,
  50. 'class' => $class,
  51. 'method' => $method,
  52. 'file' => $file,
  53. 'line' => $line,
  54. 'value' => (string) $exception
  55. )
  56. )
  57. )
  58. ->integer($score->getExceptionNumber())->isEqualTo(1)
  59. ->object($score->addException($otherFile = uniqid(), $otherClass = uniqid(), $otherMethod = uniqid(), $otherLine = rand(1, PHP_INT_MAX), $otherException = new \exception()))->isIdenticalTo($score)
  60. ->array($score->getExceptions())->isEqualTo(array(
  61. array(
  62. 'case' => null,
  63. 'dataSetKey' => null,
  64. 'dataSetProvider' => null,
  65. 'class' => $class,
  66. 'method' => $method,
  67. 'file' => $file,
  68. 'line' => $line,
  69. 'value' => (string) $exception
  70. ),
  71. array(
  72. 'case' => null,
  73. 'dataSetKey' => null,
  74. 'dataSetProvider' => null,
  75. 'class' => $otherClass,
  76. 'method' => $otherMethod,
  77. 'file' => $otherFile,
  78. 'line' => $otherLine,
  79. 'value' => (string) $otherException
  80. )
  81. )
  82. )
  83. ;
  84. }
  85. public function testAddPass()
  86. {
  87. $this
  88. ->if($score = new atoum\score())
  89. ->then
  90. ->object($score->addPass())->isIdenticalTo($score)
  91. ->integer($score->getPassNumber())->isEqualTo(1)
  92. ->object($score->addPass())->isIdenticalTo($score)
  93. ->integer($score->getPassNumber())->isEqualTo(2)
  94. ;
  95. }
  96. public function testAddFail()
  97. {
  98. $this
  99. ->if($score = new atoum\score())
  100. ->then
  101. ->integer($score->addFail($file = uniqid(), $class = uniqid(), $method = uniqid(), $line = rand(1, PHP_INT_MAX), $asserter = new atoum\asserters\integer(new atoum\asserter\generator()), $reason = uniqid()))->isGreaterThan(0)
  102. ->array($score->getFailAssertions())->isEqualTo(array(
  103. array(
  104. 'case' => null,
  105. 'dataSetKey' => null,
  106. 'dataSetProvider' => null,
  107. 'class' => $class,
  108. 'method' => $method,
  109. 'file' => $file,
  110. 'line' => $line,
  111. 'asserter' => $asserter,
  112. 'fail' => $reason
  113. )
  114. )
  115. )
  116. ->integer($score->addFail($otherFile = uniqid(), $otherClass = uniqid(), $otherMethod = uniqid(), $otherLine = rand(1, PHP_INT_MAX), $otherAsserter = new atoum\asserters\integer(new atoum\asserter\generator()), $otherReason = uniqid()))->isGreaterThan(0)
  117. ->array($score->getFailAssertions())->isEqualTo(array(
  118. array(
  119. 'case' => null,
  120. 'dataSetKey' => null,
  121. 'dataSetProvider' => null,
  122. 'class' => $class,
  123. 'method' => $method,
  124. 'file' => $file,
  125. 'line' => $line,
  126. 'asserter' => $asserter,
  127. 'fail' => $reason
  128. ),
  129. array(
  130. 'case' => null,
  131. 'dataSetKey' => null,
  132. 'dataSetProvider' => null,
  133. 'class' => $otherClass,
  134. 'method' => $otherMethod,
  135. 'file' => $otherFile,
  136. 'line' => $otherLine,
  137. 'asserter' => $otherAsserter,
  138. 'fail' => $otherReason
  139. )
  140. )
  141. )
  142. ;
  143. }
  144. public function testAddError()
  145. {
  146. $this
  147. ->if($score = new atoum\score())
  148. ->then
  149. ->array($score->getErrors())->isEmpty()
  150. ->integer($score->getErrorNumber())->isZero()
  151. ->object($score->addError($file = 'file1', $class = 'class1', $method = 'method1', $line = 1, $type = 5, $message = 'message1', $errorFile = 'errorFile1', $errorLine = 2))->isIdenticalTo($score)
  152. ->array($score->getErrors())->isEqualTo(array(
  153. array(
  154. 'case' => null,
  155. 'dataSetKey' => null,
  156. 'dataSetProvider' => null,
  157. 'class' => $class,
  158. 'method' => $method,
  159. 'file' => $file,
  160. 'line' => $line,
  161. 'type' => $type,
  162. 'message' => $message,
  163. 'errorFile' => $errorFile,
  164. 'errorLine' => $errorLine
  165. )
  166. )
  167. )
  168. ->integer($score->getErrorNumber())->isEqualTo(1)
  169. ->object($score->addError($otherFile = 'file2', $otherClass = 'class2', $otherMethod = 'method2', $otherLine = 10, $otherType = 15, $otherMessage = 'message2', $otherErrorFile = 'errorFile2', $otherErrorLine = 20))->isIdenticalTo($score)
  170. ->array($score->getErrors())->isEqualTo(array(
  171. array(
  172. 'case' => null,
  173. 'dataSetKey' => null,
  174. 'dataSetProvider' => null,
  175. 'class' => $class,
  176. 'method' => $method,
  177. 'file' => $file,
  178. 'line' => $line,
  179. 'type' => $type,
  180. 'message' => $message,
  181. 'errorFile' => $errorFile,
  182. 'errorLine' => $errorLine
  183. ),
  184. array(
  185. 'case' => null,
  186. 'dataSetKey' => null,
  187. 'dataSetProvider' => null,
  188. 'class' => $otherClass,
  189. 'method' => $otherMethod,
  190. 'file' => $otherFile,
  191. 'line' => $otherLine,
  192. 'type' => $otherType,
  193. 'message' => $otherMessage,
  194. 'errorFile' => $otherErrorFile,
  195. 'errorLine' => $otherErrorLine
  196. )
  197. )
  198. )
  199. ->integer($score->getErrorNumber())->isEqualTo(2)
  200. ->object($score->addError($file, $class, $method, $line, $type, $anAnotherMessage = 'message1.1', $errorFile, $errorLine))->isIdenticalTo($score)
  201. ->array($score->getErrors())->isEqualTo(array(
  202. array(
  203. 'case' => null,
  204. 'dataSetKey' => null,
  205. 'dataSetProvider' => null,
  206. 'class' => $class,
  207. 'method' => $method,
  208. 'file' => $file,
  209. 'line' => $line,
  210. 'type' => $type,
  211. 'message' => $message,
  212. 'errorFile' => $errorFile,
  213. 'errorLine' => $errorLine
  214. ),
  215. array(
  216. 'case' => null,
  217. 'dataSetKey' => null,
  218. 'dataSetProvider' => null,
  219. 'class' => $class,
  220. 'method' => $method,
  221. 'file' => $file,
  222. 'line' => $line,
  223. 'type' => $type,
  224. 'message' => $anAnotherMessage,
  225. 'errorFile' => $errorFile,
  226. 'errorLine' => $errorLine
  227. ),
  228. array(
  229. 'case' => null,
  230. 'dataSetKey' => null,
  231. 'dataSetProvider' => null,
  232. 'class' => $otherClass,
  233. 'method' => $otherMethod,
  234. 'file' => $otherFile,
  235. 'line' => $otherLine,
  236. 'type' => $otherType,
  237. 'message' => $otherMessage,
  238. 'errorFile' => $otherErrorFile,
  239. 'errorLine' => $otherErrorLine
  240. )
  241. )
  242. )
  243. ->integer($score->getErrorNumber())->isEqualTo(3)
  244. ->object($score->addError($file, $class, $method, $line + 1, $type, (" \t \t" . $messageWithWhitespace = 'message with withespace' . " \t " . PHP_EOL), $errorFile, $errorLine))->isIdenticalTo($score)
  245. ->array($score->getErrors())->isEqualTo(array(
  246. array(
  247. 'case' => null,
  248. 'dataSetKey' => null,
  249. 'dataSetProvider' => null,
  250. 'class' => $class,
  251. 'method' => $method,
  252. 'file' => $file,
  253. 'line' => $line,
  254. 'type' => $type,
  255. 'message' => $anAnotherMessage,
  256. 'errorFile' => $errorFile,
  257. 'errorLine' => $errorLine
  258. ),
  259. array(
  260. 'case' => null,
  261. 'dataSetKey' => null,
  262. 'dataSetProvider' => null,
  263. 'class' => $class,
  264. 'method' => $method,
  265. 'file' => $file,
  266. 'line' => $line,
  267. 'type' => $type,
  268. 'message' => $message,
  269. 'errorFile' => $errorFile,
  270. 'errorLine' => $errorLine
  271. ),
  272. array(
  273. 'case' => null,
  274. 'dataSetKey' => null,
  275. 'dataSetProvider' => null,
  276. 'class' => $class,
  277. 'method' => $method,
  278. 'file' => $file,
  279. 'line' => $line + 1,
  280. 'type' => $type,
  281. 'message' => trim($messageWithWhitespace),
  282. 'errorFile' => $errorFile,
  283. 'errorLine' => $errorLine
  284. ),
  285. array(
  286. 'case' => null,
  287. 'dataSetKey' => null,
  288. 'dataSetProvider' => null,
  289. 'class' => $otherClass,
  290. 'method' => $otherMethod,
  291. 'file' => $otherFile,
  292. 'line' => $otherLine,
  293. 'type' => $otherType,
  294. 'message' => $otherMessage,
  295. 'errorFile' => $otherErrorFile,
  296. 'errorLine' => $otherErrorLine
  297. ),
  298. )
  299. )
  300. ->integer($score->getErrorNumber())->isEqualTo(4)
  301. ;
  302. }
  303. public function testAddOutput()
  304. {
  305. $this
  306. ->if($score = new atoum\score())
  307. ->then
  308. ->array($score->getOutputs())->isEmpty()
  309. ->integer($score->getOutputNumber())->isZero()
  310. ->object($score->addOutput($file = uniqid(), $class = uniqid(), $method = uniqid(), $output = uniqid()))->isIdenticalTo($score)
  311. ->array($score->getOutputs())->isEqualTo(array(
  312. array(
  313. 'class' => $class,
  314. 'method' => $method,
  315. 'value' => $output
  316. )
  317. )
  318. )
  319. ->integer($score->getOutputNumber())->isEqualTo(1)
  320. ->object($score->addOutput($file = uniqid(), $otherClass = uniqid(), $otherMethod = uniqid(), $otherOutput = uniqid()))->isIdenticalTo($score)
  321. ->array($score->getOutputs())->isEqualTo(array(
  322. array(
  323. 'class' => $class,
  324. 'method' => $method,
  325. 'value' => $output
  326. ),
  327. array(
  328. 'class' => $otherClass,
  329. 'method' => $otherMethod,
  330. 'value' => $otherOutput
  331. )
  332. )
  333. )
  334. ->integer($score->getOutputNumber())->isEqualTo(2)
  335. ->object($score->addOutput($file = uniqid(), $class, $method, $moreOutput = uniqid()))->isIdenticalTo($score)
  336. ->array($score->getOutputs())->isEqualTo(array(
  337. array(
  338. 'class' => $class,
  339. 'method' => $method,
  340. 'value' => $output
  341. ),
  342. array(
  343. 'class' => $otherClass,
  344. 'method' => $otherMethod,
  345. 'value' => $otherOutput
  346. ),
  347. array(
  348. 'class' => $class,
  349. 'method' => $method,
  350. 'value' => $moreOutput
  351. )
  352. )
  353. )
  354. ->integer($score->getOutputNumber())->isEqualTo(3)
  355. ;
  356. }
  357. public function testAddDuration()
  358. {
  359. $this
  360. ->if($score = new atoum\score())
  361. ->then
  362. ->array($score->getDurations())->isEmpty()
  363. ->integer($score->getDurationNumber())->isZero()
  364. ->object($score->addDuration($path = uniqid(), $class = uniqid(), $method = uniqid(), $duration = rand(1, PHP_INT_MAX)))->isIdenticalTo($score)
  365. ->array($score->getDurations())->isEqualTo(array(
  366. array(
  367. 'class' => $class,
  368. 'method' => $method,
  369. 'value' => $duration,
  370. 'path' => $path
  371. )
  372. )
  373. )
  374. ->integer($score->getDurationNumber())->isEqualTo(1)
  375. ->object($score->addDuration($otherPath = uniqid(), $otherClass = uniqid(), $otherMethod = uniqid(), $otherDuration = rand(1, PHP_INT_MAX)))->isIdenticalTo($score)
  376. ->array($score->getDurations())->isEqualTo(array(
  377. array(
  378. 'class' => $class,
  379. 'method' => $method,
  380. 'value' => $duration,
  381. 'path' => $path
  382. ),
  383. array(
  384. 'class' => $otherClass,
  385. 'method' => $otherMethod,
  386. 'value' => $otherDuration,
  387. 'path' => $otherPath
  388. )
  389. )
  390. )
  391. ->integer($score->getDurationNumber())->isEqualTo(2)
  392. ->object($score->addDuration(uniqid(), uniqid(), uniqid(), 0))->isIdenticalTo($score)
  393. ->array($score->getDurations())->isEqualTo(array(
  394. array(
  395. 'class' => $class,
  396. 'method' => $method,
  397. 'value' => $duration,
  398. 'path' => $path
  399. ),
  400. array(
  401. 'class' => $otherClass,
  402. 'method' => $otherMethod,
  403. 'value' => $otherDuration,
  404. 'path' => $otherPath
  405. )
  406. )
  407. )
  408. ->integer($score->getDurationNumber())->isEqualTo(2)
  409. ->object($score->addDuration(uniqid(), uniqid(), uniqid(), - rand(1, PHP_INT_MAX)))->isIdenticalTo($score)
  410. ->array($score->getDurations())->isEqualTo(array(
  411. array(
  412. 'class' => $class,
  413. 'method' => $method,
  414. 'value' => $duration,
  415. 'path' => $path
  416. ),
  417. array(
  418. 'class' => $otherClass,
  419. 'method' => $otherMethod,
  420. 'value' => $otherDuration,
  421. 'path' => $otherPath
  422. )
  423. )
  424. )
  425. ->integer($score->getDurationNumber())->isEqualTo(2)
  426. ->object($score->addDuration($path, $class, $method, $moreDuration = rand(1, PHP_INT_MAX)))->isIdenticalTo($score)
  427. ->array($score->getDurations())->isEqualTo(array(
  428. array(
  429. 'class' => $class,
  430. 'method' => $method,
  431. 'value' => $duration,
  432. 'path' => $path
  433. ),
  434. array(
  435. 'class' => $otherClass,
  436. 'method' => $otherMethod,
  437. 'value' => $otherDuration,
  438. 'path' => $otherPath
  439. ),
  440. array(
  441. 'class' => $class,
  442. 'method' => $method,
  443. 'value' => $moreDuration,
  444. 'path' => $path
  445. )
  446. )
  447. )
  448. ->integer($score->getDurationNumber())->isEqualTo(3)
  449. ;
  450. }
  451. public function testAddMemoryUsage()
  452. {
  453. $this
  454. ->if($score = new atoum\score())
  455. ->then
  456. ->array($score->getMemoryUsages())->isEmpty()
  457. ->object($score->addMemoryUsage($file = uniqid(), $class = uniqid(), $method = uniqid(), $memoryUsage = rand(1, PHP_INT_MAX)))->isIdenticalTo($score)
  458. ->array($score->getMemoryUsages())->isEqualTo(array(
  459. array(
  460. 'class' => $class,
  461. 'method' => $method,
  462. 'value' => $memoryUsage
  463. )
  464. )
  465. )
  466. ->object($score->addMemoryUsage($otherFile = uniqid(), $otherClass = uniqid(), $otherMethod = uniqid(), $otherMemoryUsage = rand(1, PHP_INT_MAX)))->isIdenticalTo($score)
  467. ->array($score->getMemoryUsages())->isEqualTo(array(
  468. array(
  469. 'class' => $class,
  470. 'method' => $method,
  471. 'value' => $memoryUsage
  472. ),
  473. array(
  474. 'class' => $otherClass,
  475. 'method' => $otherMethod,
  476. 'value' => $otherMemoryUsage
  477. )
  478. )
  479. )
  480. ->object($score->addMemoryUsage(uniqid(), uniqid(), uniqid(), 0))->isIdenticalTo($score)
  481. ->array($score->getMemoryUsages())->isEqualTo(array(
  482. array(
  483. 'class' => $class,
  484. 'method' => $method,
  485. 'value' => $memoryUsage
  486. ),
  487. array(
  488. 'class' => $otherClass,
  489. 'method' => $otherMethod,
  490. 'value' => $otherMemoryUsage
  491. )
  492. )
  493. )
  494. ->object($score->addMemoryUsage(uniqid(), uniqid(), uniqid(), - rand(1, PHP_INT_MAX)))->isIdenticalTo($score)
  495. ->array($score->getMemoryUsages())->isEqualTo(array(
  496. array(
  497. 'class' => $class,
  498. 'method' => $method,
  499. 'value' => $memoryUsage
  500. ),
  501. array(
  502. 'class' => $otherClass,
  503. 'method' => $otherMethod,
  504. 'value' => $otherMemoryUsage
  505. )
  506. )
  507. )
  508. ->object($score->addMemoryUsage($file, $class, $method, $moreMemoryUsage = rand(1, PHP_INT_MAX)))->isIdenticalTo($score)
  509. ->array($score->getMemoryUsages())->isEqualTo(array(
  510. array(
  511. 'class' => $class,
  512. 'method' => $method,
  513. 'value' => $memoryUsage
  514. ),
  515. array(
  516. 'class' => $otherClass,
  517. 'method' => $otherMethod,
  518. 'value' => $otherMemoryUsage
  519. ),
  520. array(
  521. 'class' => $class,
  522. 'method' => $method,
  523. 'value' => $moreMemoryUsage
  524. )
  525. )
  526. )
  527. ;
  528. }
  529. public function testAddUncompletedMethod()
  530. {
  531. $this
  532. ->if($score = new atoum\score())
  533. ->then
  534. ->array($score->getUncompletedMethods())->isEmpty()
  535. ->object($score->addUncompletedMethod($file = uniqid(), $class = uniqid(), $method = uniqid(), $exitCode = rand(1, PHP_INT_MAX), $output = uniqid()))->isIdenticalTo($score)
  536. ->array($score->getUncompletedMethods())->isEqualTo(array(
  537. array(
  538. 'file' => $file,
  539. 'class' => $class,
  540. 'method' => $method,
  541. 'exitCode' => $exitCode,
  542. 'output' => $output,
  543. )
  544. )
  545. )
  546. ->object($score->addUncompletedMethod($otherFile = uniqid(), $otherClass = uniqid(), $otherMethod = uniqid(), $otherExitCode = rand(1, PHP_INT_MAX), $otherOutput = uniqid()))->isIdenticalTo($score)
  547. ->array($score->getUncompletedMethods())->isEqualTo(array(
  548. array(
  549. 'file' => $file,
  550. 'class' => $class,
  551. 'method' => $method,
  552. 'exitCode' => $exitCode,
  553. 'output' => $output,
  554. ),
  555. array(
  556. 'file' => $otherFile,
  557. 'class' => $otherClass,
  558. 'method' => $otherMethod,
  559. 'exitCode' => $otherExitCode,
  560. 'output' => $otherOutput,
  561. )
  562. )
  563. )
  564. ;
  565. }
  566. public function testAddSkippedMethod()
  567. {
  568. $this
  569. ->if($score = new atoum\score())
  570. ->then
  571. ->array($score->getSkippedMethods())->isEmpty()
  572. ->object($score->addSkippedMethod($file = uniqid(), $class = uniqid(), $method = uniqid(), $line = rand(1, PHP_INT_MAX), $message = uniqid()))->isIdenticalTo($score)
  573. ->array($score->getSkippedMethods())->isEqualTo(array(
  574. array(
  575. 'file' => $file,
  576. 'class' => $class,
  577. 'method' => $method,
  578. 'line' => $line,
  579. 'message' => $message
  580. )
  581. )
  582. )
  583. ;
  584. }
  585. public function testAddRuntimeException()
  586. {
  587. $this
  588. ->if($score = new atoum\score())
  589. ->then
  590. ->array($score->getRuntimeExceptions())->isEmpty()
  591. ->integer($score->getRuntimeExceptionNumber())->isZero()
  592. ->object($score->addRuntimeException(uniqid(), uniqid(), uniqid(), $exception = new atoum\test\exceptions\runtime()))->isIdenticalTo($score)
  593. ->array($score->getRuntimeExceptions())->isEqualTo(array(
  594. $exception
  595. )
  596. )
  597. ->integer($score->getRuntimeExceptionNumber())->isEqualTo(1)
  598. ->object($score->addRuntimeException(uniqid(), uniqid(), uniqid(), $otherException = new atoum\test\exceptions\runtime()))->isIdenticalTo($score)
  599. ->array($score->getRuntimeExceptions())->isEqualTo(array(
  600. $exception,
  601. $otherException
  602. )
  603. )
  604. ->integer($score->getRuntimeExceptionNumber())->isEqualTo(2)
  605. ;
  606. }
  607. public function testSetCoverage()
  608. {
  609. $this
  610. ->if($score = new atoum\score())
  611. ->then
  612. ->object($score->setCoverage($coverage = new atoum\score\coverage()))->isIdenticalTo($score)
  613. ->object($score->getCoverage())->isIdenticalTo($coverage)
  614. ;
  615. }
  616. public function testGetExceptionNumber()
  617. {
  618. $this
  619. ->if($score = new atoum\score())
  620. ->then
  621. ->integer($score->getExceptionNumber())->isZero()
  622. ->if($score->addException(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), new \exception()))
  623. ->then
  624. ->integer($score->getExceptionNumber())->isEqualTo(1)
  625. ->if($score->addException(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), new \exception()))
  626. ->then
  627. ->integer($score->getExceptionNumber())->isEqualTo(2)
  628. ;
  629. }
  630. public function testGetFailNumber()
  631. {
  632. $this
  633. ->if($score = new atoum\score())
  634. ->then
  635. ->integer($score->getFailNumber())->isZero()
  636. ->if($score->addFail(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), new atoum\asserters\integer(new atoum\asserter\generator()), uniqid()))
  637. ->then
  638. ->integer($score->getFailNumber())->isEqualTo(1)
  639. ->if($score->addFail(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), new atoum\asserters\integer(new atoum\asserter\generator()), uniqid()))
  640. ->then
  641. ->integer($score->getFailNumber())->isEqualTo(2)
  642. ;
  643. }
  644. public function testGetFailAssertions()
  645. {
  646. $this
  647. ->if($score = new atoum\score())
  648. ->then
  649. ->array($score->getFailAssertions())->isEmpty()
  650. ->if($score->addPass())
  651. ->then
  652. ->array($score->getFailAssertions())->isEmpty()
  653. ->if($score->addFail($file = uniqid(), $class = uniqid(), $method = uniqid(), $line = rand(1, PHP_INT_MAX), $asserter = new atoum\asserters\integer(new atoum\asserter\generator()), $reason = uniqid()))
  654. ->then
  655. ->array($score->getFailAssertions())->isEqualTo(array(
  656. array(
  657. 'case' => null,
  658. 'dataSetKey' => null,
  659. 'dataSetProvider' => null,
  660. 'class' => $class,
  661. 'method' => $method,
  662. 'file' => $file,
  663. 'line' => $line,
  664. 'asserter' => $asserter,
  665. 'fail' => $reason
  666. )
  667. )
  668. )
  669. ;
  670. }
  671. public function testGetLastFailAssertion()
  672. {
  673. $this
  674. ->if($score = new atoum\score())
  675. ->then
  676. ->variable($score->getLastFailAssertion())->isNull()
  677. ->if($score->addPass())
  678. ->then
  679. ->variable($score->getLastFailAssertion())->isNull()
  680. ->if($score->addFail($file = uniqid(), $class = uniqid(), $method = uniqid(), $line = rand(1, PHP_INT_MAX), $asserter = new atoum\asserters\integer(new atoum\asserter\generator()), $reason = uniqid()))
  681. ->then
  682. ->array($score->getLastFailAssertion())->isEqualTo(array(
  683. 'case' => null,
  684. 'dataSetKey' => null,
  685. 'dataSetProvider' => null,
  686. 'class' => $class,
  687. 'method' => $method,
  688. 'file' => $file,
  689. 'line' => $line,
  690. 'asserter' => $asserter,
  691. 'fail' => $reason
  692. )
  693. )
  694. ;
  695. }
  696. public function testGetLastVoidMethod()
  697. {
  698. $this
  699. ->if($score = new atoum\score())
  700. ->then
  701. ->variable($score->getLastVoidMethod())->isNull()
  702. ->if($score->addPass())
  703. ->then
  704. ->variable($score->getLastVoidMethod())->isNull()
  705. ->if($score->addVoidMethod($file = uniqid(), $class = uniqid(), $method = uniqid()))
  706. ->then
  707. ->array($score->getLastVoidMethod())->isEqualTo(array(
  708. 'file' => $file,
  709. 'class' => $class,
  710. 'method' => $method
  711. )
  712. )
  713. ;
  714. }
  715. public function testGetLastSkippedMethod()
  716. {
  717. $this
  718. ->if($score = new atoum\score())
  719. ->then
  720. ->variable($score->getLastSkippedMethod())->isNull()
  721. ->if($score->addPass())
  722. ->then
  723. ->variable($score->getLastSkippedMethod())->isNull()
  724. ->if($score->addSkippedMethod($file = uniqid(), $class = uniqid(), $method = uniqid(), $line = rand(1, PHP_INT_MAX), $message = uniqid()))
  725. ->then
  726. ->array($score->getLastSkippedMethod())->isEqualTo(array(
  727. 'file' => $file,
  728. 'class' => $class,
  729. 'method' => $method,
  730. 'line' => $line,
  731. 'message' => $message
  732. )
  733. )
  734. ;
  735. }
  736. public function testGetLastErroredMethod()
  737. {
  738. $this
  739. ->if($score = new atoum\score())
  740. ->then
  741. ->variable($score->getLastErroredMethod())->isNull()
  742. ->if($score->addPass())
  743. ->then
  744. ->variable($score->getLastErroredMethod())->isNull()
  745. ->if($score->addError($file = uniqid(), $class = uniqid(), $method = uniqid(), $line = rand(1, PHP_INT_MAX), $type = rand(E_ERROR, E_USER_DEPRECATED), $message = uniqid()))
  746. ->then
  747. ->array($score->getLastErroredMethod())->isEqualTo(array(
  748. 'case' => null,
  749. 'dataSetKey' => null,
  750. 'dataSetProvider' => null,
  751. 'class' => $class,
  752. 'method' => $method,
  753. 'file' => $file,
  754. 'line' => $line,
  755. 'type' => $type,
  756. 'message' => trim($message),
  757. 'errorFile' => null,
  758. 'errorLine' => null
  759. )
  760. )
  761. ->if($score->addError($file = uniqid(), $class = uniqid(), $method = uniqid(), $line = rand(1, PHP_INT_MAX), $type = rand(E_ERROR, E_USER_DEPRECATED), $message = uniqid(), $errorFile = uniqid(), $errorLine = rand(1, PHP_INT_MAX), $case = uniqid(), $dataSetKey = uniqid(), $dataSetProvider = uniqid()))
  762. ->then
  763. ->array($score->getLastErroredMethod())->isEqualTo(array(
  764. 'case' => $case,
  765. 'dataSetKey' => $dataSetKey,
  766. 'dataSetProvider' => $dataSetProvider,
  767. 'class' => $class,
  768. 'method' => $method,
  769. 'file' => $file,
  770. 'line' => $line,
  771. 'type' => $type,
  772. 'message' => trim($message),
  773. 'errorFile' => $errorFile,
  774. 'errorLine' => $errorLine
  775. )
  776. )
  777. ;
  778. }
  779. public function testGetLastException()
  780. {
  781. $this
  782. ->if($score = new atoum\score())
  783. ->then
  784. ->variable($score->getLastException())->isNull()
  785. ->if($score->addPass())
  786. ->then
  787. ->variable($score->getLastException())->isNull()
  788. ->if($score->addException($file = uniqid(), $class = uniqid(), $method = uniqid(), $line = rand(1, PHP_INT_MAX), $exception = new \exception()))
  789. ->then
  790. ->array($score->getLastException())->isEqualTo(array(
  791. 'case' => null,
  792. 'dataSetKey' => null,
  793. 'dataSetProvider' => null,
  794. 'class' => $class,
  795. 'method' => $method,
  796. 'file' => $file,
  797. 'line' => $line,
  798. 'value' => (string) $exception
  799. )
  800. )
  801. ->if($score->addException($otherFile = uniqid(), $otherClass = uniqid(), $otherMethod = uniqid(), $otherLine = rand(1, PHP_INT_MAX), $otherException = new \exception(), $case = uniqid(), $dataSetKey = uniqid(), $dataSetProvider = uniqid()))
  802. ->then
  803. ->array($score->getLastException())->isEqualTo(array(
  804. 'case' => $case,
  805. 'dataSetKey' => $dataSetKey,
  806. 'dataSetProvider' => $dataSetProvider,
  807. 'class' => $otherClass,
  808. 'method' => $otherMethod,
  809. 'file' => $otherFile,
  810. 'line' => $otherLine,
  811. 'value' => (string) $otherException
  812. )
  813. )
  814. ;
  815. }
  816. public function testGetLastUncompleteMethod()
  817. {
  818. $this
  819. ->if($score = new atoum\score())
  820. ->then
  821. ->variable($score->getLastUncompleteMethod())->isNull()
  822. ->if($score->addPass())
  823. ->then
  824. ->variable($score->getLastUncompleteMethod())->isNull()
  825. ->if($score->addUncompletedMethod($file = uniqid(), $class = uniqid(), $method = uniqid(), $exitCode = rand(1, PHP_INT_MAX), $output = uniqid()))
  826. ->then
  827. ->array($score->getLastUncompleteMethod())->isEqualTo(array(
  828. 'file' => $file,
  829. 'class' => $class,
  830. 'method' => $method,
  831. 'exitCode' => $exitCode,
  832. 'output' => $output,
  833. )
  834. )
  835. ->if($score->addUncompletedMethod($otherFile = uniqid(), $otherClass = uniqid(), $otherMethod = uniqid(), $otherExitCode = rand(1, PHP_INT_MAX), $otherOutput = uniqid()))
  836. ->then
  837. ->array($score->getLastUncompleteMethod())->isEqualTo(array(
  838. 'file' => $otherFile,
  839. 'class' => $otherClass,
  840. 'method' => $otherMethod,
  841. 'exitCode' => $otherExitCode,
  842. 'output' => $otherOutput,
  843. )
  844. )
  845. ;
  846. }
  847. public function testGetLastRuntimeException()
  848. {
  849. $this
  850. ->if($score = new atoum\score())
  851. ->then
  852. ->variable($score->getLastRuntimeException())->isNull()
  853. ->if($score->addPass())
  854. ->then
  855. ->variable($score->getLastRuntimeException())->isNull()
  856. ->if($score->addRuntimeException($file = uniqid(), $class = uniqid(), $method = uniqid(), $exception = new exceptions\runtime()))
  857. ->then
  858. ->object($score->getLastRuntimeException())->isIdenticalTo($exception)
  859. ->if($score->addRuntimeException($otherFile = uniqid(), $otherClass = uniqid(), $otherMethod = uniqid(), $otherException = new exceptions\runtime()))
  860. ->then
  861. ->object($score->getLastRuntimeException())->isIdenticalTo($otherException)
  862. ;
  863. }
  864. public function testGetPassAssertions()
  865. {
  866. $this
  867. ->if($score = new atoum\score())
  868. ->then
  869. ->integer($score->getPassNumber())->isZero()
  870. ->if($score->addFail(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), new atoum\asserters\integer(new atoum\asserter\generator()), uniqid()))
  871. ->then
  872. ->integer($score->getPassNumber())->isZero()
  873. ->if($score->addPass())
  874. ->then
  875. ->integer($score->getPassNumber())->isEqualTo(1)
  876. ;
  877. }
  878. public function testGetCoverage()
  879. {
  880. $this
  881. ->if($score = new atoum\score())
  882. ->then
  883. ->object($coverage = $score->getCoverage())->isInstanceOf('mageekguy\atoum\score\coverage')
  884. ;
  885. }
  886. public function testGetMethodsWithFail()
  887. {
  888. $this
  889. ->if($score = new atoum\score())
  890. ->then
  891. ->array($score->getMethodsWithFail())->isEmpty()
  892. ->if($asserter = new atoum\asserters\integer(new atoum\asserter\generator()))
  893. ->and($score->addFail(uniqid(), $class = uniqid(), $classMethod = uniqid(), rand(1, PHP_INT_MAX), $asserter, uniqid()))
  894. ->then
  895. ->array($score->getMethodsWithFail())->isEqualTo(array($class => array($classMethod)))
  896. ->if($score->addFail(uniqid(), $class, $classOtherMethod = uniqid(), rand(1, PHP_INT_MAX), $asserter, uniqid()))
  897. ->then
  898. ->array($score->getMethodsWithFail())->isEqualTo(array($class => array($classMethod, $classOtherMethod)))
  899. ->if($score->addFail(uniqid(), $otherClass = uniqid(), $otherClassMethod = uniqid(), rand(1, PHP_INT_MAX), $asserter, uniqid()))
  900. ->then
  901. ->array($score->getMethodsWithFail())->isEqualTo(array(
  902. $class => array($classMethod, $classOtherMethod),
  903. $otherClass => array($otherClassMethod)
  904. )
  905. )
  906. ;
  907. }
  908. public function testGetMethodsWithError()
  909. {
  910. $this
  911. ->if($score = new atoum\score())
  912. ->then
  913. ->array($score->getMethodsWithError())->isEmpty()
  914. ->if($score->addError(uniqid(), $class = uniqid(), $classMethod = uniqid(), rand(1, PHP_INT_MAX), rand(1, PHP_INT_MAX), uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  915. ->then
  916. ->array($score->getMethodsWithError())->isEqualTo(array($class => array($classMethod)))
  917. ->if($score->addError(uniqid(), $class, $classOtherMethod = uniqid(), rand(1, PHP_INT_MAX), rand(1, PHP_INT_MAX), uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  918. ->then
  919. ->array($score->getMethodsWithError())->isEqualTo(array($class => array($classMethod, $classOtherMethod)))
  920. ->if($score->addError(uniqid(), $otherClass = uniqid(), $otherClassMethod = uniqid(), rand(1, PHP_INT_MAX), rand(1, PHP_INT_MAX), uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  921. ->then
  922. ->array($score->getMethodsWithError())->isEqualTo(array(
  923. $class => array($classMethod, $classOtherMethod),
  924. $otherClass => array($otherClassMethod)
  925. )
  926. )
  927. ;
  928. }
  929. public function testGetMethodsWithException()
  930. {
  931. $this
  932. ->if($score = new atoum\score())
  933. ->then
  934. ->array($score->getMethodsWithError())->isEmpty()
  935. ->if($score->addException(uniqid(), $class = uniqid(), $classMethod = uniqid(), rand(1, PHP_INT_MAX), new \exception()))
  936. ->then
  937. ->array($score->getMethodsWithException())->isEqualTo(array($class => array($classMethod)))
  938. ->if($score->addException(uniqid(), $class, $classOtherMethod = uniqid(), rand(1, PHP_INT_MAX), new \exception()))
  939. ->then
  940. ->array($score->getMethodsWithException())->isEqualTo(array($class => array($classMethod, $classOtherMethod)))
  941. ->if($score->addException(uniqid(), $otherClass = uniqid(), $otherClassMethod = uniqid(), rand(1, PHP_INT_MAX), new \exception()))
  942. ->then
  943. ->array($score->getMethodsWithException())->isEqualTo(array(
  944. $class => array($classMethod, $classOtherMethod),
  945. $otherClass => array($otherClassMethod)
  946. )
  947. )
  948. ;
  949. }
  950. public function testReset()
  951. {
  952. $this
  953. ->if($score = new atoum\score())
  954. ->then
  955. ->integer($score->getPassNumber())->isZero()
  956. ->array($score->getFailAssertions())->isEmpty()
  957. ->array($score->getExceptions())->isEmpty()
  958. ->array($score->getRuntimeExceptions())->isEmpty()
  959. ->array($score->getErrors())->isEmpty()
  960. ->array($score->getOutputs())->isEmpty()
  961. ->array($score->getDurations())->isEmpty()
  962. ->array($score->getMemoryUsages())->isEmpty()
  963. ->array($score->getUncompletedMethods())->isEmpty()
  964. ->object($score->reset())->isIdenticalTo($score)
  965. ->integer($score->getPassNumber())->isZero()
  966. ->array($score->getFailAssertions())->isEmpty()
  967. ->array($score->getExceptions())->isEmpty()
  968. ->array($score->getRuntimeExceptions())->isEmpty()
  969. ->array($score->getErrors())->isEmpty()
  970. ->array($score->getOutputs())->isEmpty()
  971. ->array($score->getDurations())->isEmpty()
  972. ->array($score->getMemoryUsages())->isEmpty()
  973. ->array($score->getUncompletedMethods())->isEmpty()
  974. ->if($score
  975. ->addPass()
  976. ->addException(uniqid(), rand(1, PHP_INT_MAX), uniqid(), uniqid(), new \exception())
  977. ->addRuntimeException(uniqid(), uniqid(), uniqid(), new atoum\exceptions\runtime())
  978. ->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), E_ERROR, uniqid(), uniqid(), rand(1, PHP_INT_MAX))
  979. ->addOutput(uniqid(), uniqid(), uniqid(), uniqid())
  980. ->addDuration(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX))
  981. ->addMemoryUsage(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX))
  982. ->addUncompletedMethod(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid())
  983. )
  984. ->and($score->addFail(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), new atoum\asserters\integer(new atoum\asserter\generator()), uniqid()))
  985. ->then
  986. ->integer($score->getPassNumber())->isGreaterThan(0)
  987. ->array($score->getFailAssertions())->isNotEmpty()
  988. ->array($score->getExceptions())->isNotEmpty()
  989. ->array($score->getRuntimeExceptions())->isNotEmpty()
  990. ->array($score->getErrors())->isNotEmpty()
  991. ->array($score->getOutputs())->isNotEmpty()
  992. ->array($score->getDurations())->isNotEmpty()
  993. ->array($score->getMemoryUsages())->isNotEmpty()
  994. ->array($score->getUncompletedMethods())->isNotEmpty()
  995. ->object($score->reset())->isIdenticalTo($score)
  996. ->integer($score->getPassNumber())->isZero()
  997. ->array($score->getFailAssertions())->isEmpty()
  998. ->array($score->getExceptions())->isEmpty()
  999. ->array($score->getRuntimeExceptions())->isEmpty()
  1000. ->array($score->getErrors())->isEmpty()
  1001. ->array($score->getOutputs())->isEmpty()
  1002. ->array($score->getDurations())->isEmpty()
  1003. ->array($score->getMemoryUsages())->isEmpty()
  1004. ->array($score->getUncompletedMethods())->isEmpty()
  1005. ;
  1006. }
  1007. public function testMerge()
  1008. {
  1009. $this
  1010. ->if($score = new atoum\score())
  1011. ->and($otherScore = new atoum\score())
  1012. ->then
  1013. ->object($score->merge($otherScore))->isIdenticalTo($score)
  1014. ->integer($score->getPassNumber())->isZero()
  1015. ->array($score->getFailAssertions())->isEmpty()
  1016. ->array($score->getExceptions())->isEmpty()
  1017. ->array($score->getRuntimeExceptions())->isEmpty()
  1018. ->array($score->getErrors())->isEmpty()
  1019. ->array($score->getOutputs())->isEmpty()
  1020. ->array($score->getDurations())->isEmpty()
  1021. ->array($score->getMemoryUsages())->isEmpty()
  1022. ->array($score->getUncompletedMethods())->isEmpty()
  1023. ->array($score->getSkippedMethods())->isEmpty()
  1024. ->if($score->addPass())
  1025. ->and($score->addFail(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), new atoum\asserters\integer(new atoum\asserter\generator()), uniqid()))
  1026. ->and($score->addException(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), new \exception()))
  1027. ->and($score->addRuntimeException(uniqid(), uniqid(), uniqid(), new atoum\exceptions\runtime()))
  1028. ->and($score->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), E_ERROR, uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  1029. ->and($score->addOutput(uniqid(), uniqid(), uniqid(), uniqid()))
  1030. ->and($score->addDuration(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  1031. ->and($score->addMemoryUsage(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  1032. ->and($score->addUncompletedMethod(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))
  1033. ->and($score->addSkippedMethod(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))
  1034. ->then
  1035. ->object($score->merge($otherScore))->isIdenticalTo($score)
  1036. ->integer($score->getPassNumber())->isEqualTo(1)
  1037. ->integer($score->getFailNumber())->isEqualTo(1)
  1038. ->integer($score->getExceptionNumber())->isEqualTo(1)
  1039. ->integer($score->getErrorNumber())->isEqualTo(1)
  1040. ->integer($score->getOutputNumber())->isEqualTo(1)
  1041. ->integer($score->getDurationNumber())->isEqualTo(1)
  1042. ->integer($score->getMemoryUsageNumber())->isEqualTo(1)
  1043. ->integer($score->getUncompletedMethodNumber())->isEqualTo(1)
  1044. ->integer($score->getSkippedMethodNumber())->isEqualTo(1)
  1045. ->if($otherScore->addPass())
  1046. ->and($otherScore->addFail(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), new atoum\asserters\integer(new atoum\asserter\generator()), uniqid()))
  1047. ->and($otherScore->addException(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), new \exception()))
  1048. ->and($otherScore->addRuntimeException(uniqid(), uniqid(), uniqid(), new atoum\exceptions\runtime()))
  1049. ->and($otherScore->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), E_ERROR, uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  1050. ->and($otherScore->addOutput(uniqid(), uniqid(), uniqid(), uniqid()))
  1051. ->and($otherScore->addDuration(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  1052. ->and($otherScore->addMemoryUsage(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  1053. ->and($otherScore->addUncompletedMethod(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))
  1054. ->and($otherScore->addSkippedMethod(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))
  1055. ->then
  1056. ->object($score->merge($otherScore))->isIdenticalTo($score)
  1057. ->integer($score->getPassNumber())->isEqualTo(2)
  1058. ->integer($score->getFailNumber())->isEqualTo(2)
  1059. ->integer($score->getExceptionNumber())->isEqualTo(2)
  1060. ->integer($score->getRuntimeExceptionNumber())->isEqualTo(2)
  1061. ->integer($score->getErrorNumber())->isEqualTo(2)
  1062. ->integer($score->getOutputNumber())->isEqualTo(2)
  1063. ->integer($score->getDurationNumber())->isEqualTo(2)
  1064. ->integer($score->getMemoryUsageNumber())->isEqualTo(2)
  1065. ->integer($score->getUncompletedMethodNumber())->isEqualTo(2)
  1066. ->integer($score->getSkippedMethodNumber())->isEqualTo(2)
  1067. ->object($score->merge($otherScore))->isIdenticalTo($score)
  1068. ->integer($score->getPassNumber())->isEqualTo(3)
  1069. ->integer($score->getFailNumber())->isEqualTo(3)
  1070. ->integer($score->getExceptionNumber())->isEqualTo(3)
  1071. ->integer($score->getRuntimeExceptionNumber())->isEqualTo(3)
  1072. ->integer($score->getErrorNumber())->isEqualTo(3)
  1073. ->integer($score->getOutputNumber())->isEqualTo(3)
  1074. ->integer($score->getDurationNumber())->isEqualTo(3)
  1075. ->integer($score->getMemoryUsageNumber())->isEqualTo(3)
  1076. ->integer($score->getUncompletedMethodNumber())->isEqualTo(3)
  1077. ->integer($score->getSkippedMethodNumber())->isEqualTo(3)
  1078. ;
  1079. }
  1080. public function testErrorExists()
  1081. {
  1082. $this
  1083. ->if($score = new atoum\score())
  1084. ->then
  1085. ->variable($score->errorExists(uniqid()))->isNull()
  1086. ->variable($score->errorExists(uniqid(), rand(1, PHP_INT_MAX)))->isNull()
  1087. ->variable($score->errorExists(uniqid(), rand(1, PHP_INT_MAX), rand(1, PHP_INT_MAX)))->isNull()
  1088. ->if($score->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $type = rand(1, PHP_INT_MAX - 1), $message = uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  1089. ->then
  1090. ->variable($score->errorExists(uniqid()))->isNull()
  1091. ->variable($score->errorExists(uniqid(), rand(1, PHP_INT_MAX)))->isNull()
  1092. ->integer($score->errorExists($message))->isEqualTo(0)
  1093. ->integer($score->errorExists(null, $type))->isEqualTo(0)
  1094. ->integer($score->errorExists($message, $type))->isEqualTo(0)
  1095. ->if($score->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $type, $otherMessage = uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  1096. ->then
  1097. ->variable($score->errorExists(uniqid()))->isNull()
  1098. ->variable($score->errorExists(uniqid(), rand(1, PHP_INT_MAX)))->isNull()
  1099. ->integer($score->errorExists($message))->isEqualTo(0)
  1100. ->integer($score->errorExists(null, $type))->isEqualTo(0)
  1101. ->integer($score->errorExists($message, $type))->isEqualTo(0)
  1102. ->integer($score->errorExists($otherMessage, $type))->isEqualTo(1)
  1103. ->if($score->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $otherType = $type + 1, $message, uniqid(), rand(1, PHP_INT_MAX)))
  1104. ->then
  1105. ->variable($score->errorExists(uniqid()))->isNull()
  1106. ->variable($score->errorExists(uniqid(), rand(1, PHP_INT_MAX)))->isNull()
  1107. ->integer($score->errorExists($message))->isEqualTo(0)
  1108. ->integer($score->errorExists(null, $type))->isEqualTo(0)
  1109. ->integer($score->errorExists($message, $type))->isEqualTo(0)
  1110. ->integer($score->errorExists($otherMessage, $type))->isEqualTo(1)
  1111. ->variable($score->errorExists($otherMessage, $otherType))->isNull()
  1112. ->integer($score->errorExists($message, $otherType))->isEqualTo(2)
  1113. ->integer($score->errorExists(null, $otherType))->isEqualTo(2)
  1114. ->if($score->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $otherType, $otherMessage, uniqid(), rand(1, PHP_INT_MAX)))
  1115. ->then
  1116. ->variable($score->errorExists(uniqid()))->isNull()
  1117. ->variable($score->errorExists(uniqid(), rand(1, PHP_INT_MAX)))->isNull()
  1118. ->integer($score->errorExists($message))->isEqualTo(0)
  1119. ->integer($score->errorExists(null, $type))->isEqualTo(0)
  1120. ->integer($score->errorExists($message, $type))->isEqualTo(0)
  1121. ->integer($score->errorExists($otherMessage, $type))->isEqualTo(1)
  1122. ->integer($score->errorExists($otherMessage, $otherType))->isEqualTo(3)
  1123. ->integer($score->errorExists($message, $otherType))->isEqualTo(2)
  1124. ->integer($score->errorExists(null, $otherType))->isEqualTo(2)
  1125. ->if($score->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $otherType, $pattern = uniqid() . 'FOO' . uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  1126. ->then
  1127. ->variable($score->errorExists(uniqid()))->isNull()
  1128. ->variable($score->errorExists(uniqid(), rand(1, PHP_INT_MAX)))->isNull()
  1129. ->integer($score->errorExists($message))->isEqualTo(0)
  1130. ->integer($score->errorExists(null, $type))->isEqualTo(0)
  1131. ->integer($score->errorExists($message, $type))->isEqualTo(0)
  1132. ->integer($score->errorExists($otherMessage, $type))->isEqualTo(1)
  1133. ->integer($score->errorExists($otherMessage, $otherType))->isEqualTo(3)
  1134. ->integer($score->errorExists($message, $otherType))->isEqualTo(2)
  1135. ->integer($score->errorExists(null, $otherType))->isEqualTo(2)
  1136. ->integer($score->errorExists($pattern, $otherType))->isEqualTo(4)
  1137. ->variable($score->errorExists('/FOO/', $otherType))->isNull()
  1138. ->integer($score->errorExists('/FOO/', $otherType, true))->isEqualTo(4)
  1139. ;
  1140. }
  1141. public function testDeleteError()
  1142. {
  1143. $this
  1144. ->if($score = new atoum\score())
  1145. ->exception(function() use ($score, & $key) { $score->deleteError($key = rand(- PHP_INT_MAX, PHP_INT_MAX)); })
  1146. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  1147. ->hasMessage('Error key \'' . $key . '\' does not exist')
  1148. ->if($score->addError(uniqid(), uniqid(), uniqid(), rand(1, PHP_INT_MAX), $type = rand(1, PHP_INT_MAX), $message = uniqid(), uniqid(), rand(1, PHP_INT_MAX)))
  1149. ->then
  1150. ->integer($score->errorExists($message, $type))->isEqualTo(0)
  1151. ->object($score->deleteError(0))->isIdenticalTo($score)
  1152. ->variable($score->errorExists($message, $type))->isNull()
  1153. ;
  1154. }
  1155. }