PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/units/classes/test.php

http://github.com/mageekguy/atoum
PHP | 1098 lines | 1043 code | 39 blank | 16 comment | 2 complexity | f530430e4a7ef73983828acb58fdb655 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum
  3. {
  4. class emptyTest {}
  5. class notEmptyTest {}
  6. }
  7. namespace mageekguy\atoum\mock\mageekguy\atoum
  8. {
  9. class test {}
  10. }
  11. namespace mageekguy\atoum\tests\units
  12. {
  13. use
  14. mageekguy\atoum,
  15. mageekguy\atoum\mock
  16. ;
  17. require_once __DIR__ . '/../runner.php';
  18. /**
  19. @ignore on
  20. @tags empty fake dummy
  21. @maxChildrenNumber 666
  22. */
  23. class emptyTest extends atoum\test {}
  24. /**
  25. @ignore on
  26. */
  27. class notEmptyTest extends atoum\test
  28. {
  29. /**
  30. @tags test method one method
  31. */
  32. public function testMethod1() {}
  33. /**
  34. @extensions mbstring socket
  35. @ignore off
  36. @tags test method two
  37. */
  38. public function testMethod2() {}
  39. public function aDataProvider()
  40. {
  41. }
  42. }
  43. class foo extends atoum\test
  44. {
  45. public function __construct()
  46. {
  47. $this->setTestedClassName('mageekguy\atoum\test');
  48. parent::__construct();
  49. }
  50. }
  51. class test extends atoum\test
  52. {
  53. public function testClassConstants()
  54. {
  55. $this
  56. ->string(atoum\test::testMethodPrefix)->isEqualTo('test')
  57. ->string(atoum\test::runStart)->isEqualTo('testRunStart')
  58. ->string(atoum\test::beforeSetUp)->isEqualTo('beforeTestSetUp')
  59. ->string(atoum\test::afterSetUp)->isEqualTo('afterTestSetUp')
  60. ->string(atoum\test::beforeTestMethod)->isEqualTo('beforeTestMethod')
  61. ->string(atoum\test::fail)->isEqualTo('testAssertionFail')
  62. ->string(atoum\test::error)->isEqualTo('testError')
  63. ->string(atoum\test::uncompleted)->isEqualTo('testUncompleted')
  64. ->string(atoum\test::skipped)->isEqualTo('testSkipped')
  65. ->string(atoum\test::exception)->isEqualTo('testException')
  66. ->string(atoum\test::success)->isEqualTo('testAssertionSuccess')
  67. ->string(atoum\test::afterTestMethod)->isEqualTo('afterTestMethod')
  68. ->string(atoum\test::beforeTearDown)->isEqualTo('beforeTestTearDown')
  69. ->string(atoum\test::afterTearDown)->isEqualTo('afterTestTearDown')
  70. ->string(atoum\test::runStop)->isEqualTo('testRunStop')
  71. ->string(atoum\test::defaultNamespace)->isEqualTo('#(?:^|\\\\)tests?\\\\units?\\\\#i')
  72. ->string(atoum\test::defaultMethodPrefix)->isEqualTo('#^(?:test|_*[^_]+_should_)#i')
  73. ;
  74. }
  75. public function test__construct()
  76. {
  77. $this
  78. ->if($test = new emptyTest())
  79. ->then
  80. ->object($test->getScore())->isInstanceOf('mageekguy\atoum\score')
  81. ->object($test->getLocale())->isEqualTo(new atoum\locale())
  82. ->object($test->getAdapter())->isEqualTo(new atoum\adapter())
  83. ->object($test->getPhpMocker())->isInstanceOf('mageekguy\atoum\php\mocker')
  84. ->object($test->getFactoryBuilder())->isInstanceOf('mageekguy\atoum\factory\builder\closure')
  85. ->boolean($test->isIgnored())->isTrue()
  86. ->boolean($test->debugModeIsEnabled())->isFalse()
  87. ->array($test->getAllTags())->isEqualTo($tags = array('empty', 'fake', 'dummy'))
  88. ->array($test->getTags())->isEqualTo($tags)
  89. ->array($test->getMethodTags())->isEmpty()
  90. ->array($test->getDataProviders())->isEmpty()
  91. ->integer($test->getMaxChildrenNumber())->isEqualTo(666)
  92. ->boolean($test->codeCoverageIsEnabled())->isEqualTo(extension_loaded('xdebug'))
  93. ->string($test->getTestNamespace())->isEqualTo(atoum\test::defaultNamespace)
  94. ->integer($test->getMaxChildrenNumber())->isEqualTo(666)
  95. ->variable($test->getBootstrapFile())->isNull()
  96. ->array($test->getClassPhpVersions())->isEmpty()
  97. ->array($test->getMandatoryClassExtensions())->isEmpty()
  98. ->array($test->getMandatoryMethodExtensions())->isEmpty()
  99. ->variable($test->getXdebugConfig())->isNull()
  100. ;
  101. }
  102. public function test__toString()
  103. {
  104. $this->castToString($this)->isEqualTo(__CLASS__);
  105. }
  106. public function test__get()
  107. {
  108. $this
  109. ->if($test = new emptyTest())
  110. ->then
  111. ->object($test->assert)->isInstanceOf('mageekguy\atoum\test')
  112. ->object($test->define)->isInstanceOf('mageekguy\atoum\test\assertion\aliaser')
  113. ->object($test->mockGenerator)->isInstanceOf('mageekguy\atoum\mock\generator')
  114. ->if($test->setMockGenerator($mockGenerator = new atoum\test\mock\generator($this)))
  115. ->then
  116. ->object($test->mockGenerator)->isIdenticalTo($mockGenerator)
  117. ->if($test->setAsserterGenerator($asserterGenerator = new atoum\test\asserter\generator(new emptyTest())))
  118. ->then
  119. ->object($test->assert)->isIdenticalTo($test)
  120. ->variable($test->exception)->isNull()
  121. ->exception(function() use ($test, & $property) { $test->{$property = uniqid()}; })
  122. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  123. ->hasMessage('Asserter \'' . $property . '\' does not exist')
  124. ->exception($test->exception)
  125. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  126. ->hasMessage('Asserter \'' . $property . '\' does not exist')
  127. ;
  128. }
  129. public function test__set()
  130. {
  131. $this
  132. ->given(
  133. $test = new emptyTest(),
  134. $test->setAssertionManager($assertionManager = new \mock\mageekguy\atoum\test\assertion\manager())
  135. )
  136. ->if($test->{$event = uniqid()} = $handler = function() {})
  137. ->then
  138. ->mock($assertionManager)->call('setHandler')->withArguments($event, $handler)->once()
  139. ;
  140. }
  141. public function testEnableDebugMode()
  142. {
  143. $this
  144. ->if($test = new emptyTest())
  145. ->then
  146. ->object($test->enableDebugMode())->isIdenticalTo($test)
  147. ->boolean($test->debugModeIsEnabled())->isTrue()
  148. ->object($test->enableDebugMode())->isIdenticalTo($test)
  149. ->boolean($test->debugModeIsEnabled())->isTrue()
  150. ;
  151. }
  152. public function testDisableDebugMode()
  153. {
  154. $this
  155. ->if($test = new emptyTest())
  156. ->then
  157. ->object($test->disableDebugMode())->isIdenticalTo($test)
  158. ->boolean($test->debugModeIsEnabled())->isFalse()
  159. ->object($test->disableDebugMode())->isIdenticalTo($test)
  160. ->boolean($test->debugModeIsEnabled())->isFalse()
  161. ->if($test->enableDebugMode())
  162. ->then
  163. ->object($test->disableDebugMode())->isIdenticalTo($test)
  164. ->boolean($test->debugModeIsEnabled())->isFalse()
  165. ;
  166. }
  167. public function testEnableCodeCoverage()
  168. {
  169. $this
  170. ->assert('Code coverage must be enabled only if xdebug is available')
  171. ->if($adapter = new atoum\test\adapter())
  172. ->and($adapter->extension_loaded = function($extension) { return $extension == 'xdebug'; })
  173. ->and($test = new emptyTest($adapter))
  174. ->then
  175. ->boolean($test->codeCoverageIsEnabled())->isTrue()
  176. ->object($test->enableCodeCoverage())->isIdenticalTo($test)
  177. ->boolean($test->codeCoverageIsEnabled())->isTrue()
  178. ->if($test->disableCodeCoverage())
  179. ->then
  180. ->boolean($test->codeCoverageIsEnabled())->isFalse()
  181. ->object($test->enableCodeCoverage())->isIdenticalTo($test)
  182. ->boolean($test->codeCoverageIsEnabled())->isTrue()
  183. ->assert('Code coverage must not be enabled if xdebug is not available')
  184. ->if($adapter->extension_loaded = function($extension) { return $extension != 'xdebug'; })
  185. ->and($test = new emptyTest($adapter))
  186. ->then
  187. ->boolean($test->codeCoverageIsEnabled())->isFalse()
  188. ->object($test->enableCodeCoverage())->isIdenticalTo($test)
  189. ->boolean($test->codeCoverageIsEnabled())->isFalse()
  190. ;
  191. }
  192. public function testDisableCodeCoverage()
  193. {
  194. $this
  195. ->if($adapter = new atoum\test\adapter())
  196. ->and($adapter->extension_loaded = true)
  197. ->and($test = new emptyTest($adapter))
  198. ->then
  199. ->boolean($test->codeCoverageIsEnabled())->isTrue()
  200. ->object($test->disableCodeCoverage())->isIdenticalTo($test)
  201. ->boolean($test->codeCoverageIsEnabled())->isFalse()
  202. ->if($test->enableCodeCoverage())
  203. ->then
  204. ->boolean($test->codeCoverageIsEnabled())->isTrue()
  205. ->object($test->disableCodeCoverage())->isIdenticalTo($test)
  206. ->boolean($test->codeCoverageIsEnabled())->isFalse()
  207. ;
  208. }
  209. public function testGetMockGenerator()
  210. {
  211. $this
  212. ->if($test = new emptyTest())
  213. ->then
  214. ->object($test->getMockGenerator())->isInstanceOf('mageekguy\atoum\mock\generator')
  215. ->if($test->setMockGenerator($mockGenerator = new atoum\test\mock\generator($this)))
  216. ->then
  217. ->object($test->getMockGenerator())->isIdenticalTo($mockGenerator)
  218. ->object($mockGenerator->getTest())->isIdenticalTo($test)
  219. ;
  220. }
  221. public function testSetMockGenerator()
  222. {
  223. $this
  224. ->if($test = new emptyTest())
  225. ->then
  226. ->object($test->setMockGenerator($mockGenerator = new atoum\test\mock\generator($this)))->isIdenticalTo($test)
  227. ->object($test->getMockGenerator())->isIdenticalTo($mockGenerator)
  228. ->object($mockGenerator->getTest())->isIdenticalTo($test)
  229. ;
  230. }
  231. public function testSetMockAutoloader()
  232. {
  233. $this
  234. ->if($test = new emptyTest())
  235. ->then
  236. ->object($test->setMockAutoloader($mockAutoloader = new atoum\autoloader\mock()))->isIdenticalTo($test)
  237. ->object($test->getMockAutoloader())->isIdenticalTo($mockAutoloader)
  238. ;
  239. }
  240. public function testGetAsserterGenerator()
  241. {
  242. $this
  243. ->if($test = new emptyTest())
  244. ->then
  245. ->object($test->getAsserterGenerator())->isInstanceOf('mageekguy\atoum\test\asserter\generator')
  246. ->if($test->setAsserterGenerator($asserterGenerator = new atoum\test\asserter\generator($this)))
  247. ->then
  248. ->object($test->getAsserterGenerator())->isIdenticalTo($asserterGenerator)
  249. ->object($asserterGenerator->getTest())->isIdenticalTo($test)
  250. ;
  251. }
  252. public function testSetAsserterGenerator()
  253. {
  254. $this
  255. ->if($test = new emptyTest())
  256. ->then
  257. ->object($test->setAsserterGenerator($asserterGenerator = new atoum\test\asserter\generator($test)))->isIdenticalTo($test)
  258. ->object($test->getAsserterGenerator())->isIdenticalTo($asserterGenerator)
  259. ->object($asserterGenerator->getTest())->isIdenticalTo($test)
  260. ->object($asserterGenerator->getLocale())->isIdenticalTo($test->getLocale())
  261. ;
  262. }
  263. public function testGetFactoryBuilder()
  264. {
  265. $this
  266. ->if($test = new emptyTest())
  267. ->then
  268. ->object($test->getFactoryBuilder())->isInstanceOf('mageekguy\atoum\factory\builder\closure')
  269. ->if($test->setFactoryBuilder($factoryBuilder = new \mock\atoum\factory\builder()))
  270. ->then
  271. ->object($test->getFactoryBuilder())->isIdenticalTo($factoryBuilder)
  272. ;
  273. }
  274. public function testSetFactoryBuilder()
  275. {
  276. $this
  277. ->if($test = new emptyTest())
  278. ->then
  279. ->object($test->setFactoryBuilder($factoryBuilder = new \mock\atoum\factory\builder()))->isIdenticalTo($test)
  280. ->object($test->getFactoryBuilder())->isIdenticalTo($factoryBuilder)
  281. ->object($test->setFactoryBuilder())->isIdenticalTo($test)
  282. ->object($test->getFactoryBuilder())
  283. ->isEqualTo(new atoum\Factory\builder\closure())
  284. ->isNotIdenticalTo($factoryBuilder)
  285. ;
  286. }
  287. public function testSetPhpMocker()
  288. {
  289. $this
  290. ->if($test = new emptyTest())
  291. ->then
  292. ->object($test->setPhpMocker($phpMocker = new atoum\php\mocker()))->isIdenticalTo($test)
  293. ->object($test->getPhpMocker())->isIdenticalTo($phpMocker)
  294. ->object($test->setPhpMocker())->isIdenticalTo($test)
  295. ->object($test->getPhpMocker())
  296. ->isNotIdenticalTo($phpMocker)
  297. ->isInstanceOf('mageekguy\atoum\php\mocker')
  298. ;
  299. }
  300. public function testSetTestNamespace()
  301. {
  302. $this
  303. ->if($test = new self())
  304. ->then
  305. ->object($test->setTestNamespace($testNamespace = uniqid()))->isIdenticalTo($test)
  306. ->string($test->getTestNamespace())->isEqualTo($testNamespace)
  307. ->object($test->setTestNamespace('\\' . ($testNamespace = uniqid())))->isIdenticalTo($test)
  308. ->string($test->getTestNamespace())->isEqualTo($testNamespace)
  309. ->object($test->setTestNamespace('\\' . ($testNamespace = uniqid()) . '\\'))->isIdenticalTo($test)
  310. ->string($test->getTestNamespace())->isEqualTo($testNamespace)
  311. ->object($test->setTestNamespace(($testNamespace = uniqid()) . '\\'))->isIdenticalTo($test)
  312. ->string($test->getTestNamespace())->isEqualTo($testNamespace)
  313. ->object($test->setTestNamespace($testNamespace = rand(- PHP_INT_MAX, PHP_INT_MAX)))->isIdenticalTo($test)
  314. ->string($test->getTestNamespace())->isEqualTo((string) $testNamespace)
  315. ->exception(function() use ($test) {
  316. $test->setTestNamespace('');
  317. }
  318. )
  319. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  320. ->hasMessage('Test namespace must not be empty')
  321. ;
  322. }
  323. public function testGetTestNamespace()
  324. {
  325. $this
  326. ->if($test = new self())
  327. ->then
  328. ->string($test->getTestNamespace())->isEqualTo(atoum\test::defaultNamespace)
  329. ->if($test->setTestNamespace($testNamespace = uniqid()))
  330. ->then
  331. ->string($test->getTestNamespace())->isEqualTo($testNamespace)
  332. ;
  333. }
  334. public function testSetTestMethodPrefix()
  335. {
  336. $this
  337. ->if($test = new self())
  338. ->then
  339. ->object($test->setTestMethodPrefix($testMethodPrefix = uniqid()))->isIdenticalTo($test)
  340. ->string($test->getTestMethodPrefix())->isEqualTo($testMethodPrefix)
  341. ->object($test->setTestMethodPrefix($testMethodPrefix = rand(- PHP_INT_MAX, PHP_INT_MAX)))->isIdenticalTo($test)
  342. ->string($test->getTestMethodPrefix())->isEqualTo((string) $testMethodPrefix)
  343. ->exception(function() use ($test) {
  344. $test->setTestMethodPrefix('');
  345. }
  346. )
  347. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  348. ->hasMessage('Test method prefix must not be empty')
  349. ;
  350. }
  351. public function testGetTestMethodPrefix()
  352. {
  353. $this
  354. ->if($test = new self())
  355. ->then
  356. ->string($test->getTestMethodPrefix())->isEqualTo(atoum\test::defaultMethodPrefix)
  357. ->if($test->setTestMethodPrefix($testMethodPrefix = uniqid()))
  358. ->then
  359. ->string($test->getTestMethodPrefix())->isEqualTo($testMethodPrefix)
  360. ;
  361. }
  362. public function testGetTestedClassName()
  363. {
  364. $mockClass = '\mock\\' . __CLASS__;
  365. $this
  366. ->if($test = new $mockClass())
  367. ->and($test->getMockController()->getClass = $testClass = 'foo')
  368. ->then
  369. ->exception(function() use ($test) { $test->getTestedClassName(); })
  370. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  371. ->hasMessage('Test class \'' . $testClass . '\' is not in a namespace which match pattern \'' . $test->getTestNamespace() . '\'')
  372. ->if($test->getMockController()->getClass = 'tests\units\foo')
  373. ->then
  374. ->string($test->getTestedClassName())->isEqualTo('foo')
  375. ;
  376. }
  377. public function testGetTestedClassPath()
  378. {
  379. $this
  380. ->if($testedClass = new \reflectionClass($this->getTestedClassName()))
  381. ->then
  382. ->string($this->getTestedClassPath())->isEqualTo($testedClass->getFilename())
  383. ;
  384. }
  385. public function testGetAdapter()
  386. {
  387. $this
  388. ->if($test = new emptyTest())
  389. ->then
  390. ->object($test->getAdapter())->isInstanceOf('mageekguy\atoum\adapter')
  391. ;
  392. }
  393. public function testSetAdapter()
  394. {
  395. $this
  396. ->if($test = new emptyTest())
  397. ->then
  398. ->object($test->setAdapter($adapter = new atoum\test\adapter()))->isIdenticalTo($test)
  399. ->object($test->getAdapter())->isIdenticalTo($adapter)
  400. ;
  401. }
  402. public function testSetLocale()
  403. {
  404. $this
  405. ->if($test = new emptyTest())
  406. ->then
  407. ->object($test->setLocale($locale = new atoum\locale()))->isIdenticalTo($test)
  408. ->object($test->getLocale())->isIdenticalTo($locale)
  409. ;
  410. }
  411. public function testSetScore()
  412. {
  413. $this
  414. ->if($test = new emptyTest())
  415. ->then
  416. ->object($test->setScore($score = new atoum\test\score()))->isIdenticalTo($test)
  417. ->object($test->getScore())->isIdenticalTo($score)
  418. ;
  419. }
  420. public function testSetBootstrapFile()
  421. {
  422. $this
  423. ->if($test = new emptyTest())
  424. ->then
  425. ->object($test->setBootstrapFile($path = uniqid()))->isIdenticalTo($test)
  426. ->string($test->getBootstrapFile())->isEqualTo($path)
  427. ;
  428. }
  429. public function testSetMaxChildrenNumber()
  430. {
  431. $this
  432. ->if($test = new emptyTest())
  433. ->then
  434. ->exception(function() use ($test) { $test->setMaxChildrenNumber(- rand(1, PHP_INT_MAX)); })
  435. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  436. ->hasMessage('Maximum number of children must be greater or equal to 1')
  437. ->exception(function() use ($test) { $test->setMaxChildrenNumber(0); })
  438. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  439. ->hasMessage('Maximum number of children must be greater or equal to 1')
  440. ->object($test->setMaxChildrenNumber($maxChildrenNumber = rand(1, PHP_INT_MAX)))->isIdenticalTo($test)
  441. ->integer($test->getMaxChildrenNumber())->isEqualTo($maxChildrenNumber)
  442. ->object($test->setMaxChildrenNumber((string) $maxChildrenNumber = rand(1, PHP_INT_MAX)))->isIdenticalTo($test)
  443. ->integer($test->getMaxChildrenNumber())->isEqualTo($maxChildrenNumber)
  444. ;
  445. }
  446. public function testGetClass()
  447. {
  448. $this
  449. ->if($test = new emptyTest())
  450. ->then
  451. ->string($test->getClass())->isEqualTo(__NAMESPACE__ . '\emptyTest')
  452. ;
  453. }
  454. public function testGetPath()
  455. {
  456. $this
  457. ->if($test = new emptyTest())
  458. ->then
  459. ->string($test->getPath())->isEqualTo(__FILE__)
  460. ;
  461. }
  462. public function testGetCoverage()
  463. {
  464. $this
  465. ->if($test = new emptyTest())
  466. ->then
  467. ->object($test->getCoverage())->isIdenticalTo($test->getScore()->getCoverage())
  468. ;
  469. }
  470. public function testIsIgnored()
  471. {
  472. $this
  473. ->if($test = new emptyTest())
  474. ->then
  475. ->boolean($test->isIgnored())->isTrue()
  476. ->object($test->ignore(false))->isIdenticalTo($test)
  477. ->boolean($test->isIgnored())->isTrue()
  478. ->object($test->ignore(true))->isIdenticalTo($test)
  479. ->boolean($test->isIgnored())->isTrue()
  480. ->if($test = new notEmptyTest())
  481. ->then
  482. ->boolean($test->isIgnored())->isTrue()
  483. ->boolean($test->methodIsIgnored('testMethod1'))->isTrue()
  484. ->boolean($test->methodIsIgnored('testMethod2'))->isTrue()
  485. ->object($test->ignore(false))->isIdenticalTo($test)
  486. ->boolean($test->isIgnored())->isFalse()
  487. ->boolean($test->methodIsIgnored('testMethod1'))->isFalse()
  488. ->boolean($test->methodIsIgnored('testMethod2'))->isFalse()
  489. ->object($test->ignore(true))->isIdenticalTo($test)
  490. ->boolean($test->isIgnored())->isTrue()
  491. ->boolean($test->methodIsIgnored('testMethod1'))->istrue()
  492. ->boolean($test->methodIsIgnored('testMethod2'))->isTrue()
  493. ;
  494. }
  495. public function testGetCurrentMethod()
  496. {
  497. $this
  498. ->if($test = new emptyTest())
  499. ->then
  500. ->variable($test->getCurrentMethod())->isNull()
  501. ;
  502. }
  503. public function testCount()
  504. {
  505. $this
  506. ->sizeOf(new emptyTest())->isEqualTo(0)
  507. ->if($test = new notEmptyTest())
  508. ->then
  509. ->sizeOf($test)->isEqualTo(0)
  510. ->if($test->ignore(false))
  511. ->then
  512. ->boolean($test->methodIsIgnored('testMethod1'))->isFalse()
  513. ->boolean($test->methodIsIgnored('testMethod2'))->isFalse()
  514. ->sizeOf($test)->isEqualTo(2)
  515. ->if($test->ignoreMethod('testMethod1', true))
  516. ->boolean($test->methodIsIgnored('testMethod1'))->isTrue()
  517. ->boolean($test->methodIsIgnored('testMethod2'))->isFalse()
  518. ->sizeOf($test)->isEqualTo(1)
  519. ->if($test->ignoreMethod('testMethod2', true))
  520. ->boolean($test->methodIsIgnored('testMethod1'))->isTrue()
  521. ->boolean($test->methodIsIgnored('testMethod2'))->isTrue()
  522. ->sizeOf($test)->isEqualTo(0)
  523. ;
  524. }
  525. public function testGetTestMethods()
  526. {
  527. $this
  528. ->if($test = new emptyTest())
  529. ->then
  530. ->boolean($test->ignore(false)->isIgnored())->isTrue()
  531. ->sizeOf($test)->isZero()
  532. ->array($test->getTestMethods())->isEmpty()
  533. ->if($test = new notEmptyTest())
  534. ->then
  535. ->boolean($test->isIgnored())->isTrue()
  536. ->boolean($test->methodIsIgnored('testMethod1'))->isTrue()
  537. ->boolean($test->methodIsIgnored('testMethod2'))->isTrue()
  538. ->sizeOf($test)->isEqualTo(0)
  539. ->array($test->getTestMethods())->isEmpty()
  540. ->boolean($test->ignore(false)->isIgnored())->isFalse()
  541. ->boolean($test->methodIsIgnored('testMethod1'))->isFalse()
  542. ->boolean($test->methodIsIgnored('testMethod2'))->isFalse()
  543. ->sizeOf($test)->isEqualTo(2)
  544. ->array($test->getTestMethods())->isEqualTo(array('testMethod1', 'testMethod2'))
  545. ->array($test->getTestMethods(array('method')))->isEqualTo(array('testMethod1', 'testMethod2'))
  546. ->array($test->getTestMethods(array('test')))->isEqualTo(array('testMethod1', 'testMethod2'))
  547. ->array($test->getTestMethods(array('two')))->isEqualTo(array('testMethod2'))
  548. ->array($test->getTestMethods(array(uniqid())))->isEmpty()
  549. ->array($test->getTestMethods(array('test', 'method')))->isEqualTo(array('testMethod1', 'testMethod2'))
  550. ->array($test->getTestMethods(array('test', 'method', uniqid())))->isEqualTo(array('testMethod1', 'testMethod2'))
  551. ->array($test->getTestMethods(array('test', 'method', 'two', uniqid())))->isEqualTo(array('testMethod1', 'testMethod2'))
  552. ;
  553. }
  554. public function testGetPhpPath()
  555. {
  556. $this
  557. ->if($test = new emptyTest())
  558. ->then
  559. ->variable($test->getPhpPath())->isNull()
  560. ->if($test->setPhpPath($phpPath = uniqid()))
  561. ->then
  562. ->string($test->getPhpPath())->isEqualTo($phpPath)
  563. ;
  564. }
  565. public function testSetPhpPath()
  566. {
  567. $this
  568. ->if($test = new emptyTest())
  569. ->then
  570. ->object($test->setPhpPath($phpPath = uniqid()))->isIdenticalTo($test)
  571. ->string($test->getPhpPath())->isIdenticalTo($phpPath)
  572. ->object($test->setPhpPath($phpPath = rand(1, PHP_INT_MAX)))->isIdenticalTo($test)
  573. ->string($test->getPhpPath())->isIdenticalTo((string) $phpPath)
  574. ;
  575. }
  576. public function testMethodIsIgnored()
  577. {
  578. $this
  579. ->if($test = new emptyTest())
  580. ->then
  581. ->exception(function() use ($test, & $method) { $test->methodIsIgnored($method = uniqid()); })
  582. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  583. ->hasMessage('Test method ' . get_class($test) . '::' . $method . '() does not exist')
  584. ;
  585. }
  586. public function testSetTags()
  587. {
  588. $this
  589. ->if($test = new emptyTest())
  590. ->then
  591. ->object($test->setTags($tags = array(uniqid(), uniqid())))->isIdenticalTo($test)
  592. ->array($test->getTags())->isEqualTo($tags)
  593. ;
  594. }
  595. public function testSetMethodTags()
  596. {
  597. $this
  598. ->if($test = new notEmptyTest())
  599. ->then
  600. ->object($test->setMethodTags('testMethod1', $tags = array(uniqid(), uniqid())))->isIdenticalTo($test)
  601. ->array($test->getMethodTags('testMethod1'))->isEqualTo($tags)
  602. ->exception(function() use ($test, & $method) { $test->setMethodTags($method = uniqid(), array()); })
  603. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  604. ->hasMessage('Test method ' . get_class($test) . '::' . $method . '() does not exist')
  605. ;
  606. }
  607. public function testGetMethodTags()
  608. {
  609. $this
  610. ->if($test = new notemptyTest())
  611. ->then
  612. ->array($test->getMethodTags('testMethod1'))->isEqualTo(array('test', 'method', 'one'))
  613. ->exception(function() use ($test, & $method) { $test->getMethodTags($method = uniqid()); })
  614. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  615. ->hasMessage('Test method ' . get_class($test) . '::' . $method . '() does not exist')
  616. ;
  617. }
  618. public function testAddMandatoryClassExtension()
  619. {
  620. $this
  621. ->if($test = new notEmptyTest())
  622. ->then
  623. ->object($test->addMandatoryClassExtension($extension = uniqid()))->isIdenticalTo($test)
  624. ->array($test->getMandatoryClassExtensions())->isEqualTo(array($extension))
  625. ->object($test->addMandatoryClassExtension($otherExtension = uniqid()))->isIdenticalTo($test)
  626. ->array($test->getMandatoryClassExtensions())->isEqualTo(array($extension, $otherExtension))
  627. ;
  628. }
  629. public function testGetMandatoryMethodExtensions()
  630. {
  631. $this
  632. ->if($test = new notEmptyTest())
  633. ->then
  634. ->array($test->getMandatoryMethodExtensions('testMethod1'))->isEmpty()
  635. ->array($test->getMandatoryMethodExtensions('testMethod2'))->isEqualTo(array('mbstring', 'socket'))
  636. ;
  637. }
  638. public function testAddMandatoryMethodExtension()
  639. {
  640. $this
  641. ->if($test = new notEmptyTest())
  642. ->then
  643. ->exception(function() use ($test, & $method) { $test->addMandatoryMethodExtension($method = uniqid(), uniqid()); })
  644. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  645. ->hasMessage('Test method ' . get_class($test) . '::' . $method . '() does not exist')
  646. ->object($test->addMandatoryMethodExtension('testMethod1', $extension = uniqid()))->isIdenticalTo($test)
  647. ->array($test->getMandatoryMethodExtensions())->isEqualTo(array('testMethod1' => array($extension), 'testMethod2' => array('mbstring', 'socket')))
  648. ->array($test->getMandatoryMethodExtensions('testMethod1'))->isEqualTo(array($extension))
  649. ->array($test->getMandatoryMethodExtensions('testMethod2'))->isEqualTo(array('mbstring', 'socket'))
  650. ->object($test->addMandatoryMethodExtension('testMethod1', $otherExtension = uniqid()))->isIdenticalTo($test)
  651. ->array($test->getMandatoryMethodExtensions())->isEqualTo(array('testMethod1' => array($extension, $otherExtension), 'testMethod2' => array('mbstring', 'socket')))
  652. ->array($test->getMandatoryMethodExtensions('testMethod1'))->isEqualTo(array($extension, $otherExtension))
  653. ->array($test->getMandatoryMethodExtensions('testMethod2'))->isEqualTo(array('mbstring', 'socket'))
  654. ->object($test->addMandatoryMethodExtension('testMethod2', $anOtherExtension = uniqid()))->isIdenticalTo($test)
  655. ->array($test->getMandatoryMethodExtensions())->isEqualTo(array('testMethod1' => array($extension, $otherExtension), 'testMethod2' => array('mbstring', 'socket', $anOtherExtension)))
  656. ->array($test->getMandatoryMethodExtensions('testMethod1'))->isEqualTo(array($extension, $otherExtension))
  657. ->array($test->getMandatoryMethodExtensions('testMethod2'))->isEqualTo(array('mbstring', 'socket', $anOtherExtension))
  658. ->if($test->addMandatoryClassExtension($classExtension = uniqid()))
  659. ->then
  660. ->array($test->getMandatoryMethodExtensions())->isEqualTo(array('testMethod1' => array($classExtension, $extension, $otherExtension), 'testMethod2' => array($classExtension, 'mbstring', 'socket', $anOtherExtension)))
  661. ->array($test->getMandatoryMethodExtensions('testMethod1'))->isEqualTo(array($classExtension, $extension, $otherExtension))
  662. ->array($test->getMandatoryMethodExtensions('testMethod2'))->isEqualTo(array($classExtension, 'mbstring', 'socket', $anOtherExtension))
  663. ;
  664. }
  665. public function testAddClassPhpVersion()
  666. {
  667. $this
  668. ->if($test = new notEmptyTest())
  669. ->then
  670. ->object($test->addClassPhpVersion('5.3'))->isIdenticalTo($test)
  671. ->array($test->getClassPhpVersions())->isEqualTo(array('5.3' => '>='))
  672. ->object($test->addClassPhpVersion('5.4', '<='))->isIdenticalTo($test)
  673. ->array($test->getClassPhpVersions())->isEqualTo(array('5.3' => '>=', '5.4' => '<='))
  674. ;
  675. }
  676. public function testAddMethodPhpVersion()
  677. {
  678. $this
  679. ->if($test = new notEmptyTest())
  680. ->then
  681. ->exception(function() use ($test, & $method) { $test->addMethodPhpVersion($method, '6.0'); })
  682. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  683. ->hasMessage('Test method ' . get_class($test) . '::' . $method . '() does not exist')
  684. ->object($test->addMethodPhpVersion('testMethod1', '5.3'))->isIdenticalTo($test)
  685. ->array($test->getMethodPhpVersions())->isEqualTo(array('testMethod1' => array('5.3' => '>='), 'testMethod2' => array()))
  686. ->array($test->getMethodPhpVersions('testMethod1'))->isEqualTo(array('5.3' => '>='))
  687. ->array($test->getMethodPhpVersions('testMethod2'))->isEmpty()
  688. ->object($test->addMethodPhpVersion('testMethod1', '5.4', '<='))->isIdenticalTo($test)
  689. ->array($test->getMethodPhpVersions())->isEqualTo(array('testMethod1' => array('5.3' => '>=', '5.4' => '<='), 'testMethod2' => array()))
  690. ->array($test->getMethodPhpVersions('testMethod1'))->isEqualTo(array('5.3' => '>=', '5.4' => '<='))
  691. ->array($test->getMethodPhpVersions('testMethod2'))->isEmpty()
  692. ->object($test->addMethodPhpVersion('testMethod2', '5.4', '>='))->isIdenticalTo($test)
  693. ->array($test->getMethodPhpVersions())->isEqualTo(array('testMethod1' => array('5.3' => '>=', '5.4' => '<='), 'testMethod2' => array('5.4' => '>=')))
  694. ->array($test->getMethodPhpVersions('testMethod1'))->isEqualTo(array('5.3' => '>=', '5.4' => '<='))
  695. ->array($test->getMethodPhpVersions('testMethod2'))->isEqualTo(array('5.4' => '>='))
  696. ->if($test->addClassPhpVersion('5.5'))
  697. ->then
  698. ->array($test->getMethodPhpVersions())->isEqualTo(array('testMethod1' => array('5.5' => '>=', '5.3' => '>=', '5.4' => '<='), 'testMethod2' => array('5.5' => '>=', '5.4' => '>=')))
  699. ->array($test->getMethodPhpVersions('testMethod1'))->isEqualTo(array('5.5' => '>=', '5.3' => '>=', '5.4' => '<='))
  700. ->array($test->getMethodPhpVersions('testMethod2'))->isEqualTo(array('5.5' => '>=', '5.4' => '>='))
  701. ;
  702. }
  703. public function testRun()
  704. {
  705. $this
  706. ->mockTestedClass('mock\tests\units')
  707. ->if($test = new \mock\tests\units\test())
  708. ->then
  709. ->object($test->run())->isIdenticalTo($test)
  710. ->mock($test)
  711. ->call('callObservers')
  712. ->withArguments(\mageekguy\atoum\test::runStart)->never()
  713. ->withArguments(\mageekguy\atoum\test::runStop)->never()
  714. ->withArguments(\mageekguy\atoum\test::beforeSetUp)->never()
  715. ->withArguments(\mageekguy\atoum\test::afterSetUp)->never()
  716. ->withArguments(\mageekguy\atoum\test::beforeTestMethod)->never()
  717. ->withArguments(\mageekguy\atoum\test::afterTestMethod)->never()
  718. ;
  719. }
  720. public function testSetTestedClassName()
  721. {
  722. $this
  723. ->if($test = new foo())
  724. ->then
  725. ->string($test->getTestedClassName())->isEqualTo('mageekguy\atoum\test')
  726. ->exception(function() use ($test) { $test->setTestedClassName(uniqid()); })
  727. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  728. ->hasMessage('Tested class name is already defined')
  729. ->if($test = new self())
  730. ->then
  731. ->object($test->setTestedClassName($class = uniqid()))->isIdenticalTo($test)
  732. ->string($test->getTestedClassName())->isEqualTo($class)
  733. ->exception(function() use ($test) { $test->setTestedClassName(uniqid()); })
  734. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  735. ->hasMessage('Tested class name is already defined')
  736. ;
  737. }
  738. public function testMockClass()
  739. {
  740. $this
  741. ->if($test = new emptyTest())
  742. ->then
  743. ->object($test->mockClass(__CLASS__))->isIdenticalTo($test)
  744. ->class('mock\\' . __CLASS__)->isSubClassOf(__CLASS__)
  745. ->object($test->mockClass(__CLASS__, 'foo'))->isIdenticalTo($test)
  746. ->class('foo\test')->isSubClassOf(__CLASS__)
  747. ->object($test->mockClass(__CLASS__, 'foo\bar'))->isIdenticalTo($test)
  748. ->class('foo\bar\test')->isSubClassOf(__CLASS__)
  749. ->object($test->mockClass(__CLASS__, 'foo', 'bar'))->isIdenticalTo($test)
  750. ->class('foo\bar')->isSubClassOf(__CLASS__)
  751. ;
  752. }
  753. public function testMockTestedClass()
  754. {
  755. $this
  756. ->if($test = new emptyTest())
  757. ->and($testedClassName = $test->getTestedClassName())
  758. ->then
  759. ->object($test->mockTestedClass())->isIdenticalTo($test)
  760. ->class('mock\\' . $testedClassName)->isSubClassOf($testedClassName)
  761. ->object($test->mockTestedClass('foo'))->isIdenticalTo($test)
  762. ->class('foo\emptyTest')->isSubClassOf($testedClassName)
  763. ->object($test->mockTestedClass('foo\bar'))->isIdenticalTo($test)
  764. ->class('foo\bar\emptyTest')->isSubClassOf($testedClassName)
  765. ->object($test->mockTestedClass('foo', 'bar'))->isIdenticalTo($test)
  766. ->class('foo\bar')->isSubClassOf($testedClassName)
  767. ;
  768. }
  769. public function testGetTaggedTestMethods()
  770. {
  771. $this
  772. ->if($test = new emptyTest())
  773. ->then
  774. ->array($test->getTaggedTestMethods(array()))->isEmpty()
  775. ->array($test->getTaggedTestMethods(array(uniqid())))->isEmpty()
  776. ->array($test->getTaggedTestMethods(array(uniqid(), uniqid())))->isEmpty()
  777. ->if($test = new notEmptyTest())
  778. ->then
  779. ->array($test->getTaggedTestMethods(array()))->isEmpty()
  780. ->array($test->getTaggedTestMethods(array(uniqid())))->isEmpty()
  781. ->array($test->getTaggedTestMethods(array(uniqid(), uniqid())))->isEmpty()
  782. ->array($test->getTaggedTestMethods(array(uniqid(), 'testMethod1', uniqid())))->isEmpty()
  783. ->array($test->getTaggedTestMethods(array(uniqid(), 'testMethod1', uniqid(), 'testMethod2')))->isEmpty()
  784. ->array($test->getTaggedTestMethods(array(uniqid(), 'Testmethod1', uniqid(), 'Testmethod2')))->isEmpty()
  785. ->if($test->ignore(false))
  786. ->then
  787. ->array($test->getTaggedTestMethods(array(uniqid(), 'testMethod1', uniqid())))->isEqualTo(array('testMethod1'))
  788. ->array($test->getTaggedTestMethods(array(uniqid(), 'testMethod2', uniqid())))->isEqualTo(array('testMethod2'))
  789. ->array($test->getTaggedTestMethods(array(uniqid(), 'Testmethod1', uniqid(), 'Testmethod2')))->isEqualTo(array('Testmethod1', 'Testmethod2'))
  790. ->array($test->getTaggedTestMethods(array(uniqid(), 'Testmethod1', uniqid(), 'Testmethod2'), array('one')))->isEqualTo(array('Testmethod1'))
  791. ->if($test->ignoreMethod('testMethod1', true))
  792. ->then
  793. ->array($test->getTaggedTestMethods(array(uniqid(), 'testMethod1', uniqid())))->isEmpty()
  794. ->array($test->getTaggedTestMethods(array(uniqid(), 'testMethod2', uniqid())))->isEqualTo(array('testMethod2'))
  795. ->array($test->getTaggedTestMethods(array(uniqid(), 'Testmethod1', uniqid(), 'Testmethod2')))->isEqualTo(array('Testmethod2'))
  796. ->array($test->getTaggedTestMethods(array(uniqid(), 'Testmethod1', uniqid(), 'Testmethod2'), array('one')))->isEmpty()
  797. ;
  798. }
  799. public function testSetDataProvider()
  800. {
  801. $this
  802. ->if($test = new emptyTest())
  803. ->then
  804. ->exception(function() use ($test, & $method) { $test->setDataProvider($method = uniqid(), uniqid()); })
  805. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  806. ->hasMessage('Test method ' . get_class($test) . '::' . $method . '() does not exist')
  807. ->if($test = new notEmptyTest())
  808. ->then
  809. ->exception(function() use ($test, & $dataProvider) { $test->setDataProvider('testMethod1', $dataProvider = uniqid()); })
  810. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  811. ->hasMessage('Data provider ' . get_class($test) . '::' . $dataProvider . '() is unknown')
  812. ->object($test->setDataProvider('testMethod1', 'aDataProvider'))->isIdenticalTo($test)
  813. ->array($test->getDataProviders())->isEqualTo(array('testMethod1' => 'aDataProvider'))
  814. ;
  815. }
  816. public function testCalling()
  817. {
  818. $this
  819. ->if($test = new emptyTest())
  820. ->and($mock = new \mock\foo())
  821. ->and($test->calling($mock)->bar = $value = uniqid())
  822. ->then
  823. ->string($mock->bar())->isEqualTo($value)
  824. ->and($test->Æ’($mock)->bar = $otherValue = uniqid())
  825. ->then
  826. ->string($mock->bar())->isEqualTo($otherValue)
  827. ;
  828. }
  829. public function testResetMock()
  830. {
  831. $this
  832. ->if($test = new emptyTest())
  833. ->and($mockController = new \mock\mageekguy\atoum\mock\controller())
  834. ->and($mockController->control($mock = new \mock\object()))
  835. ->and($this->resetMock($mockController))
  836. ->then
  837. ->object($test->resetMock($mock))->isIdenticalTo($mock->getMockController())
  838. ->mock($mockController)->call('resetCalls')->once()
  839. ;
  840. }
  841. public function testResetFunction()
  842. {
  843. $this
  844. ->if($test = new emptyTest())
  845. ->and($this->function->md5 = uniqid())
  846. ->then
  847. ->object($test->resetFunction($this->function->md5))->isIdenticalTo($this->function->md5)
  848. ;
  849. }
  850. public function testResetAdapter()
  851. {
  852. $this
  853. ->if($test = new emptyTest())
  854. ->and($adapter = new \mock\mageekguy\atoum\test\adapter())
  855. ->and($this->resetMock($adapter))
  856. ->then
  857. ->object($test->resetAdapter($adapter))->isIdenticalTo($adapter)
  858. ->mock($adapter)->call('resetCalls')->once()
  859. ;
  860. }
  861. public function testErrorHandler()
  862. {
  863. $this
  864. ->if($test = new emptyTest())
  865. ->and($adapter = new atoum\test\adapter())
  866. ->and($adapter->error_reporting = 0)
  867. ->and($test->setAdapter($adapter))
  868. ->then
  869. ->boolean($test->errorHandler(rand(1, PHP_INT_MAX), uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  870. ->array($test->getScore()->getErrors())->isEmpty()
  871. ->if($adapter->error_reporting = E_ALL)
  872. ->then
  873. ->boolean($test->errorHandler(E_NOTICE, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  874. ->variable($test->getScore()->errorExists($errstr, E_NOTICE))->isNotNull()
  875. ->boolean($test->errorHandler(E_WARNING, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  876. ->variable($test->getScore()->errorExists($errstr, E_WARNING))->isNotNull()
  877. ->boolean($test->errorHandler(E_USER_NOTICE, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  878. ->variable($test->getScore()->errorExists($errstr, E_USER_NOTICE))->isNotNull()
  879. ->boolean($test->errorHandler(E_USER_WARNING, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  880. ->variable($test->getScore()->errorExists($errstr, E_USER_WARNING))->isNotNull()
  881. ->boolean($test->errorHandler(E_DEPRECATED, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  882. ->variable($test->getScore()->errorExists($errstr, E_DEPRECATED))->isNotNull()
  883. ->boolean($test->errorHandler(E_RECOVERABLE_ERROR, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isFalse()
  884. ->variable($test->getScore()->errorExists($errstr, E_RECOVERABLE_ERROR))->isNotNull()
  885. ->if($adapter->error_reporting = E_ALL & ~E_DEPRECATED)
  886. ->then
  887. ->boolean($test->errorHandler(E_NOTICE, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  888. ->variable($test->getScore()->errorExists($errstr, E_NOTICE))->isNotNull()
  889. ->boolean($test->errorHandler(E_WARNING, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  890. ->variable($test->getScore()->errorExists($errstr, E_WARNING))->isNotNull()
  891. ->boolean($test->errorHandler(E_USER_NOTICE, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  892. ->variable($test->getScore()->errorExists($errstr, E_USER_NOTICE))->isNotNull()
  893. ->boolean($test->errorHandler(E_USER_WARNING, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  894. ->variable($test->getScore()->errorExists($errstr, E_USER_WARNING))->isNotNull()
  895. ->boolean($test->errorHandler(E_DEPRECATED, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  896. ->variable($test->getScore()->errorExists($errstr, E_DEPRECATED))->isNull()
  897. ->if($adapter->error_reporting = E_ALL & ~E_RECOVERABLE_ERROR)
  898. ->then
  899. ->boolean($test->errorHandler(E_RECOVERABLE_ERROR, $errstr = uniqid(), uniqid(), rand(1, PHP_INT_MAX), uniqid()))->isTrue()
  900. ->variable($test->getScore()->errorExists($errstr, E_RECOVERABLE_ERROR))->isNull()
  901. ->if($adapter->error_reporting = 32767)
  902. ->and($factory = function($class) use (& $reflection, & $filename, & $classname) {
  903. $reflection = new \mock\ReflectionClass($class);
  904. $reflection->getMockController()->getFilename = $filename = 'filename';
  905. $reflection->getMockController()->getName = $classname = 'classname';
  906. return $reflection;
  907. })
  908. ->and($score = new \mock\mageekguy\atoum\test\score())
  909. ->and($test = new emptyTest(null, null, null, null, $factory))
  910. ->and($test->setAdapter($adapter))
  911. ->and($test->setScore($score))
  912. ->then
  913. ->boolean($test->errorHandler($errno = E_NOTICE, $errstr = 'errstr', $errfile = 'errfile', $errline = rand(1, PHP_INT_MAX)))->isTrue()
  914. ->mock($score)
  915. ->call('addError')->withArguments($errfile, $classname, $test->getCurrentMethod(), $errline, $errno, $errstr, $errfile, $errline, null, null, null)->once()
  916. ->boolean($test->errorHandler($errno, $errstr, null, $errline = rand(1, PHP_INT_MAX)))->isTrue()
  917. ->mock($score)
  918. ->call('addError')->withArguments($filename, $classname, $test->getCurrentMethod(), $errline, $errno, $errstr, null, $errline, null, null, null)->once()
  919. ;
  920. }
  921. public function testGetTestedClassNameFromTestClass()
  922. {
  923. $this
  924. ->string(atoum\test::getTestedClassNameFromTestClass(__CLASS__))->isEqualTo('mageekguy\atoum\test')
  925. ->string(atoum\test::getTestedClassNameFromTestClass('foo\bar\tests\units\testedClass'))->isEqualTo('foo\bar\testedClass')
  926. ->if(atoum\test::setNamespace('test\unit'))
  927. ->then
  928. ->string(atoum\test::getTestedClassNameFromTestClass('foo\bar\test\unit\testedClass'))->isEqualTo('foo\bar\testedClass')
  929. ->if(atoum\test::setNamespace('\test\unit\\'))
  930. ->then
  931. ->string(atoum\test::getTestedClassNameFromTestClass('foo\bar\test\unit\testedClass'))->isEqualTo('foo\bar\testedClass')
  932. ->if(atoum\test::setNamespace('test\unit\\'))
  933. ->then
  934. ->string(atoum\test::getTestedClassNameFromTestClass('foo\bar\test\unit\testedClass'))->isEqualTo('foo\bar\testedClass')
  935. ->if(atoum\test::setNamespace('\test\unit'))
  936. ->then
  937. ->string(atoum\test::getTestedClassNameFromTestClass('foo\bar\test\unit\testedClass'))->isEqualTo('foo\bar\testedClass')
  938. ->exception(function() { atoum\test::getTestedClassNameFromTestClass('foo\bar\aaa\bbb\testedClass'); })
  939. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  940. ->hasMessage('Test class \'foo\bar\aaa\bbb\testedClass\' is not in a namespace which contains \'' . atoum\test::getNamespace() . '\'')
  941. ->if(atoum\test::setNamespace('#(?:^|\\\)xxxs?\\\yyys?\\\#i'))
  942. ->then
  943. ->string(atoum\test::getTestedClassNameFromTestClass('foo\bar\xxx\yyy\testedClass'))->isEqualTo('foo\bar\testedClass')
  944. ->string(atoum\test::getTestedClassNameFromTestClass('foo\bar\xxxs\yyy\testedClass'))->isEqualTo('foo\bar\testedClass')
  945. ->string(atoum\test::getTestedClassNameFromTestClass('foo\bar\xxxs\yyys\testedClass'))->isEqualTo('foo\bar\testedClass')
  946. ->string(atoum\test::getTestedClassNameFromTestClass('foo\bar\xxx\yyys\testedClass'))->isEqualTo('foo\bar\testedClass')
  947. ->exception(function() { atoum\test::getTestedClassNameFromTestClass('foo\bar\aaa\bbb\testedClass'); })
  948. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  949. ->hasMessage('Test class \'foo\bar\aaa\bbb\testedClass\' is not in a namespace which match pattern \'' . atoum\test::getNamespace() . '\'')
  950. ->string(atoum\test::getTestedClassNameFromTestClass('foo\bar\aaa\bbb\testedClass', '#(?:^|\\\)aaas?\\\bbbs?\\\#i'))->isEqualTo('foo\bar\testedClass')
  951. ;
  952. }
  953. public function testAddExtension()
  954. {
  955. $this
  956. ->if($test = new emptyTest())
  957. ->then
  958. ->object($test->addExtension($extension = new \mock\mageekguy\atoum\extension()))->isIdenticalTo($test)
  959. ->array($test->getExtensions())->isEqualTo(array($extension))
  960. ->array($test->getObservers())->contains($extension)
  961. ->mock($extension)
  962. ->call('setTest')->withArguments($test)->once()
  963. ->if($this->resetMock($extension))
  964. ->then
  965. ->object($test->addExtension($extension))->isIdenticalTo($test)
  966. ->array($test->getExtensions())->isEqualTo(array($extension))
  967. ->array($test->getObservers())->contains($extension)
  968. ->mock($extension)
  969. ->call('setTest')->never();
  970. ;
  971. }
  972. public function testRemoveExtension()
  973. {
  974. $this
  975. ->if($test = new emptyTest())
  976. ->then
  977. ->array($test->getExtensions())->isEmpty()
  978. ->array($test->getObservers())->isEmpty()
  979. ->object($test->removeExtension(new \mock\mageekguy\atoum\extension()))->isIdenticalTo($test)
  980. ->array($test->getExtensions())->isEmpty()
  981. ->array($test->getObservers())->isEmpty()
  982. ->if($extension = new \mock\mageekguy\atoum\extension())
  983. ->and($otherExtension = new \mock\mageekguy\atoum\extension())
  984. ->and($test->addExtension($extension)->addExtension($otherExtension))
  985. ->then
  986. ->array($test->getExtensions())->isEqualTo(array($extension, $otherExtension))
  987. ->array($test->getObservers())->isEqualTo(array($extension, $otherExtension))
  988. ->object($test->removeExtension(new \mock\mageekguy\atoum\extension()))->isIdenticalTo($test)
  989. ->array($test->getExtensions())->isEqualTo(array($extension, $otherExtension))
  990. ->array($test->getObservers())->isEqualTo(array($extension, $otherExtension))
  991. ->object($test->removeExtension($extension))->isIdenticalTo($test)
  992. ->array($test->getExtensions())->isEqualTo(array($otherExtension))
  993. ->array($test->getObservers())->isEqualTo(array($otherExtension))
  994. ->object($test->removeExtension($otherExtension))->isIdenticalTo($test)
  995. ->array($test->getExtensions())->isEmpty()
  996. ->array($test->getObservers())->isEmpty()
  997. ;
  998. }
  999. public function testRemoveExtensions()
  1000. {
  1001. $this
  1002. ->if($test = new emptyTest())
  1003. ->then
  1004. ->array($test->getExtensions())->isEmpty()
  1005. ->array($test->getObservers())->isEmpty()
  1006. ->object($test->removeExtensions())->isIdenticalTo($test)
  1007. ->array($test->getExtensions())->isEmpty()
  1008. ->array($test->getObservers())->isEmpty()
  1009. ->if($extension = new \mock\mageekguy\atoum\extension())
  1010. ->and($otherExtension = new \mock\mageekguy\atoum\extension())
  1011. ->and($test->addExtension($extension)->addExtension($otherExtension))
  1012. ->then
  1013. ->array($test->getExtensions())->isEqualTo(array($extension, $otherExtension))
  1014. ->array($test->getObservers())->isEqualTo(array($extension, $otherExtension))
  1015. ->object($test->removeExtensions())->isIdenticalTo($test)
  1016. ->array($test->getExtensions())->isEmpty()
  1017. ->array($test->getObservers())->isEmpty()
  1018. ;
  1019. }
  1020. }
  1021. }