PageRenderTime 31ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/units/classes/score/coverage.php

http://github.com/mageekguy/atoum
PHP | 1373 lines | 1343 code | 30 blank | 0 comment | 0 complexity | 6a5f93109230822855b38cc84a57e3f3 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\score;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\mock,
  6. mageekguy\atoum\score,
  7. mageekguy\atoum\score\coverage as testedClass
  8. ;
  9. require_once __DIR__ . '/../../runner.php';
  10. class coverage extends atoum\test
  11. {
  12. public function testClass()
  13. {
  14. $this->testedClass
  15. ->hasInterface('countable')
  16. ->hasInterface('serializable')
  17. ;
  18. }
  19. public function test__construct()
  20. {
  21. $this
  22. ->if($coverage = new testedClass())
  23. ->then
  24. ->variable($coverage->getValue())->isNull()
  25. ->array($coverage->getMethods())->isEmpty()
  26. ->object($coverage->getAdapter())->isEqualTo(new atoum\adapter())
  27. ->object($defaultReflectionClassFactory = $coverage->getReflectionClassFactory())->isInstanceOf('closure')
  28. ->object($defaultReflectionClassFactory($this))->isEqualTo(new \reflectionClass($this))
  29. ->if($coverage = new testedClass($adapter = new atoum\adapter(), $reflectionClassFactory = function() {}))
  30. ->then
  31. ->variable($coverage->getValue())->isNull()
  32. ->array($coverage->getMethods())->isEmpty()
  33. ->object($coverage->getAdapter())->isIdenticalTo($adapter)
  34. ->object($coverage->getReflectionClassFactory())->isIdenticalTo($reflectionClassFactory)
  35. ;
  36. }
  37. public function testSetAdapter()
  38. {
  39. $this
  40. ->if($coverage = new testedClass())
  41. ->then
  42. ->object($coverage->setAdapter($adapter = new atoum\adapter()))->isIdenticalTo($coverage)
  43. ->object($coverage->getAdapter())->isIdenticalTo($adapter)
  44. ->object($coverage->setAdapter())->isIdenticalTo($coverage)
  45. ->object($coverage->getAdapter())
  46. ->isInstanceOf('mageekguy\atoum\adapter')
  47. ->isNotIdenticalTo($adapter)
  48. ;
  49. }
  50. public function testSetReflectionClassFactory()
  51. {
  52. $this
  53. ->if($coverage = new testedClass())
  54. ->then
  55. ->object($coverage->setReflectionClassFactory($reflectionClassFactory = function() {}))->isIdenticalTo($coverage)
  56. ->object($coverage->getReflectionClassFactory())->isIdenticalTo($reflectionClassFactory)
  57. ->object($coverage->setReflectionClassFactory())->isIdenticalTo($coverage)
  58. ->object($defaultReflectionClassFactory = $coverage->getReflectionClassFactory())
  59. ->isInstanceOf('closure')
  60. ->isNotIdenticalTo($reflectionClassFactory)
  61. ->object($defaultReflectionClassFactory($this))->isEqualTo(new \reflectionClass($this))
  62. ;
  63. }
  64. public function testAddXdebugDataForTest()
  65. {
  66. $this
  67. ->if($coverage = new testedClass())
  68. ->then
  69. ->object($coverage->addXdebugDataForTest($this, array()))->isIdenticalTo($coverage)
  70. ->array($coverage->getClasses())->isEqualTo(
  71. array($this->getTestedClassName() => $this->getTestedClassPath())
  72. )
  73. ->array($coverage->getMethods())->isEqualTo(
  74. array($this->getTestedClassName() => array())
  75. )
  76. ->if($classController = new mock\controller())
  77. ->and($classController->disableMethodChecking())
  78. ->and($classController->__construct = function() {})
  79. ->and($classController->getName = function() use (& $className) { return $className; })
  80. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  81. ->and($classController->getTraits = array())
  82. ->and($classController->getStartLine = 1)
  83. ->and($classController->getEndLine = 12)
  84. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  85. ->and($methodController = new mock\controller())
  86. ->and($methodController->__construct = function() {})
  87. ->and($methodController->isAbstract = false)
  88. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  89. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  90. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  91. ->and($methodController->getStartLine = 6)
  92. ->and($methodController->getEndLine = 8)
  93. ->and($methodController->getFileName = $classFile)
  94. ->and($classController->getMethods = array($method = new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  95. ->and($classDirectory = uniqid())
  96. ->and($classFile = $classDirectory . DIRECTORY_SEPARATOR . uniqid())
  97. ->and($className = uniqid())
  98. ->and($methodName = uniqid())
  99. ->and($xdebugData = array(
  100. $classFile =>
  101. array(
  102. 5 => -1,
  103. 6 => 1,
  104. 7 => -1,
  105. 8 => -2,
  106. 9 => -1
  107. ),
  108. uniqid() =>
  109. array(
  110. 5 => 2,
  111. 6 => 3,
  112. 7 => 4,
  113. 8 => 3,
  114. 9 => 2
  115. )
  116. )
  117. )
  118. ->and($reflectionClassFactory = function() use ($class) { return $class; })
  119. ->and($coverage->setReflectionClassFactory($reflectionClassFactory))
  120. ->then
  121. ->object($coverage->addXdebugDataForTest($this, $xdebugData))->isIdenticalTo($coverage)
  122. ->array($coverage->getMethods())->isEqualTo(array(
  123. $this->getTestedClassName() => array(),
  124. $className => array(
  125. $methodName => array(
  126. 6 => 1,
  127. 7 => -1,
  128. 8 => -2
  129. )
  130. )
  131. )
  132. )
  133. ->array($coverage->getMethods())->isEqualTo(array(
  134. $this->getTestedClassName() => array(),
  135. $className => array(
  136. $methodName => array(
  137. 6 => 1,
  138. 7 => -1,
  139. 8 => -2
  140. )
  141. )
  142. )
  143. )
  144. ->object($coverage->addXdebugDataForTest($this, $xdebugData))->isIdenticalTo($coverage)
  145. ->array($coverage->getMethods())->isEqualTo(array(
  146. $this->getTestedClassName() => array(),
  147. $className => array(
  148. $methodName => array(
  149. 6 => 1,
  150. 7 => -1,
  151. 8 => -2
  152. )
  153. )
  154. )
  155. )
  156. ->if($class->getMockController()->getName = get_class($class))
  157. ->and($coverage = new testedClass())
  158. ->and($coverage->setReflectionClassFactory($reflectionClassFactory))
  159. ->and($coverage->excludeClass(get_class($class)))
  160. ->then
  161. ->object($coverage->addXdebugDataForTest($this, array()))->isIdenticalTo($coverage)
  162. ->array($coverage->getClasses())->isEmpty()
  163. ->array($coverage->getMethods())->isEmpty()
  164. ->object($coverage->addXdebugDataForTest($this, $xdebugData))->isIdenticalTo($coverage)
  165. ->array($coverage->getClasses())->isEmpty()
  166. ->array($coverage->getMethods())->isEmpty()
  167. ->and($coverage = new testedClass())
  168. ->and($coverage->setReflectionClassFactory($reflectionClassFactory))
  169. ->and($coverage->excludeDirectory($classDirectory))
  170. ->then
  171. ->object($coverage->addXdebugDataForTest($this, array()))->isIdenticalTo($coverage)
  172. ->array($coverage->getClasses())->isEmpty()
  173. ->array($coverage->getMethods())->isEmpty()
  174. ->object($coverage->addXdebugDataForTest($this, $xdebugData))->isIdenticalTo($coverage)
  175. ->array($coverage->getClasses())->isEmpty()
  176. ->array($coverage->getMethods())->isEmpty()
  177. ;
  178. }
  179. public function testReset()
  180. {
  181. $this
  182. ->if($coverage = new testedClass())
  183. ->then
  184. ->array($coverage->getClasses())->isEmpty()
  185. ->array($coverage->getMethods())->isEmpty()
  186. ->array($coverage->getExcludedClasses())->isEmpty()
  187. ->array($coverage->getExcludedNamespaces())->isEmpty()
  188. ->array($coverage->getExcludedDirectories())->isEmpty()
  189. ->object($coverage->reset())->isIdenticalTo($coverage)
  190. ->array($coverage->getClasses())->isEmpty()
  191. ->array($coverage->getMethods())->isEmpty()
  192. ->array($coverage->getExcludedClasses())->isEmpty()
  193. ->array($coverage->getExcludedNamespaces())->isEmpty()
  194. ->array($coverage->getExcludedDirectories())->isEmpty()
  195. ->if($classController = new mock\controller())
  196. ->and($classController->disableMethodChecking())
  197. ->and($classController->__construct = function() {})
  198. ->and($classController->getName = function() use (& $className) { return $className; })
  199. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  200. ->and($classController->getTraits = array())
  201. ->and($classController->getStartLine = 1)
  202. ->and($classController->getEndLine = 12)
  203. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  204. ->and($methodController = new mock\controller())
  205. ->and($methodController->__construct = function() {})
  206. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  207. ->and($methodController->isAbstract = false)
  208. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  209. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  210. ->and($methodController->getStartLine = 6)
  211. ->and($methodController->getEndLine = 8)
  212. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  213. ->and($classFile = uniqid())
  214. ->and($className = uniqid())
  215. ->and($methodName = uniqid())
  216. ->and($xdebugData = array(
  217. $classFile =>
  218. array(
  219. 5 => 1,
  220. 6 => 2,
  221. 7 => 3,
  222. 8 => 2,
  223. 9 => 1
  224. ),
  225. uniqid() =>
  226. array(
  227. 5 => 2,
  228. 6 => 3,
  229. 7 => 4,
  230. 8 => 3,
  231. 9 => 2
  232. )
  233. )
  234. )
  235. ->and($coverage = new testedClass())
  236. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  237. ->and($coverage->addXdebugDataForTest($this, $xdebugData))
  238. ->and($coverage->excludeClass($excludedClass =uniqid()))
  239. ->and($coverage->excludeNamespace($excludedNamespace= uniqid()))
  240. ->and($coverage->excludeDirectory($excludedDirectory = uniqid()))
  241. ->then
  242. ->array($coverage->getClasses())->isNotEmpty()
  243. ->array($coverage->getMethods())->isNotEmpty()
  244. ->array($coverage->getExcludedClasses())->isNotEmpty()
  245. ->array($coverage->getExcludedNamespaces())->isNotEmpty()
  246. ->array($coverage->getExcludedDirectories())->isNotEmpty()
  247. ->object($coverage->reset())->isIdenticalTo($coverage)
  248. ->array($coverage->getClasses())->isEmpty()
  249. ->array($coverage->getMethods())->isEmpty()
  250. ->array($coverage->getExcludedClasses())->isNotEmpty()
  251. ->array($coverage->getExcludedNamespaces())->isNotEmpty()
  252. ->array($coverage->getExcludedDirectories())->isNotEmpty()
  253. ;
  254. }
  255. public function testResetExcludedMethods()
  256. {
  257. $this
  258. ->if($coverage = new testedClass())
  259. ->then
  260. ->object($coverage->resetExcludedMethods())->isIdenticalTo($coverage)
  261. ->array($coverage->getExcludedMethods())->isEmpty()
  262. ->if($coverage->excludeMethod(uniqid()))
  263. ->then
  264. ->object($coverage->resetExcludedMethods())->isIdenticalTo($coverage)
  265. ->array($coverage->getExcludedMethods())->isEmpty()
  266. ;
  267. }
  268. public function testResetExcludedClasses()
  269. {
  270. $this
  271. ->if($coverage = new testedClass())
  272. ->then
  273. ->object($coverage->resetExcludedClasses())->isIdenticalTo($coverage)
  274. ->array($coverage->getExcludedClasses())->isEmpty()
  275. ->if($coverage->excludeClass(uniqid()))
  276. ->then
  277. ->object($coverage->resetExcludedClasses())->isIdenticalTo($coverage)
  278. ->array($coverage->getExcludedClasses())->isEmpty()
  279. ;
  280. }
  281. public function testResetExcludedNamespaces()
  282. {
  283. $this
  284. ->if($coverage = new testedClass())
  285. ->then
  286. ->object($coverage->resetExcludedNamespaces())->isIdenticalTo($coverage)
  287. ->array($coverage->getExcludedNamespaces())->isEmpty()
  288. ->if($coverage->excludeNamespace(uniqid()))
  289. ->then
  290. ->object($coverage->resetExcludedNamespaces())->isIdenticalTo($coverage)
  291. ->array($coverage->getExcludedNamespaces())->isEmpty()
  292. ;
  293. }
  294. public function testResetExcludedDirectories()
  295. {
  296. $this
  297. ->if($coverage = new testedClass())
  298. ->then
  299. ->object($coverage->resetExcludedDirectories())->isIdenticalTo($coverage)
  300. ->array($coverage->getExcludedDirectories())->isEmpty()
  301. ->if($coverage->excludeDirectory(uniqid()))
  302. ->then
  303. ->object($coverage->resetExcludedDirectories())->isIdenticalTo($coverage)
  304. ->array($coverage->getExcludedDirectories())->isEmpty()
  305. ;
  306. }
  307. public function testMerge()
  308. {
  309. $this
  310. ->if($classController = new mock\controller())
  311. ->and($classController->disableMethodChecking())
  312. ->and($classController->__construct = function() {})
  313. ->and($classController->getName = function() use (& $className) { return $className; })
  314. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  315. ->and($classController->getTraits = array())
  316. ->and($classController->getStartLine = 1)
  317. ->and($classController->getEndLine = 12)
  318. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  319. ->and($methodController = new mock\controller())
  320. ->and($methodController->__construct = function() {})
  321. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  322. ->and($methodController->isAbstract = false)
  323. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  324. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  325. ->and($methodController->getStartLine = 6)
  326. ->and($methodController->getEndLine = 8)
  327. ->and($method = new \mock\reflectionMethod(uniqid(), uniqid(), $methodController))
  328. ->and($classController->getMethod = function() use ($method) { return $method; })
  329. ->and($classController->getMethods = array($method))
  330. ->and($classFile = uniqid())
  331. ->and($className = uniqid())
  332. ->and($methodName = uniqid())
  333. ->and($xdebugData = array(
  334. $classFile =>
  335. array(
  336. 5 => -2,
  337. 6 => -1,
  338. 7 => 1,
  339. 8 => -2,
  340. 9 =>-2
  341. ),
  342. uniqid() =>
  343. array(
  344. 5 => 2,
  345. 6 => 3,
  346. 7 => 4,
  347. 8 => 3,
  348. 9 => 2
  349. )
  350. )
  351. )
  352. ->and($coverage = new testedClass())
  353. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  354. ->then
  355. ->object($coverage->merge($coverage))->isIdenticalTo($coverage)
  356. ->array($coverage->getClasses())->isEmpty()
  357. ->array($coverage->getMethods())->isEmpty()
  358. ->if($otherCoverage = new testedClass())
  359. ->then
  360. ->object($coverage->merge($otherCoverage))->isIdenticalTo($coverage)
  361. ->array($coverage->getClasses())->isEmpty()
  362. ->array($coverage->getMethods())->isEmpty()
  363. ->if($coverage->addXdebugDataForTest($this, $xdebugData))
  364. ->then
  365. ->object($coverage->merge($otherCoverage))->isIdenticalTo($coverage)
  366. ->array($coverage->getClasses())->isEqualTo(array($className => $classFile))
  367. ->array($coverage->getMethods())->isEqualTo(array(
  368. $className => array(
  369. $methodName => array(
  370. 6 => -1,
  371. 7 => 1,
  372. 8 => -2
  373. )
  374. )
  375. )
  376. )
  377. ->object($coverage->merge($coverage))->isIdenticalTo($coverage)
  378. ->array($coverage->getClasses())->isEqualTo(array($className => $classFile))
  379. ->array($coverage->getMethods())->isEqualTo(array(
  380. $className => array(
  381. $methodName => array(
  382. 6 => -1,
  383. 7 => 1,
  384. 8 => -2
  385. )
  386. )
  387. )
  388. )
  389. ->if($otherClassController = new mock\controller())
  390. ->and($otherClassController->disableMethodChecking())
  391. ->and($otherClassController->__construct = function() {})
  392. ->and($otherClassController->getName = function() use (& $otherClassName) { return $otherClassName; })
  393. ->and($otherClassController->getFileName = function() use (& $otherClassFile) { return $otherClassFile; })
  394. ->and($otherClassController->getTraits = array())
  395. ->and($otherClassController->getStartLine = 1)
  396. ->and($otherClassController->getEndLine = 12)
  397. ->and($otherClass = new \mock\reflectionClass($class, $otherClassController))
  398. ->and($otherMethodController = new mock\controller())
  399. ->and($otherMethodController->__construct = function() {})
  400. ->and($otherMethodController->getName = function() use (& $otherMethodName) { return $otherMethodName; })
  401. ->and($otherMethodController->isAbstract = false)
  402. ->and($otherMethodController->getFileName = function() use (& $otherClassFile) { return $otherClassFile; })
  403. ->and($otherMethodController->getDeclaringClass = function() use ($otherClass) { return $otherClass; })
  404. ->and($otherMethodController->getStartLine = 5)
  405. ->and($otherMethodController->getEndLine = 9)
  406. ->and($otherClassController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $otherMethodController)))
  407. ->and($otherClassFile = uniqid())
  408. ->and($otherClassName = uniqid())
  409. ->and($otherMethodName = uniqid())
  410. ->and($otherXdebugData = array(
  411. $otherClassFile =>
  412. array(
  413. 1 => -2,
  414. 2 => -1,
  415. 3 => 1,
  416. 4 => 1,
  417. 5 => -1,
  418. 6 => 1,
  419. 7 => 1,
  420. 8 => -1,
  421. 9 => -2,
  422. 10 => 1
  423. ),
  424. uniqid() =>
  425. array(
  426. 500 => 200,
  427. 600 => 300,
  428. 700 => 400,
  429. 800 => 300,
  430. 900 => 200
  431. )
  432. )
  433. )
  434. ->and($otherCoverage->setReflectionClassFactory(function() use ($otherClass) { return $otherClass; }))
  435. ->then
  436. ->object($coverage->merge($otherCoverage->addXdebugDataForTest($this, $otherXdebugData)))->isIdenticalTo($coverage)
  437. ->array($coverage->getClasses())->isEqualTo(array(
  438. $className => $classFile,
  439. $otherClassName => $otherClassFile
  440. )
  441. )
  442. ->array($coverage->getMethods())->isEqualTo(array(
  443. $className => array(
  444. $methodName => array(
  445. 6 => -1,
  446. 7 => 1,
  447. 8 =>-2
  448. )
  449. ),
  450. $otherClassName => array(
  451. $otherMethodName => array(
  452. 5 => -1,
  453. 6 => 1,
  454. 7 => 1,
  455. 8 => -1,
  456. 9 => -2
  457. )
  458. )
  459. )
  460. )
  461. ->if($classController = new mock\controller())
  462. ->and($classController->disableMethodChecking())
  463. ->and($classController->__construct = function() {})
  464. ->and($classController->getName = function() use (& $className) { return $className; })
  465. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  466. ->and($classController->getTraits = array())
  467. ->and($classController->getStartLine = 1)
  468. ->and($classController->getEndLine = 12)
  469. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  470. ->and($methodController = new mock\controller())
  471. ->and($methodController->__construct = function() {})
  472. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  473. ->and($methodController->isAbstract = false)
  474. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  475. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  476. ->and($methodController->getStartLine = 6)
  477. ->and($methodController->getEndLine = 8)
  478. ->and($method = new \mock\reflectionMethod(uniqid(), uniqid(), $methodController))
  479. ->and($classController->getMethod = function() use ($method) { return $method; })
  480. ->and($classController->getMethods = array($method))
  481. ->and($classFile = uniqid())
  482. ->and($className = uniqid())
  483. ->and($methodName = uniqid())
  484. ->and($xdebugData = array(
  485. $classFile =>
  486. array(
  487. 5 => -2,
  488. 6 => -1,
  489. 7 => 1,
  490. 8 => -2,
  491. 9 =>-2
  492. ),
  493. uniqid() =>
  494. array(
  495. 5 => 2,
  496. 6 => 3,
  497. 7 => 4,
  498. 8 => 3,
  499. 9 => 2
  500. )
  501. )
  502. )
  503. ->and($coverage = new testedClass())
  504. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  505. ->and($coverage->excludeClass($className))
  506. ->and($otherCoverage = new testedClass())
  507. ->and($otherCoverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  508. ->and($otherCoverage->addXdebugDataForTest($this, $xdebugData))
  509. ->then
  510. ->array($otherCoverage->getClasses())->isNotEmpty()
  511. ->array($otherCoverage->getMethods())->isNotEmpty()
  512. ->object($coverage->merge($otherCoverage))->isIdenticalTo($coverage)
  513. ->array($coverage->getClasses())->isEmpty()
  514. ->array($coverage->getMethods())->isEmpty()
  515. ;
  516. }
  517. public function testCount()
  518. {
  519. $this
  520. ->if($coverage = new testedClass())
  521. ->then
  522. ->sizeOf($coverage)->isZero()
  523. ->if($classController = new mock\controller())
  524. ->and($classController->disableMethodChecking())
  525. ->and($classController->__construct = function() {})
  526. ->and($classController->getName = function() use (& $className) { return $className; })
  527. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  528. ->and($classController->getTraits = array())
  529. ->and($classController->getStartLine = 1)
  530. ->and($classController->getEndLine = 12)
  531. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  532. ->and($methodController = new mock\controller())
  533. ->and($methodController->__construct = function() {})
  534. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  535. ->and($methodController->isAbstract = false)
  536. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  537. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  538. ->and($methodController->getStartLine = 6)
  539. ->and($methodController->getEndLine = 8)
  540. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  541. ->and($classFile = uniqid())
  542. ->and($className = uniqid())
  543. ->and($methodName = uniqid())
  544. ->and($xdebugData = array(
  545. $classFile =>
  546. array(
  547. 5 => 1,
  548. 6 => 2,
  549. 7 => 3,
  550. 8 => 2,
  551. 9 => 1
  552. ),
  553. uniqid() =>
  554. array(
  555. 5 => 2,
  556. 6 => 3,
  557. 7 => 4,
  558. 8 => 3,
  559. 9 => 2
  560. )
  561. )
  562. )
  563. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  564. ->then
  565. ->sizeOf($coverage->addXdebugDataForTest($this, $xdebugData))->isEqualTo(1)
  566. ;
  567. }
  568. public function testGetClasses()
  569. {
  570. $this
  571. ->if($classController = new mock\controller())
  572. ->and($classController->disableMethodChecking())
  573. ->and($classController->__construct = function() {})
  574. ->and($classController->getName = function() use (& $className) { return $className; })
  575. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  576. ->and($classController->getTraits = array())
  577. ->and($classController->getStartLine = 1)
  578. ->and($classController->getEndLine = 12)
  579. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  580. ->and($methodController = new mock\controller())
  581. ->and($methodController->__construct = function() {})
  582. ->and($methodController->getName = function() { return uniqid(); })
  583. ->and($methodController->isAbstract = false)
  584. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  585. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  586. ->and($methodController->getStartLine = 4)
  587. ->and($methodController->getEndLine = 8)
  588. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  589. ->and($classFile = uniqid())
  590. ->and($className = uniqid())
  591. ->and($xdebugData = array(
  592. $classFile =>
  593. array(
  594. 3 => -2,
  595. 4 => -1,
  596. 5 => -1,
  597. 6 => -1,
  598. 7 => -1,
  599. 8 => -2,
  600. 9 => -2
  601. )
  602. )
  603. )
  604. ->and($coverage = new testedClass())
  605. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  606. ->and($coverage->addXdebugDataForTest($this, $xdebugData))
  607. ->then
  608. ->array($coverage->getClasses())->isEqualTo(array($className => $classFile))
  609. ;
  610. }
  611. public function testGetValue()
  612. {
  613. $this
  614. ->if($classController = new mock\controller())
  615. ->and($classController->disableMethodChecking())
  616. ->and($classController->__construct = function() {})
  617. ->and($classController->getName = function() use (& $className) { return $className; })
  618. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  619. ->and($classController->getTraits = array())
  620. ->and($classController->getStartLine = 1)
  621. ->and($classController->getEndLine = 12)
  622. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  623. ->and($methodController = new mock\controller())
  624. ->and($methodController->__construct = function() {})
  625. ->and($methodController->getName = function() { return uniqid(); })
  626. ->and($methodController->isAbstract = false)
  627. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  628. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  629. ->and($methodController->getStartLine = 4)
  630. ->and($methodController->getEndLine = 8)
  631. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  632. ->and($classFile = uniqid())
  633. ->and($className = uniqid())
  634. ->and($xdebugData = array(
  635. $classFile =>
  636. array(
  637. 3 => -2,
  638. 4 => -1,
  639. 5 => -1,
  640. 6 => -1,
  641. 7 => -1,
  642. 8 => -2,
  643. 9 => -2
  644. ),
  645. uniqid() =>
  646. array(
  647. 5 => 2,
  648. 6 => 3,
  649. 7 => 4,
  650. 8 => 3,
  651. 9 => 2
  652. )
  653. )
  654. )
  655. ->and($coverage = new testedClass())
  656. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  657. ->and($coverage->addXdebugDataForTest($this, $xdebugData))
  658. ->then
  659. ->float($coverage->getValue())->isEqualTo(0.0)
  660. ->if($xdebugData = array(
  661. $classFile =>
  662. array(
  663. 3 => -2,
  664. 4 => 1,
  665. 5 => -1,
  666. 6 => -1,
  667. 7 => -1,
  668. 8 => -2,
  669. 9 => -1
  670. ),
  671. uniqid() =>
  672. array(
  673. 5 => 2,
  674. 6 => 3,
  675. 7 => 4,
  676. 8 => 3,
  677. 9 => 2
  678. )
  679. )
  680. )
  681. ->and($coverage->reset()->addXdebugDataForTest($this, $xdebugData))
  682. ->then
  683. ->float($coverage->getValue())->isEqualTo(1 / 4)
  684. ->if($xdebugData = array(
  685. $classFile =>
  686. array(
  687. 3 => -2,
  688. 4 => 1,
  689. 5 => -1,
  690. 6 => -1,
  691. 7 => 1,
  692. 8 => -2,
  693. 9 => -1
  694. ),
  695. uniqid() =>
  696. array(
  697. 5 => 2,
  698. 6 => 3,
  699. 7 => 4,
  700. 8 => 3,
  701. 9 => 2
  702. )
  703. )
  704. )
  705. ->and($coverage->reset()->addXdebugDataForTest($this, $xdebugData))
  706. ->then
  707. ->float($coverage->getValue())->isEqualTo(2 / 4)
  708. ->if($xdebugData = array(
  709. $classFile =>
  710. array(
  711. 3 => -2,
  712. 4 => 1,
  713. 5 => 1,
  714. 6 => 1,
  715. 7 => 1,
  716. 8 => -2,
  717. 9 => -1
  718. ),
  719. uniqid() =>
  720. array(
  721. 5 => 2,
  722. 6 => 3,
  723. 7 => 4,
  724. 8 => 3,
  725. 9 => 2
  726. )
  727. )
  728. )
  729. ->and($coverage->reset()->addXdebugDataForTest($this, $xdebugData))
  730. ->then
  731. ->float($coverage->getValue())->isEqualTo(1.0)
  732. ;
  733. }
  734. public function testGetValueForClass()
  735. {
  736. $this
  737. ->if($coverage = new testedClass())
  738. ->then
  739. ->variable($coverage->getValueForClass(uniqid()))->isNull()
  740. ->if($classController = new mock\controller())
  741. ->and($classController->disableMethodChecking())
  742. ->and($classController->__construct = function() {})
  743. ->and($classController->getName = function() use (& $className) { return $className; })
  744. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  745. ->and($classController->getTraits = array())
  746. ->and($classController->getStartLine = 1)
  747. ->and($classController->getEndLine = 12)
  748. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  749. ->and($methodController = new mock\controller())
  750. ->and($methodController->__construct = function() {})
  751. ->and($methodController->getName = function() { return uniqid(); })
  752. ->and($methodController->isAbstract = false)
  753. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  754. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  755. ->and($methodController->getStartLine = 4)
  756. ->and($methodController->getEndLine = 8)
  757. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  758. ->and($classFile = uniqid())
  759. ->and($className = uniqid())
  760. ->and($xdebugData = array(
  761. $classFile =>
  762. array(
  763. 3 => -2,
  764. 4 => -1,
  765. 5 => -1,
  766. 6 => -1,
  767. 7 => -1,
  768. 8 => -2,
  769. 9 => -2
  770. ),
  771. uniqid() =>
  772. array(
  773. 5 => 2,
  774. 6 => 3,
  775. 7 => 4,
  776. 8 => 3,
  777. 9 => 2
  778. )
  779. )
  780. )
  781. ->and($coverage = new testedClass())
  782. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  783. ->and($coverage->addXdebugDataForTest($this, $xdebugData))
  784. ->then
  785. ->variable($coverage->getValueForClass(uniqid()))->isNull()
  786. ->float($coverage->getValueForClass($className))->isEqualTo(0.0)
  787. ->if($xdebugData = array(
  788. $classFile =>
  789. array(
  790. 3 => -2,
  791. 4 => 1,
  792. 5 => -1,
  793. 6 => -1,
  794. 7 => -1,
  795. 8 => -2,
  796. 9 => -1
  797. ),
  798. uniqid() =>
  799. array(
  800. 5 => 2,
  801. 6 => 3,
  802. 7 => 4,
  803. 8 => 3,
  804. 9 => 2
  805. )
  806. )
  807. )
  808. ->and($coverage->reset()->addXdebugDataForTest($this, $xdebugData))
  809. ->then
  810. ->variable($coverage->getValueForClass(uniqid()))->isNull()
  811. ->float($coverage->getValueForClass($className))->isEqualTo(1 / 4)
  812. ->if($xdebugData = array(
  813. $classFile =>
  814. array(
  815. 3 => -2,
  816. 4 => 1,
  817. 5 => -1,
  818. 6 => -1,
  819. 7 => 1,
  820. 8 => -2,
  821. 9 => -1
  822. ),
  823. uniqid() =>
  824. array(
  825. 5 => 2,
  826. 6 => 3,
  827. 7 => 4,
  828. 8 => 3,
  829. 9 => 2
  830. )
  831. )
  832. )
  833. ->and($coverage->reset()->addXdebugDataForTest($this, $xdebugData))
  834. ->then
  835. ->variable($coverage->getValueForClass(uniqid()))->isNull()
  836. ->float($coverage->getValueForClass($className))->isEqualTo(2 / 4)
  837. ->if($xdebugData = array(
  838. $classFile =>
  839. array(
  840. 3 => -2,
  841. 4 => 1,
  842. 5 => 1,
  843. 6 => 1,
  844. 7 => 1,
  845. 8 => -2,
  846. 9 => -1
  847. ),
  848. uniqid() =>
  849. array(
  850. 5 => 2,
  851. 6 => 3,
  852. 7 => 4,
  853. 8 => 3,
  854. 9 => 2
  855. )
  856. )
  857. )
  858. ->and($coverage->reset()->addXdebugDataForTest($this, $xdebugData))
  859. ->then
  860. ->variable($coverage->getValueForClass(uniqid()))->isNull()
  861. ->float($coverage->getValueForClass($className))->isEqualTo(1.0)
  862. ;
  863. }
  864. public function testGetCoverageForClass()
  865. {
  866. $this
  867. ->if($coverage = new testedClass())
  868. ->then
  869. ->array($coverage->getCoverageForClass(uniqid()))->isEmpty()
  870. ->if($classController = new mock\controller())
  871. ->and($classController->disableMethodChecking())
  872. ->and($classController->__construct = function() {})
  873. ->and($classController->getName = function() use (& $className) { return $className; })
  874. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  875. ->and($classController->getTraits = array())
  876. ->and($classController->getStartLine = 1)
  877. ->and($classController->getEndLine = 12)
  878. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  879. ->and($methodController = new mock\controller())
  880. ->and($methodController->__construct = function() {})
  881. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  882. ->and($methodController->isAbstract = false)
  883. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  884. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  885. ->and($methodController->getStartLine = 4)
  886. ->and($methodController->getEndLine = 8)
  887. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  888. ->and($classFile = uniqid())
  889. ->and($className = uniqid())
  890. ->and($methodName = uniqid())
  891. ->and($xdebugData = array(
  892. $classFile =>
  893. array(
  894. 3 => -2,
  895. 4 => 1,
  896. 5 => -1,
  897. 6 => -1,
  898. 7 => -1,
  899. 8 => -2,
  900. 9 => -1
  901. ),
  902. uniqid() =>
  903. array(
  904. 5 => 2,
  905. 6 => 3,
  906. 7 => 4,
  907. 8 => 3,
  908. 9 => 2
  909. )
  910. )
  911. )
  912. ->and($expected = array(
  913. $methodName =>
  914. array(
  915. 4 => 1,
  916. 5 => -1,
  917. 6 => -1,
  918. 7 => -1,
  919. 8 => -2,
  920. )
  921. )
  922. )
  923. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  924. ->and($coverage->addXdebugDataForTest($this, $xdebugData))
  925. ->then
  926. ->array($coverage->getCoverageForClass($className))->isEqualTo($expected)
  927. ;
  928. }
  929. public function testGetNumberOfCoverableLinesInClass()
  930. {
  931. $this
  932. ->if($coverage = new testedClass())
  933. ->then
  934. ->integer($coverage->getNumberOfCoverableLinesInClass(uniqid()))->isZero()
  935. ->if($classController = new mock\controller())
  936. ->and($classController->disableMethodChecking())
  937. ->and($classController->__construct = function() {})
  938. ->and($classController->getName = function() use (& $className) { return $className; })
  939. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  940. ->and($classController->getTraits = array())
  941. ->and($classController->getStartLine = 1)
  942. ->and($classController->getEndLine = 12)
  943. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  944. ->and($methodController = new mock\controller())
  945. ->and($methodController->__construct = function() {})
  946. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  947. ->and($methodController->isAbstract = false)
  948. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  949. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  950. ->and($methodController->getStartLine = 4)
  951. ->and($methodController->getEndLine = 8)
  952. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  953. ->and($classFile = uniqid())
  954. ->and($className = uniqid())
  955. ->and($methodName = uniqid())
  956. ->and($xdebugData = array(
  957. $classFile =>
  958. array(
  959. 3 => -2,
  960. 4 => 1,
  961. 5 => -1,
  962. 6 => -1,
  963. 7 => -1,
  964. 8 => -2,
  965. 9 => -1
  966. ),
  967. uniqid() =>
  968. array(
  969. 5 => 2,
  970. 6 => 3,
  971. 7 => 4,
  972. 8 => 3,
  973. 9 => 2
  974. )
  975. )
  976. )
  977. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  978. ->and($coverage->addXdebugDataForTest($this, $xdebugData))
  979. ->then
  980. ->integer($coverage->getNumberOfCoverableLinesInClass($className))->isEqualTo(4)
  981. ;
  982. }
  983. public function testGetNumberOfCoveredLinesInClass()
  984. {
  985. $this
  986. ->if($coverage = new testedClass())
  987. ->then
  988. ->integer($coverage->getNumberOfCoveredLinesInClass(uniqid()))->isZero()
  989. ->if($classController = new mock\controller())
  990. ->and($classController->disableMethodChecking())
  991. ->and($classController->__construct = function() {})
  992. ->and($classController->getName = function() use (& $className) { return $className; })
  993. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  994. ->and($classController->getTraits = array())
  995. ->and($classController->getStartLine = 1)
  996. ->and($classController->getEndLine = 12)
  997. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  998. ->and($methodController = new mock\controller())
  999. ->and($methodController->__construct = function() {})
  1000. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  1001. ->and($methodController->isAbstract = false)
  1002. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  1003. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  1004. ->and($methodController->getStartLine = 4)
  1005. ->and($methodController->getEndLine = 8)
  1006. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  1007. ->and($classFile = uniqid())
  1008. ->and($className = uniqid())
  1009. ->and($methodName = uniqid())
  1010. ->and($xdebugData = array(
  1011. $classFile =>
  1012. array(
  1013. 3 => -2,
  1014. 4 => 1,
  1015. 5 => -1,
  1016. 6 => -1,
  1017. 7 => -1,
  1018. 8 => -2,
  1019. 9 => -1
  1020. ),
  1021. uniqid() =>
  1022. array(
  1023. 5 => 2,
  1024. 6 => 3,
  1025. 7 => 4,
  1026. 8 => 3,
  1027. 9 => 2
  1028. )
  1029. )
  1030. )
  1031. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  1032. ->and($coverage->addXdebugDataForTest($this, $xdebugData))
  1033. ->then
  1034. ->integer($coverage->getNumberOfCoveredLinesInClass($className))->isEqualTo(1)
  1035. ;
  1036. }
  1037. public function testGetValueForMethod()
  1038. {
  1039. $this
  1040. ->if($coverage = new testedClass())
  1041. ->then
  1042. ->variable($coverage->getValueForMethod(uniqid(), uniqid()))->isNull()
  1043. ->if($classController = new mock\controller())
  1044. ->and($classController->disableMethodChecking())
  1045. ->and($classController->__construct = function() {})
  1046. ->and($classController->getName = function() use (& $className) { return $className; })
  1047. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  1048. ->and($classController->getTraits = array())
  1049. ->and($classController->getStartLine = 1)
  1050. ->and($classController->getEndLine = 12)
  1051. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  1052. ->and($methodController = new mock\controller())
  1053. ->and($methodController->__construct = function() {})
  1054. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  1055. ->and($methodController->isAbstract = false)
  1056. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  1057. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  1058. ->and($methodController->getStartLine = 4)
  1059. ->and($methodController->getEndLine = 8)
  1060. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  1061. ->and($classFile = uniqid())
  1062. ->and($className = uniqid())
  1063. ->and($methodName = uniqid())
  1064. ->and($xdebugData = array(
  1065. $classFile =>
  1066. array(
  1067. 3 => -2,
  1068. 4 => -1,
  1069. 5 => -1,
  1070. 6 => -1,
  1071. 7 => -1,
  1072. 8 => -2,
  1073. 9 => -2
  1074. ),
  1075. uniqid() =>
  1076. array(
  1077. 5 => 2,
  1078. 6 => 3,
  1079. 7 => 4,
  1080. 8 => 3,
  1081. 9 => 2
  1082. )
  1083. )
  1084. )
  1085. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  1086. ->and($coverage->addXdebugDataForTest($this, $xdebugData))
  1087. ->then
  1088. ->variable($coverage->getValueForMethod(uniqid(), uniqid()))->isNull()
  1089. ->variable($coverage->getValueForMethod($className, uniqid()))->isNull()
  1090. ->float($coverage->getValueForMethod($className, $methodName))->isEqualTo(0.0)
  1091. ->if($xdebugData = array(
  1092. $classFile =>
  1093. array(
  1094. 3 => -2,
  1095. 4 => 1,
  1096. 5 => -1,
  1097. 6 => -1,
  1098. 7 => -1,
  1099. 8 => -2,
  1100. 9 => -1
  1101. ),
  1102. uniqid() =>
  1103. array(
  1104. 5 => 2,
  1105. 6 => 3,
  1106. 7 => 4,
  1107. 8 => 3,
  1108. 9 => 2
  1109. )
  1110. )
  1111. )
  1112. ->and($coverage->reset()->addXdebugDataForTest($this, $xdebugData))
  1113. ->then
  1114. ->variable($coverage->getValueForMethod(uniqid(), uniqid()))->isNull()
  1115. ->variable($coverage->getValueForMethod($className, uniqid()))->isNull()
  1116. ->float($coverage->getValueForMethod($className, $methodName))->isEqualTo(1 / 4)
  1117. ->if($xdebugData = array(
  1118. $classFile =>
  1119. array(
  1120. 3 => -2,
  1121. 4 => 1,
  1122. 5 => -1,
  1123. 6 => -1,
  1124. 7 => 1,
  1125. 8 => -2,
  1126. 9 => -1
  1127. ),
  1128. uniqid() =>
  1129. array(
  1130. 5 => 2,
  1131. 6 => 3,
  1132. 7 => 4,
  1133. 8 => 3,
  1134. 9 => 2
  1135. )
  1136. )
  1137. )
  1138. ->and($coverage->reset()->addXdebugDataForTest($this, $xdebugData))
  1139. ->then
  1140. ->variable($coverage->getValueForMethod(uniqid(), uniqid()))->isNull()
  1141. ->variable($coverage->getValueForMethod($className, uniqid()))->isNull()
  1142. ->float($coverage->getValueForMethod($className, $methodName))->isEqualTo(2 / 4)
  1143. ->if($xdebugData = array(
  1144. $classFile =>
  1145. array(
  1146. 3 => -2,
  1147. 4 => 1,
  1148. 5 => 1,
  1149. 6 => 1,
  1150. 7 => 1,
  1151. 8 => -2,
  1152. 9 => -1
  1153. ),
  1154. uniqid() =>
  1155. array(
  1156. 5 => 2,
  1157. 6 => 3,
  1158. 7 => 4,
  1159. 8 => 3,
  1160. 9 => 2
  1161. )
  1162. )
  1163. )
  1164. ->and($coverage->reset()->addXdebugDataForTest($this, $xdebugData))
  1165. ->then
  1166. ->variable($coverage->getValueForMethod(uniqid(), uniqid()))->isNull()
  1167. ->variable($coverage->getValueForMethod($className, uniqid()))->isNull()
  1168. ->float($coverage->getValueForMethod($className, $methodName))->isEqualTo(1.0)
  1169. ;
  1170. }
  1171. public function testGetCoverageForMethod()
  1172. {
  1173. $this
  1174. ->if($coverage = new testedClass())
  1175. ->then
  1176. ->array($coverage->getCoverageForClass(uniqid()))->isEmpty()
  1177. ->if($classController = new mock\controller())
  1178. ->and($classController->disableMethodChecking())
  1179. ->and($classController->__construct = function() {})
  1180. ->and($classController->getName = function() use (& $className) { return $className; })
  1181. ->and($classController->getFileName = function() use (& $classFile) { return $classFile; })
  1182. ->and($classController->getTraits = array())
  1183. ->and($classController->getStartLine = 1)
  1184. ->and($classController->getEndLine = 12)
  1185. ->and($class = new \mock\reflectionClass(uniqid(), $classController))
  1186. ->and($methodController = new mock\controller())
  1187. ->and($methodController->__construct = function() {})
  1188. ->and($methodController->getName = function() use (& $methodName) { return $methodName; })
  1189. ->and($methodController->isAbstract = false)
  1190. ->and($methodController->getFileName = function() use (& $classFile) { return $classFile; })
  1191. ->and($methodController->getDeclaringClass = function() use ($class) { return $class; })
  1192. ->and($methodController->getStartLine = 4)
  1193. ->and($methodController->getEndLine = 8)
  1194. ->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))
  1195. ->and($classFile = uniqid())
  1196. ->and($className = uniqid())
  1197. ->and($methodName = uniqid())
  1198. ->and($xdebugData = array(
  1199. $classFile =>
  1200. array(
  1201. 3 => -2,
  1202. 4 => 1,
  1203. 5 => -1,
  1204. 6 => -1,
  1205. 7 => -1,
  1206. 8 => -2,
  1207. 9 => -1
  1208. ),
  1209. uniqid() =>
  1210. array(
  1211. 5 => 2,
  1212. 6 => 3,
  1213. 7 => 4,
  1214. 8 => 3,
  1215. 9 => 2
  1216. )
  1217. )
  1218. )
  1219. ->and($expected = array(
  1220. 4 => 1,
  1221. 5 => -1,
  1222. 6 => -1,
  1223. 7 => -1,
  1224. 8 => -2,
  1225. )
  1226. )
  1227. ->and($coverage = new testedClass())
  1228. ->and($coverage->setReflectionClassFactory(function() use ($class) { return $class; }))
  1229. ->and($coverage->addXdebugDataForTest($this, $xdebugData))
  1230. ->then
  1231. ->array($coverage->getCoverageForMethod($className, $methodName))->isEqualTo($expected)
  1232. ;
  1233. }
  1234. public function testExcludeMethod()
  1235. {
  1236. $this
  1237. ->if($coverage = new testedClass())
  1238. ->then
  1239. ->object($coverage->excludeMethod($method = uniqid()))->isIdenticalTo($coverage)
  1240. ->array($coverage->getExcludedMethods())->isEqualTo(array($method))
  1241. ->object($coverage->excludeMethod($otherClass = rand(1, PHP_INT_MAX)))->isIdenticalTo($coverage)
  1242. ->array($coverage->getExcludedMethods())->isEqualTo(array($method, (string) $otherClass))
  1243. ->object($coverage->excludeMethod($method))->isIdenticalTo($coverage)
  1244. ->array($coverage->getExcludedMethods())->isEqualTo(array($method, (string) $otherClass))
  1245. ;
  1246. }
  1247. public function testExcludeClass()
  1248. {
  1249. $this
  1250. ->if($coverage = new testedClass())
  1251. ->then
  1252. ->object($coverage->excludeClass($class = uniqid()))->isIdenticalTo($coverage)
  1253. ->array($coverage->getExcludedClasses())->isEqualTo(array($class))
  1254. ->object($coverage->excludeClass($otherClass = rand(1, PHP_INT_MAX)))->isIdenticalTo($coverage)
  1255. ->array($coverage->getExcludedClasses())->isEqualTo(array($class, (string) $otherClass))
  1256. ->object($coverage->excludeClass($class))->isIdenticalTo($coverage)
  1257. ->array($coverage->getExcludedClasses())->isEqualTo(array($class, (string) $otherClass))
  1258. ;
  1259. }
  1260. public function testExcludeNamespace()
  1261. {
  1262. $this
  1263. ->if($coverage = new testedClass())
  1264. ->then
  1265. ->object($coverage->excludeNamespace($namespace = uniqid()))->isIdenticalTo($coverage)
  1266. ->array($coverage->getExcludedNamespaces())->isEqualTo(array($namespace))
  1267. ->object($coverage->excludeNamespace($otherNamespace = rand(1, PHP_INT_MAX)))->isIdenticalTo($coverage)
  1268. ->array($coverage->getExcludedNamespaces())->isEqualTo(array($namespace, (string) $otherNamespace))
  1269. ->object($coverage->excludeNamespace($namespace))->isIdenticalTo($coverage)
  1270. ->array($coverage->getExcludedNamespaces())->isEqualTo(array($namespace, (string) $otherNamespace))
  1271. ->object($coverage->excludeNamespace('\\' . ($anotherNamespace = uniqid()) . '\\'))->isIdenticalTo($coverage)
  1272. ->array($coverage->getExcludedNamespaces())->isEqualTo(array($namespace, (string) $otherNamespace, $anotherNamespace))
  1273. ;
  1274. }
  1275. public function testExcludeDirectory()
  1276. {
  1277. $this
  1278. ->if($coverage = new testedClass())
  1279. ->then
  1280. ->object($coverage->excludeDirectory($directory = uniqid()))->isIdenticalTo($coverage)
  1281. ->array($coverage->getExcludedDirectories())->isEqualTo(array($directory))
  1282. ->object($coverage->excludeDirectory($otherDirectory = rand(1, PHP_INT_MAX)))->isIdenticalTo($coverage)
  1283. ->array($coverage->getExcludedDirectories())->isEqualTo(array($directory, (string) $otherDirectory))
  1284. ->object($coverage->excludeDirectory($directory))->isIdenticalTo($coverage)
  1285. ->array($coverage->getExcludedDirectories())->isEqualTo(array($directory, (string) $otherDirectory))
  1286. ->object($coverage->excludeDirectory(($anotherDirectory = (DIRECTORY_SEPARATOR . uniqid())) . DIRECTORY_SEPARATOR))->isIdenticalTo($coverage)
  1287. ->array($coverage->getExcludedDirectories())->isEqualTo(array($directory, (string) $otherDirectory, $anotherDirectory))
  1288. ;
  1289. }
  1290. public function testIsInExcludedMethods()
  1291. {
  1292. $this
  1293. ->if($coverage = new testedClass())
  1294. ->then
  1295. ->boolean($coverage->isInExcludedMethods(uniqid()))->isFalse()
  1296. ->if($coverage->excludeMethod($method = uniqid()))
  1297. ->then
  1298. ->boolean($coverage->isInExcludedMethods(uniqid()))->isFalse()
  1299. ->boolean($coverage->isInExcludedMethods($method))->isTrue()
  1300. ->if($coverage->excludeMethod('/.+/'))
  1301. ->then
  1302. ->boolean($coverage->isInExcludedMethods(uniqid()))->isTrue()
  1303. ;
  1304. }
  1305. public function testIsInExcludedClasses()
  1306. {
  1307. $this
  1308. ->if($coverage = new testedClass())
  1309. ->then
  1310. ->boolean($coverage->isInExcludedClasses(uniqid()))->isFalse()
  1311. ->if($coverage->excludeClass($class = uniqid()))
  1312. ->then
  1313. ->boolean($coverage->isInExcludedClasses(uniqid()))->isFalse()
  1314. ->boolean($coverage->isInExcludedClasses($class))->isTrue()
  1315. ;
  1316. }
  1317. public function testIsInExcludedNamespaces()
  1318. {
  1319. $this
  1320. ->if($coverage = new testedClass())
  1321. ->then
  1322. ->boolean($coverage->isInExcludedNamespaces(uniqid()))->isFalse()
  1323. ->if($coverage->excludeNamespace($namespace = uniqid()))
  1324. ->then
  1325. ->boolean($coverage->isInExcludedNamespaces(uniqid()))->isFalse()
  1326. ->boolean($coverage->isInExcludedNamespaces($namespace . '\\' . uniqid()))->isTrue()
  1327. ;
  1328. }
  1329. public function testIsInExcludedDirectories()
  1330. {
  1331. $this
  1332. ->if($coverage = new testedClass())
  1333. ->then
  1334. ->boolean($coverage->isInExcludedDirectories(uniqid()))->isFalse()
  1335. ->if($coverage->excludeDirectory($directory = uniqid()))
  1336. ->then
  1337. ->boolean($coverage->isInExcludedDirectories(uniqid()))->isFalse()
  1338. ->boolean($coverage->isInExcludedDirectories($directory . DIRECTORY_SEPARATOR . uniqid()))->isTrue()
  1339. ->boolean($coverage->isInExcludedDirectories($directory . uniqid() . DIRECTORY_SEPARATOR . uniqid()))->isFalse()
  1340. ;
  1341. }
  1342. }