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

/tests/units/classes/reports/asynchronous/clover.php

http://github.com/mageekguy/atoum
PHP | 187 lines | 175 code | 12 blank | 0 comment | 0 complexity | 12042b65cce38c91362726d5ddc42357 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\reports\asynchronous;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\score,
  6. mageekguy\atoum\mock,
  7. mageekguy\atoum\reports\asynchronous\clover as testedClass
  8. ;
  9. require_once __DIR__ . '/../../../runner.php';
  10. class clover extends atoum\test
  11. {
  12. public function beforeTestMethod($method)
  13. {
  14. $this->extension('libxml')->isLoaded();
  15. }
  16. public function testClass()
  17. {
  18. $this->testedClass->extends('mageekguy\atoum\reports\asynchronous');
  19. }
  20. public function testClassConstants()
  21. {
  22. $this
  23. ->string(testedClass::defaultTitle)->isEqualTo('atoum code coverage')
  24. ->string(testedClass::defaultPackage)->isEqualTo('atoumCodeCoverage')
  25. ->string(testedClass::lineTypeMethod)->isEqualTo('method')
  26. ->string(testedClass::lineTypeStatement)->isEqualTo('stmt')
  27. ->string(testedClass::lineTypeConditional)->isEqualTo('cond')
  28. ;
  29. }
  30. public function test__construct()
  31. {
  32. $this
  33. ->if($report = new testedClass($adapter = new atoum\test\adapter()))
  34. ->then
  35. ->array($report->getFields(atoum\runner::runStart))->isEmpty()
  36. ->object($report->getLocale())->isInstanceOf('mageekguy\atoum\locale')
  37. ->object($report->getAdapter())->isInstanceOf('mageekguy\atoum\adapter')
  38. ->array($report->getFields())->isEmpty()
  39. ->adapter($adapter)->call('extension_loaded')->withArguments('libxml')->once()
  40. ->if($adapter->extension_loaded = false)
  41. ->then
  42. ->exception(function() use ($adapter) {
  43. new testedClass($adapter);
  44. }
  45. )
  46. ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
  47. ->hasMessage('libxml PHP extension is mandatory for clover report')
  48. ;
  49. }
  50. public function testHandleEvent()
  51. {
  52. $this
  53. ->if($adapter = new atoum\test\adapter())
  54. ->if($adapter->extension_loaded = true)
  55. ->and($report = new testedClass($adapter))
  56. ->and($score = new \mock\mageekguy\atoum\score())
  57. ->and($coverage = new \mock\mageekguy\atoum\score\coverage())
  58. ->and($writer = new \mock\mageekguy\atoum\writers\file())
  59. ->and($writer->getMockController()->write = $writer)
  60. ->then
  61. ->when(function() use ($report, $writer) {
  62. $report->addWriter($writer)->handleEvent(atoum\runner::runStop, new \mageekguy\atoum\runner());
  63. })
  64. ->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->once()
  65. ->and($adapter->time = 762476400)
  66. ->and($adapter->uniqid = 'foo')
  67. ->and($observable = new \mock\mageekguy\atoum\runner())
  68. ->and($observable->getMockController()->getScore = $score)
  69. ->and($score->getMockController()->getCoverage = $coverage)
  70. ->and($coverage->getMockController()->getClasses = array())
  71. ->and($filepath = join(
  72. DIRECTORY_SEPARATOR,
  73. array(
  74. __DIR__,
  75. 'clover',
  76. 'resources',
  77. '1.xml'
  78. )
  79. ))
  80. ->and($report = new testedClass($adapter))
  81. ->then
  82. ->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)
  83. ->castToString($report)->isEqualToContentsOfFile($filepath)
  84. ->if($coverage->getMockController()->getClasses = array())
  85. ->and($classController = new mock\controller())
  86. ->and($classController->disableMethodChecking())
  87. ->and($classController->__construct = function() {})
  88. ->and($classController->getName = $className = 'bar')
  89. ->and($classController->getFileName = $classFile = 'foo/bar.php')
  90. ->and($classController->getTraits = array())
  91. ->and($classController->getStartLine = 1)
  92. ->and($classController->getEndLine = 12)
  93. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  94. ->and($methodController = new mock\controller())
  95. ->and($methodController->__construct = function() {})
  96. ->and($methodController->getName = $methodName = 'baz')
  97. ->and($methodController->isAbstract = false)
  98. ->and($methodController->getFileName = $classFile)
  99. ->and($methodController->getDeclaringClass = $class)
  100. ->and($methodController->getStartLine = 4)
  101. ->and($methodController->getEndLine = 8)
  102. ->and($classController->getMethods = array(new \mock\reflectionMethod($className, $methodName, $methodController)))
  103. ->and($coverage->getMockController()->getClasses = array(
  104. $className => $classFile,
  105. 'foo' => 'bar/foo.php'
  106. ))
  107. ->and($xdebugData = array(
  108. $classFile =>
  109. array(
  110. 3 => 1,
  111. 4 => 1,
  112. 5 => 1,
  113. 6 => 0,
  114. 7 => 1,
  115. 8 => 1,
  116. 9 => 1
  117. )
  118. ))
  119. ->and($filepath = join(
  120. DIRECTORY_SEPARATOR,
  121. array(
  122. __DIR__,
  123. 'clover',
  124. 'resources',
  125. '2.xml'
  126. )
  127. ))
  128. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  129. ->and($coverage->addXdebugDataForTest($this, $xdebugData))
  130. ->then
  131. ->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)
  132. ->castToString($report)->isEqualToContentsOfFile($filepath)
  133. ;
  134. }
  135. public function testGetTitle()
  136. {
  137. $this
  138. ->if($report = new testedClass())
  139. ->then
  140. ->string($report->getTitle())->isEqualTo(testedClass::defaultTitle)
  141. ->if($report->setTitle($title = uniqid()))
  142. ->then
  143. ->string($report->getTitle())->isEqualTo($title)
  144. ;
  145. }
  146. public function testSetTitle()
  147. {
  148. $this
  149. ->if($report = new testedClass())
  150. ->then
  151. ->object($report->setTitle($title = uniqid()))->isIdenticalTo($report)
  152. ->string($report->getTitle())->isEqualTo($title)
  153. ;
  154. }
  155. public function testGetPackage()
  156. {
  157. $this
  158. ->if($report = new testedClass())
  159. ->then
  160. ->string($report->getPackage())->isEqualTo(testedClass::defaultPackage)
  161. ->if($report->setPackage($package = uniqid()))
  162. ->then
  163. ->string($report->getPackage())->isEqualTo($package)
  164. ;
  165. }
  166. public function testSetPackage()
  167. {
  168. $this
  169. ->if($report = new testedClass())
  170. ->then
  171. ->object($report->setPackage($package = uniqid()))->isIdenticalTo($report)
  172. ->string($report->getPackage())->isEqualTo($package)
  173. ;
  174. }
  175. }