/vendor/phpunit/php-code-coverage/tests/tests/BuilderTest.php

https://gitlab.com/mdabutaleb/bitm-laravel-1 · PHP · 212 lines · 183 code · 16 blank · 13 comment · 0 complexity · 93ecfcd77b45eed9b43d300a02d98b84 MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of the php-code-coverage package.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\CodeCoverage\Report;
  11. use SebastianBergmann\CodeCoverage\TestCase;
  12. use SebastianBergmann\CodeCoverage\Node\Builder;
  13. class BuilderTest extends TestCase
  14. {
  15. protected $factory;
  16. protected function setUp()
  17. {
  18. $this->factory = new Builder;
  19. }
  20. public function testSomething()
  21. {
  22. $root = $this->getCoverageForBankAccount()->getReport();
  23. $expectedPath = rtrim(TEST_FILES_PATH, DIRECTORY_SEPARATOR);
  24. $this->assertEquals($expectedPath, $root->getName());
  25. $this->assertEquals($expectedPath, $root->getPath());
  26. $this->assertEquals(10, $root->getNumExecutableLines());
  27. $this->assertEquals(5, $root->getNumExecutedLines());
  28. $this->assertEquals(1, $root->getNumClasses());
  29. $this->assertEquals(0, $root->getNumTestedClasses());
  30. $this->assertEquals(4, $root->getNumMethods());
  31. $this->assertEquals(3, $root->getNumTestedMethods());
  32. $this->assertEquals('0.00%', $root->getTestedClassesPercent());
  33. $this->assertEquals('75.00%', $root->getTestedMethodsPercent());
  34. $this->assertEquals('50.00%', $root->getLineExecutedPercent());
  35. $this->assertEquals(0, $root->getNumFunctions());
  36. $this->assertEquals(0, $root->getNumTestedFunctions());
  37. $this->assertNull($root->getParent());
  38. $this->assertEquals([], $root->getDirectories());
  39. #$this->assertEquals(array(), $root->getFiles());
  40. #$this->assertEquals(array(), $root->getChildNodes());
  41. $this->assertEquals(
  42. [
  43. 'BankAccount' => [
  44. 'methods' => [
  45. 'getBalance' => [
  46. 'signature' => 'getBalance()',
  47. 'startLine' => 6,
  48. 'endLine' => 9,
  49. 'executableLines' => 1,
  50. 'executedLines' => 1,
  51. 'ccn' => 1,
  52. 'coverage' => 100,
  53. 'crap' => '1',
  54. 'link' => 'BankAccount.php.html#6',
  55. 'methodName' => 'getBalance',
  56. 'visibility' => 'public',
  57. ],
  58. 'setBalance' => [
  59. 'signature' => 'setBalance($balance)',
  60. 'startLine' => 11,
  61. 'endLine' => 18,
  62. 'executableLines' => 5,
  63. 'executedLines' => 0,
  64. 'ccn' => 2,
  65. 'coverage' => 0,
  66. 'crap' => 6,
  67. 'link' => 'BankAccount.php.html#11',
  68. 'methodName' => 'setBalance',
  69. 'visibility' => 'protected',
  70. ],
  71. 'depositMoney' => [
  72. 'signature' => 'depositMoney($balance)',
  73. 'startLine' => 20,
  74. 'endLine' => 25,
  75. 'executableLines' => 2,
  76. 'executedLines' => 2,
  77. 'ccn' => 1,
  78. 'coverage' => 100,
  79. 'crap' => '1',
  80. 'link' => 'BankAccount.php.html#20',
  81. 'methodName' => 'depositMoney',
  82. 'visibility' => 'public',
  83. ],
  84. 'withdrawMoney' => [
  85. 'signature' => 'withdrawMoney($balance)',
  86. 'startLine' => 27,
  87. 'endLine' => 32,
  88. 'executableLines' => 2,
  89. 'executedLines' => 2,
  90. 'ccn' => 1,
  91. 'coverage' => 100,
  92. 'crap' => '1',
  93. 'link' => 'BankAccount.php.html#27',
  94. 'methodName' => 'withdrawMoney',
  95. 'visibility' => 'public',
  96. ],
  97. ],
  98. 'startLine' => 2,
  99. 'executableLines' => 10,
  100. 'executedLines' => 5,
  101. 'ccn' => 5,
  102. 'coverage' => 50,
  103. 'crap' => '8.12',
  104. 'package' => [
  105. 'namespace' => '',
  106. 'fullPackage' => '',
  107. 'category' => '',
  108. 'package' => '',
  109. 'subpackage' => ''
  110. ],
  111. 'link' => 'BankAccount.php.html#2',
  112. 'className' => 'BankAccount'
  113. ]
  114. ],
  115. $root->getClasses()
  116. );
  117. $this->assertEquals([], $root->getFunctions());
  118. }
  119. public function testBuildDirectoryStructure()
  120. {
  121. $method = new \ReflectionMethod(
  122. Builder::class,
  123. 'buildDirectoryStructure'
  124. );
  125. $method->setAccessible(true);
  126. $this->assertEquals(
  127. [
  128. 'src' => [
  129. 'Money.php/f' => [],
  130. 'MoneyBag.php/f' => []
  131. ]
  132. ],
  133. $method->invoke(
  134. $this->factory,
  135. ['src/Money.php' => [], 'src/MoneyBag.php' => []]
  136. )
  137. );
  138. }
  139. /**
  140. * @dataProvider reducePathsProvider
  141. */
  142. public function testReducePaths($reducedPaths, $commonPath, $paths)
  143. {
  144. $method = new \ReflectionMethod(
  145. Builder::class,
  146. 'reducePaths'
  147. );
  148. $method->setAccessible(true);
  149. $_commonPath = $method->invokeArgs($this->factory, [&$paths]);
  150. $this->assertEquals($reducedPaths, $paths);
  151. $this->assertEquals($commonPath, $_commonPath);
  152. }
  153. public function reducePathsProvider()
  154. {
  155. return [
  156. [
  157. [
  158. 'Money.php' => [],
  159. 'MoneyBag.php' => []
  160. ],
  161. '/home/sb/Money',
  162. [
  163. '/home/sb/Money/Money.php' => [],
  164. '/home/sb/Money/MoneyBag.php' => []
  165. ]
  166. ],
  167. [
  168. [
  169. 'Money.php' => []
  170. ],
  171. '/home/sb/Money/',
  172. [
  173. '/home/sb/Money/Money.php' => []
  174. ]
  175. ],
  176. [
  177. [],
  178. '.',
  179. []
  180. ],
  181. [
  182. [
  183. 'Money.php' => [],
  184. 'MoneyBag.php' => [],
  185. 'Cash.phar/Cash.php' => [],
  186. ],
  187. '/home/sb/Money',
  188. [
  189. '/home/sb/Money/Money.php' => [],
  190. '/home/sb/Money/MoneyBag.php' => [],
  191. 'phar:///home/sb/Money/Cash.phar/Cash.php' => [],
  192. ],
  193. ],
  194. ];
  195. }
  196. }