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

/tests/units/classes/report/fields/runner/coverage/html.php

http://github.com/mageekguy/atoum
PHP | 525 lines | 518 code | 7 blank | 0 comment | 1 complexity | 2d55f7226cd8d624ef819e230537c0f3 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\report\fields\runner\coverage;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\test,
  6. mageekguy\atoum\locale,
  7. mageekguy\atoum\template,
  8. mageekguy\atoum\mock,
  9. mageekguy\atoum\mock\stream,
  10. mageekguy\atoum\cli\prompt,
  11. mageekguy\atoum\cli\colorizer,
  12. mageekguy\atoum\report\fields\runner\coverage\html as testedClass
  13. ;
  14. require_once __DIR__ . '/../../../../../runner.php';
  15. class html extends atoum\test
  16. {
  17. public function testClass()
  18. {
  19. $this->testedClass->extends('mageekguy\atoum\report\fields\runner\coverage\cli');
  20. }
  21. public function test__construct()
  22. {
  23. $this
  24. ->if($field = new testedClass($projectName = uniqid(), $destinationDirectory = uniqid()))
  25. ->then
  26. ->string($field->getProjectName())->isEqualTo($projectName)
  27. ->string($field->getDestinationDirectory())->isEqualTo($destinationDirectory)
  28. ->string($field->getTemplatesDirectory())->isEqualTo(atoum\directory . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'coverage')
  29. ->object($field->getPrompt())->isEqualTo(new prompt())
  30. ->object($field->getTitleColorizer())->isEqualTo(new colorizer())
  31. ->object($field->getCoverageColorizer())->isEqualTo(new colorizer())
  32. ->object($field->getUrlPrompt())->isEqualTo(new prompt())
  33. ->object($field->getUrlColorizer())->isEqualTo(new colorizer())
  34. ->object($field->getPhp())->isEqualTo(new atoum\php())
  35. ->object($field->getAdapter())->isEqualTo(new atoum\adapter())
  36. ->object($field->getLocale())->isEqualTo(new locale())
  37. ->object($field->getTemplateParser())->isInstanceOf('mageekguy\atoum\template\parser')
  38. ->variable($field->getCoverage())->isNull()
  39. ->array($field->getSrcDirectories())->isEmpty()
  40. ->array($field->getEvents())->isEqualTo(array(atoum\runner::runStop))
  41. ;
  42. }
  43. public function test__toString()
  44. {
  45. $this
  46. ->if($field = new testedClass(uniqid(), uniqid()))
  47. ->then
  48. ->castToString($field)->isEqualTo('Code coverage: unknown.' . PHP_EOL)
  49. ->if($coverage = new \mock\mageekguy\atoum\score\coverage())
  50. ->and($coverageController = $coverage->getMockController())
  51. ->and($coverageController->count = rand(1, PHP_INT_MAX))
  52. ->and($coverageController->getClasses = array(
  53. $className = uniqid() => $classFile = uniqid()
  54. )
  55. )
  56. ->and($coverageController->getMethods = array(
  57. $className =>
  58. array(
  59. $method1Name = uniqid() =>
  60. array(
  61. 5 => 1,
  62. 6 => 1,
  63. 7 => -1,
  64. 8 => 1,
  65. 9 => -2
  66. ),
  67. $method3Name = uniqid() =>
  68. array(
  69. 10 => -2
  70. ),
  71. $method4Name = uniqid() =>
  72. array(
  73. 11 => 1,
  74. 12 => -2
  75. )
  76. )
  77. )
  78. )
  79. ->and($coverageController->getValue = $coverageValue = rand(1, 10) / 10)
  80. ->and($coverageController->getValueForClass = $classCoverageValue = rand(1, 10) / 10)
  81. ->and($coverageController->getValueForMethod = $methodCoverageValue = rand(1, 10) / 10)
  82. ->and($score = new \mock\mageekguy\atoum\score())
  83. ->and($score->getMockController()->getCoverage = $coverage)
  84. ->if($classCoverageTemplate = new \mock\mageekguy\atoum\template\tag('classCoverage'))
  85. ->and($classCoverageTemplate->addChild($classCoverageAvailableTemplate = new \mock\mageekguy\atoum\template\tag('classCoverageAvailable')))
  86. ->and($indexTemplate = new \mock\mageekguy\atoum\template())
  87. ->and($indexTemplate
  88. ->addChild($coverageAvailableTemplate = new \mock\mageekguy\atoum\template\tag('coverageAvailable'))
  89. ->addChild($classCoverageTemplate)
  90. )
  91. ->and($indexTemplateController = $indexTemplate->getMockController())
  92. ->and($indexTemplateController->__set = function() {})
  93. ->and($indexTemplateController->build = $buildOfIndexTemplate = uniqid())
  94. ->and($methodTemplate = new \mock\mageekguy\atoum\template())
  95. ->and($methodTemplateController = $methodTemplate->getMockController())
  96. ->and($methodTemplateController->__set = function() {})
  97. ->and($lineTemplate = new \mock\mageekguy\atoum\template\tag('line'))
  98. ->and($lineTemplateController = $lineTemplate->getMockController())
  99. ->and($lineTemplateController->__set = function() {})
  100. ->and($coveredLineTemplate = new \mock\mageekguy\atoum\template\tag('coveredLine'))
  101. ->and($coveredLineTemplateController = $coveredLineTemplate->getMockController())
  102. ->and($coveredLineTemplateController->__set = function() {})
  103. ->and($notCoveredLineTemplate = new \mock\mageekguy\atoum\template\tag('notCoveredLine'))
  104. ->and($notCoveredLineTemplateController = $notCoveredLineTemplate->getMockController())
  105. ->and($notCoveredLineTemplateController->__set = function() {})
  106. ->and($sourceFileTemplate = new \mock\mageekguy\atoum\template\tag('sourceFile'))
  107. ->and($sourceFileTemplateController = $sourceFileTemplate->getMockController())
  108. ->and($sourceFileTemplateController->__set = function() {})
  109. ->and($sourceFileTemplate
  110. ->addChild($lineTemplate)
  111. ->addChild($coveredLineTemplate)
  112. ->addChild($notCoveredLineTemplate)
  113. )
  114. ->and($methodCoverageAvailableTemplate = new \mock\mageekguy\atoum\template\tag('methodCoverageAvailable'))
  115. ->and($methodTemplate = new \mock\mageekguy\atoum\template\tag('method'))
  116. ->and($methodTemplate->addChild($methodCoverageAvailableTemplate))
  117. ->and($methodsTemplate = new \mock\mageekguy\atoum\template\tag('methods'))
  118. ->and($methodsTemplate->addChild($methodTemplate))
  119. ->and($classTemplate = new \mock\mageekguy\atoum\template())
  120. ->and($classTemplateController = $classTemplate->getMockController())
  121. ->and($classTemplateController->__set = function() {})
  122. ->and($classTemplate
  123. ->addChild($methodsTemplate)
  124. ->addChild($sourceFileTemplate)
  125. )
  126. ->and($reflectedClassController = new mock\controller())
  127. ->and($reflectedClassController->__construct = function() {})
  128. ->and($reflectedClassController->getName = $className)
  129. ->and($reflectedClass = new \mock\reflectionClass(uniqid(), $reflectedClassController))
  130. ->and($otherReflectedClassController = new mock\controller())
  131. ->and($otherReflectedClassController->__construct = function() {})
  132. ->and($otherReflectedClassController->getName = uniqid())
  133. ->and($otherReflectedClass = new \mock\reflectionClass(uniqid(), $otherReflectedClassController))
  134. ->and($reflectedMethod1Controller = new mock\controller())
  135. ->and($reflectedMethod1Controller->__construct = function() {})
  136. ->and($reflectedMethod1Controller->getName = $method1Name)
  137. ->and($reflectedMethod1Controller->isAbstract = false)
  138. ->and($reflectedMethod1Controller->getDeclaringClass = $reflectedClass)
  139. ->and($reflectedMethod1Controller->getStartLine = 5)
  140. ->and($reflectedMethod1 = new \mock\reflectionMethod(uniqid(), uniqid(), $reflectedMethod1Controller))
  141. ->and($reflectedMethod2Controller = new mock\controller())
  142. ->and($reflectedMethod2Controller->__construct = function() {})
  143. ->and($reflectedMethod2Controller->getName = $method2Name = uniqid())
  144. ->and($reflectedMethod2Controller->isAbstract = false)
  145. ->and($reflectedMethod2Controller->getDeclaringClass = $otherReflectedClass)
  146. ->and($reflectedMethod2Controller->getStartLine = 5)
  147. ->and($reflectedMethod2 = new \mock\reflectionMethod(uniqid(), uniqid(), $reflectedMethod2Controller))
  148. ->and($reflectedMethod3Controller = new mock\controller())
  149. ->and($reflectedMethod3Controller->__construct = function() {})
  150. ->and($reflectedMethod3Controller->getName = $method3Name)
  151. ->and($reflectedMethod3Controller->isAbstract = true)
  152. ->and($reflectedMethod3Controller->getDeclaringClass = $reflectedClass)
  153. ->and($reflectedMethod3Controller->getStartLine = 10)
  154. ->and($reflectedMethod3 = new \mock\reflectionMethod(uniqid(), uniqid(), $reflectedMethod3Controller))
  155. ->and($reflectedMethod4Controller = new mock\controller())
  156. ->and($reflectedMethod4Controller->__construct = function() {})
  157. ->and($reflectedMethod4Controller->getName = $method4Name)
  158. ->and($reflectedMethod4Controller->isAbstract = false)
  159. ->and($reflectedMethod4Controller->getDeclaringClass = $reflectedClass)
  160. ->and($reflectedMethod4Controller->getStartLine = 11)
  161. ->and($reflectedMethod4 = new \mock\reflectionMethod(uniqid(), uniqid(), $reflectedMethod4Controller))
  162. ->and($reflectedClassController->getMethods = array($reflectedMethod1, $reflectedMethod2, $reflectedMethod3, $reflectedMethod4))
  163. ->and($templateParser = new \mock\mageekguy\atoum\template\parser())
  164. ->and($field = new \mock\mageekguy\atoum\report\fields\runner\coverage\html($projectName = uniqid(), $destinationDirectory = uniqid()))
  165. ->and($field
  166. ->setTemplateParser($templateParser)
  167. ->setTemplatesDirectory($templatesDirectory = uniqid())
  168. ->setAdapter($adapter = new test\adapter())
  169. )
  170. ->and($fieldController = $field->getMockController())
  171. ->and($fieldController->cleanDestinationDirectory = function() {})
  172. ->and($fieldController->getReflectionClass = $reflectedClass)
  173. ->and($runner = new \mock\mageekguy\atoum\runner())
  174. ->and($runner->getMockController()->getScore = $score)
  175. ->and($field->setRootUrl($rootUrl = uniqid()))
  176. ->and($templateParserController = $templateParser->getMockController())
  177. ->and($templateParserController->parseFile = function($path) use ($templatesDirectory, $indexTemplate, $classTemplate) {
  178. switch ($path)
  179. {
  180. case $templatesDirectory . DIRECTORY_SEPARATOR . 'index.tpl':
  181. return $indexTemplate;
  182. case $templatesDirectory . DIRECTORY_SEPARATOR . 'class.tpl':
  183. return $classTemplate;
  184. }
  185. }
  186. )
  187. ->and($adapter->mkdir = function() {})
  188. ->and($adapter->file_put_contents = function() {})
  189. ->and($adapter->filemtime = $filemtime = time())
  190. ->and($adapter->fopen = $classResource = uniqid())
  191. ->and($adapter->fgets = false)
  192. ->and($adapter->fgets[1] = $line1 = uniqid())
  193. ->and($adapter->fgets[2] = $line2 = uniqid())
  194. ->and($adapter->fgets[3] = $line3 = uniqid())
  195. ->and($adapter->fgets[4] = $line4 = uniqid())
  196. ->and($adapter->fgets[5] = $line5 = uniqid())
  197. ->and($adapter->fgets[6] = $line6 = uniqid())
  198. ->and($adapter->fgets[7] = $line7 = uniqid())
  199. ->and($adapter->fgets[8] = $line8 = uniqid())
  200. ->and($adapter->fgets[9] = $line9 = uniqid())
  201. ->and($adapter->fgets[10] = $line10 = uniqid())
  202. ->and($adapter->fgets[11] = $line11 = uniqid())
  203. ->and($adapter->fgets[12] = $line12 = uniqid())
  204. ->and($adapter->fgets[13] = $line13 = uniqid())
  205. ->and($adapter->fgets[14] = $line14 = uniqid())
  206. ->and($adapter->fgets[15] = $line15 = uniqid())
  207. ->and($adapter->fclose = function() {})
  208. ->and($adapter->copy = function() {})
  209. ->and($field->handleEvent(atoum\runner::runStop, $runner))
  210. ->then
  211. ->object($field->getCoverage())->isIdenticalTo($coverage)
  212. ->castToString($field)->isIdenticalTo(sprintf($field->getLocale()->_('Code coverage: %3.2f%%.'), round($coverageValue * 100, 2)) . PHP_EOL . 'Details of code coverage are available at ' . $rootUrl . '.' . PHP_EOL)
  213. ->mock($coverage)->call('count')->once()
  214. ->mock($field)
  215. ->call('cleanDestinationDirectory')->once()
  216. ->mock($coverage)
  217. ->call('count')->once()
  218. ->call('getClasses')->once()
  219. ->call('getMethods')->once()
  220. ->call('getValueForClass')->withArguments($className)->atLeastOnce()
  221. ->call('getValueForMethod')->withArguments($className, $method1Name)->once()
  222. ->call('getValueForMethod')->withArguments($className, $method2Name)->never()
  223. ->call('getValueForMethod')->withArguments($className, $method3Name)->never()
  224. ->call('getValueForMethod')->withArguments($className, $method4Name)->once()
  225. ->mock($templateParser)
  226. ->call('parseFile')->withArguments($templatesDirectory . DIRECTORY_SEPARATOR . 'index.tpl', null)->once()
  227. ->call('parseFile')->withArguments($templatesDirectory . DIRECTORY_SEPARATOR . 'class.tpl', null)->once()
  228. ->mock($indexTemplate)
  229. ->call('__set')->withArguments('projectName', $projectName)->once()
  230. ->call('__set')->withArguments('rootUrl', $rootUrl)->once()
  231. ->call('__get')->withArguments('coverageAvailable')->once()
  232. ->call('__get')->withArguments('classCoverage')->once()
  233. ->mock($coverageAvailableTemplate)
  234. ->call('build')->withArguments(array('coverageValue' => round($coverageValue * 100, 2)))->once()
  235. ->mock($classTemplate)
  236. ->call('__set')->withArguments('rootUrl', $rootUrl)->once()
  237. ->call('__set')->withArguments('projectName' , $projectName)->once()
  238. ->call('__set')->withArguments('className', $className)->once()
  239. ->call('__get')->withArguments('methods')->once()
  240. ->call('__get')->withArguments('sourceFile')->once()
  241. ->call('build')->once()
  242. ->mock($classCoverageTemplate)
  243. ->call('__set')->withArguments('className', $className)->once()
  244. ->call('__set')->withArguments('classUrl', str_replace('\\', '/', $className) . testedClass::htmlExtensionFile)->once()
  245. ->call('build')->once()
  246. ->mock($classCoverageAvailableTemplate)
  247. ->call('build')->withArguments(array('classCoverageValue' => round($classCoverageValue * 100, 2)))->once()
  248. ->call('resetData')->atLeastOnce()
  249. ->mock($methodsTemplate)
  250. ->call('build')->once()
  251. ->call('resetData')->atLeastOnce()
  252. ->mock($methodTemplate)
  253. ->call('build')->atLeastOnce()
  254. ->call('resetData')->atLeastOnce()
  255. ->mock($methodCoverageAvailableTemplate)
  256. ->call('__set')->withArguments('methodName', $method1Name)->once()
  257. ->call('__set')->withArguments('methodName', $method2Name)->never()
  258. ->call('__set')->withArguments('methodName', $method3Name)->never()
  259. ->call('__set')->withArguments('methodName', $method4Name)->once()
  260. ->call('__set')->withArguments('methodCoverageValue', round($methodCoverageValue * 100, 2))->atLeastOnce()
  261. ->call('build')->atLeastOnce()
  262. ->call('resetData')->atLeastOnce()
  263. ->mock($lineTemplate)
  264. ->call('__set')->withArguments('code', $line1)->once()
  265. ->call('__set')->withArguments('code', $line2)->once()
  266. ->call('__set')->withArguments('code', $line3)->once()
  267. ->call('__set')->withArguments('code', $line4)->once()
  268. ->call('__set')->withArguments('code', $line9)->once()
  269. ->call('__set')->withArguments('code', $line12)->once()
  270. ->mock($coveredLineTemplate)
  271. ->call('__set')->withArguments('code', $line5)->once()
  272. ->call('__set')->withArguments('code', $line6)->once()
  273. ->call('__set')->withArguments('code', $line8)->once()
  274. ->call('__set')->withArguments('code', $line11)->once()
  275. ->mock($notCoveredLineTemplate)
  276. ->call('__set')->withArguments('code', $line7)->once()
  277. ->adapter($adapter)
  278. ->call('file_put_contents')->withArguments($destinationDirectory . DIRECTORY_SEPARATOR . 'index.html', $buildOfIndexTemplate)->once()
  279. ->call('copy')->withArguments($templatesDirectory . DIRECTORY_SEPARATOR . 'screen.css', $destinationDirectory . DIRECTORY_SEPARATOR . 'screen.css')->once()
  280. ->call('fopen')->withArguments($classFile, 'r')->once()
  281. ->call('fgets')->withArguments($classResource)->atLeastOnce()
  282. ->call('fclose')->withArguments($classResource)->once()
  283. ->if($indexTemplateController->build->throw = new \exception($errorMessage = uniqid()))
  284. ->then
  285. ->castToString($field)->isIdenticalTo(sprintf($field->getLocale()->_('Code coverage: %3.2f%%.'), round($coverageValue * 100, 2)) . PHP_EOL . 'Unable to generate code coverage at ' . $rootUrl . ': ' . $errorMessage . '.' . PHP_EOL)
  286. ;
  287. }
  288. public function testSetUrlPrompt()
  289. {
  290. $this
  291. ->if($field = new testedClass(uniqid(), uniqid()))
  292. ->then
  293. ->object($field->setUrlPrompt($urlPrompt = new prompt()))->isIdenticalTo($field)
  294. ->object($field->getUrlPrompt())->isIdenticalTo($urlPrompt)
  295. ->object($field->setUrlPrompt())->isIdenticalTo($field)
  296. ->object($field->getUrlPrompt())
  297. ->isNotIdenticalTo($urlPrompt)
  298. ->isEqualTo(new prompt())
  299. ;
  300. }
  301. public function testSetUrlColorizer()
  302. {
  303. $this
  304. ->if($field = new testedClass(uniqid(), uniqid()))
  305. ->then
  306. ->object($field->setUrlColorizer($urlColorizer = new colorizer()))->isIdenticalTo($field)
  307. ->object($field->getUrlColorizer())->isIdenticalTo($urlColorizer)
  308. ->object($field->setUrlColorizer())->isIdenticalTo($field)
  309. ->object($field->getUrlColorizer())
  310. ->isNotIdenticalTo($urlColorizer)
  311. ->isEqualTo(new colorizer())
  312. ;
  313. }
  314. public function testSetTemplatesDirectory()
  315. {
  316. $this
  317. ->if($field = new testedClass(uniqid(), uniqid()))
  318. ->then
  319. ->object($field->setTemplatesDirectory($directory = uniqid()))->isIdenticalTo($field)
  320. ->string($field->getTemplatesDirectory())->isEqualTo($directory)
  321. ->object($field->setTemplatesDirectory($directory = rand(1, PHP_INT_MAX)))->isIdenticalTo($field)
  322. ->string($field->getTemplatesDirectory())->isIdenticalTo((string) $directory)
  323. ;
  324. }
  325. public function testSetDestinationDirectory()
  326. {
  327. $this
  328. ->if($field = new testedClass(uniqid(), uniqid()))
  329. ->then
  330. ->object($field->setDestinationDirectory($directory = uniqid()))->isIdenticalTo($field)
  331. ->string($field->getDestinationDirectory())->isEqualTo($directory)
  332. ->object($field->setDestinationDirectory($directory = rand(1, PHP_INT_MAX)))->isIdenticalTo($field)
  333. ->string($field->getDestinationDirectory())->isIdenticalTo((string) $directory)
  334. ;
  335. }
  336. public function testSetTemplateParser()
  337. {
  338. $this
  339. ->if($field = new testedClass(uniqid(), uniqid(), uniqid()))
  340. ->then
  341. ->object($field->setTemplateParser($templateParser = new template\parser()))->isIdenticalTo($field)
  342. ->object($field->getTemplateParser())->isIdenticalTo($templateParser)
  343. ;
  344. }
  345. public function testSetProjectName()
  346. {
  347. $this
  348. ->if($field = new testedClass(uniqid(), uniqid()))
  349. ->then
  350. ->object($field->setProjectName($projectName = uniqid()))->isIdenticalTo($field)
  351. ->string($field->getProjectName())->isIdenticalTo($projectName)
  352. ->object($field->setProjectName($projectName = rand(1, PHP_INT_MAX)))->isIdenticalTo($field)
  353. ->string($field->getProjectName())->isIdenticalTo((string) $projectName)
  354. ;
  355. }
  356. public function testGetDestinationDirectoryIterator()
  357. {
  358. $this
  359. ->if($field = new testedClass(uniqid(), __DIR__))
  360. ->then
  361. ->object($recursiveIteratorIterator = $field->getDestinationDirectoryIterator())->isInstanceOf('recursiveIteratorIterator')
  362. ->object($recursiveDirectoryIterator = $recursiveIteratorIterator->getInnerIterator())->isInstanceOf('recursiveDirectoryIterator')
  363. ->string($recursiveDirectoryIterator->current()->getPathInfo()->getPathname())->isEqualTo(__DIR__)
  364. ;
  365. }
  366. public function testGetSrcDirectoryIterators()
  367. {
  368. $this
  369. ->if($field = new testedClass(uniqid(), uniqid()))
  370. ->then
  371. ->array($field->getSrcDirectoryIterators())->isEmpty()
  372. ->if($field->addSrcDirectory($directory = __DIR__))
  373. ->then
  374. ->array($iterators = $field->getSrcDirectoryIterators())->isEqualTo(array(new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\closure(new \recursiveDirectoryIterator($directory)))))
  375. ->array(current($iterators)->getClosures())->isEmpty()
  376. ->if($field->addSrcDirectory($directory, $closure = function() {}))
  377. ->then
  378. ->array($iterators = $field->getSrcDirectoryIterators())->isEqualTo(array(new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\closure(new \recursiveDirectoryIterator($directory)))))
  379. ->array(current($iterators)->getClosures())->isEqualTo(array($closure))
  380. ->if($field->addSrcDirectory($otherDirectory = __DIR__ . DIRECTORY_SEPARATOR . '..', $otherClosure = function() {}))
  381. ->then
  382. ->array($iterators = $field->getSrcDirectoryIterators())->isEqualTo(array(
  383. new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\closure(new \recursiveDirectoryIterator($directory))),
  384. new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\closure(new \recursiveDirectoryIterator($otherDirectory)))
  385. )
  386. )
  387. ->array(current($iterators)->getClosures())->isEqualTo(array($closure))
  388. ->array(next($iterators)->getClosures())->isEqualTo(array($otherClosure))
  389. ->if($field->addSrcDirectory($otherDirectory, $anOtherClosure = function() {}))
  390. ->then
  391. ->array($iterators = $field->getSrcDirectoryIterators())->isEqualTo(array(
  392. new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\closure(new \recursiveDirectoryIterator($directory))),
  393. new \recursiveIteratorIterator(new atoum\iterators\filters\recursives\closure(new \recursiveDirectoryIterator($otherDirectory)))
  394. )
  395. )
  396. ->array(current($iterators)->getClosures())->isEqualTo(array($closure))
  397. ->array(next($iterators)->getClosures())->isEqualTo(array($otherClosure, $anOtherClosure))
  398. ;
  399. }
  400. public function testCleanDestinationDirectory()
  401. {
  402. $this
  403. ->if($destinationDirectory = stream::get())
  404. ->and($destinationDirectory->opendir = true)
  405. ->and($destinationDirectory->readdir[1] = $directory = stream::getSubStream($destinationDirectory))
  406. ->and($directory->opendir = true)
  407. ->and($directory->readdir[1] = $firstFile = stream::getSubStream($directory))
  408. ->and($firstFile->unlink = true)
  409. ->and($directory->readdir[2] = $secondFile = stream::getSubStream($directory))
  410. ->and($secondFile->unlink = true)
  411. ->and($directory->readdir[3] = false)
  412. ->and($destinationDirectory->readdir[2] = $emptyDirectory = stream::getSubStream($destinationDirectory))
  413. ->and($emptyDirectory->opendir = true)
  414. ->and($emptyDirectory->readdir[1] = false)
  415. ->and($destinationDirectory->readdir[3] = $otherDirectory = stream::getSubStream($destinationDirectory))
  416. ->and($otherDirectory->opendir = true)
  417. ->and($otherDirectory->readdir[1] = $otherFirstFile = stream::getSubStream($otherDirectory))
  418. ->and($otherFirstFile->unlink = true)
  419. ->and($otherDirectory->readdir[2] = $otherSecondFile = stream::getSubStream($otherDirectory))
  420. ->and($otherSecondFile->unlink = true)
  421. ->and($otherDirectory->readdir[3] = false)
  422. ->and($destinationDirectory->readdir[4] = $file = stream::getSubStream($destinationDirectory))
  423. ->and($file->unlink = true)
  424. ->and($destinationDirectory->readdir[5] = false)
  425. ->and($field = new \mock\mageekguy\atoum\report\fields\runner\coverage\html(uniqid(), (string) $destinationDirectory))
  426. ->and($field->setAdapter($adapter = new test\adapter()))
  427. ->and($adapter->rmdir = function() {})
  428. ->and($adapter->unlink = function() {})
  429. ->then
  430. ->object($field->cleanDestinationDirectory())->isIdenticalTo($field)
  431. ->adapter($adapter)
  432. ->call('unlink')->withArguments((string) $firstFile)->once()
  433. ->call('unlink')->withArguments((string) $secondFile)->once()
  434. ->call('rmdir')->withArguments((string) $directory)->once()
  435. ->call('unlink')->withArguments((string) $otherFirstFile)->once()
  436. ->call('unlink')->withArguments((string) $otherSecondFile)->once()
  437. ->call('rmdir')->withArguments((string) $otherDirectory)->once()
  438. ->call('unlink')->withArguments((string) $file)->once()
  439. ->call('rmdir')->withArguments((string) $emptyDirectory)->once()
  440. ->call('rmdir')->withArguments((string) $destinationDirectory)->never()
  441. ->if($field->getMockController()->getDestinationDirectoryIterator->throw = new \exception())
  442. ->then
  443. ->object($field->cleanDestinationDirectory())->isIdenticalTo($field)
  444. ;
  445. }
  446. public function testSetRootUrl()
  447. {
  448. $this
  449. ->if($field = new testedClass(uniqid(), uniqid(), uniqid()))
  450. ->then
  451. ->object($field->setRootUrl($rootUrl = uniqid()))->isIdenticalTo($field)
  452. ->string($field->getRootUrl())->isIdenticalTo($rootUrl)
  453. ->object($field->setRootUrl($rootUrl = rand(1, PHP_INT_MAX)))->isIdenticalTo($field)
  454. ->string($field->getRootUrl())->isIdenticalTo((string) $rootUrl)
  455. ->object($field->setRootUrl(($rootUrl = uniqid()) . '/'))->isIdenticalTo($field)
  456. ->string($field->getRootUrl())->isIdenticalTo($rootUrl . '/')
  457. ;
  458. }
  459. public function testHandleEvent()
  460. {
  461. $this
  462. ->if($field = new testedClass(uniqid(), uniqid()))
  463. ->then
  464. ->boolean($field->handleEvent(atoum\runner::runStart, new atoum\runner()))->isFalse()
  465. ->variable($field->getCoverage())->isNull()
  466. ->boolean($field->handleEvent(atoum\runner::runStop, $runner = new atoum\runner()))->isTrue()
  467. ->object($field->getCoverage())->isIdenticalTo($runner->getScore()->getCoverage())
  468. ;
  469. }
  470. public function testSetReflectionClassInjector()
  471. {
  472. $this
  473. ->if($field = new testedClass(uniqid(), uniqid(), uniqid()))
  474. ->and($reflectionClassController = new mock\controller())
  475. ->and($reflectionClassController->__construct = function() {})
  476. ->and($reflectionClass = new \mock\reflectionClass(uniqid(), $reflectionClassController))
  477. ->then
  478. ->object($field->setReflectionClassInjector(function($class) use ($reflectionClass) { return $reflectionClass; }))->isIdenticalTo($field)
  479. ->object($field->getReflectionClass(uniqid()))->isIdenticalTo($reflectionClass)
  480. ->exception(function() use ($field) {
  481. $field->setReflectionClassInjector(function() {});
  482. }
  483. )
  484. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  485. ->hasMessage('Reflection class injector must take one argument')
  486. ;
  487. }
  488. public function testGetReflectionClass()
  489. {
  490. $this
  491. ->if($field = new testedClass(uniqid(), uniqid(), uniqid()))
  492. ->then
  493. ->object($field->getReflectionClass(__CLASS__))->isInstanceOf('reflectionClass')
  494. ->string($field->getReflectionClass(__CLASS__)->getName())->isEqualTo(__CLASS__)
  495. ->if($field->setReflectionClassInjector(function($class) {}))
  496. ->then
  497. ->exception(function() use ($field) {
  498. $field->getReflectionClass(uniqid());
  499. }
  500. )
  501. ->isInstanceOf('mageekguy\atoum\exceptions\runtime\unexpectedValue')
  502. ->hasMessage('Reflection class injector must return a \reflectionClass instance')
  503. ;
  504. }
  505. }