TestCase.php 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of phpunit/php-code-coverage.
  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;
  11. use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
  12. use function array_merge;
  13. use function range;
  14. use function rmdir;
  15. use function unlink;
  16. use BankAccountTest;
  17. use RecursiveDirectoryIterator;
  18. use RecursiveIteratorIterator;
  19. use SebastianBergmann\CodeCoverage\Driver\Driver;
  20. abstract class TestCase extends \PHPUnit\Framework\TestCase
  21. {
  22. protected static $TEST_TMP_PATH;
  23. public static function setUpBeforeClass(): void
  24. {
  25. self::$TEST_TMP_PATH = TEST_FILES_PATH . 'tmp';
  26. }
  27. protected function getLineCoverageXdebugDataForBankAccount()
  28. {
  29. return [
  30. RawCodeCoverageData::fromXdebugWithoutPathCoverage([
  31. TEST_FILES_PATH . 'BankAccount.php' => [
  32. 8 => 1,
  33. 9 => -2,
  34. 13 => -1,
  35. 14 => -1,
  36. 15 => -1,
  37. 16 => -1,
  38. 18 => -1,
  39. 22 => -1,
  40. 24 => -1,
  41. 25 => -2,
  42. 29 => -1,
  43. 31 => -1,
  44. 32 => -2,
  45. 33 => -2,
  46. 35 => 1,
  47. ],
  48. ]),
  49. RawCodeCoverageData::fromXdebugWithoutPathCoverage([
  50. TEST_FILES_PATH . 'BankAccount.php' => [
  51. 8 => 1,
  52. 9 => -2,
  53. 13 => 1,
  54. 14 => -1,
  55. 15 => -1,
  56. 16 => 1,
  57. 18 => -1,
  58. 29 => 1,
  59. 31 => -1,
  60. 32 => -2,
  61. 33 => -2,
  62. ],
  63. ]),
  64. RawCodeCoverageData::fromXdebugWithoutPathCoverage([
  65. TEST_FILES_PATH . 'BankAccount.php' => [
  66. 8 => 1,
  67. 9 => -2,
  68. 13 => 1,
  69. 14 => -1,
  70. 15 => -1,
  71. 16 => 1,
  72. 18 => -1,
  73. 22 => 1,
  74. 24 => -1,
  75. 25 => -2,
  76. ],
  77. ]),
  78. RawCodeCoverageData::fromXdebugWithoutPathCoverage([
  79. TEST_FILES_PATH . 'BankAccount.php' => [
  80. 8 => 1,
  81. 9 => -2,
  82. 13 => 1,
  83. 14 => 1,
  84. 15 => 1,
  85. 16 => -1,
  86. 18 => 1,
  87. 22 => 1,
  88. 24 => 1,
  89. 25 => -2,
  90. 29 => 1,
  91. 31 => 1,
  92. 32 => -2,
  93. 33 => -2,
  94. ],
  95. ]),
  96. ];
  97. }
  98. protected function getPathCoverageXdebugDataForBankAccount()
  99. {
  100. return [
  101. RawCodeCoverageData::fromXdebugWithPathCoverage([
  102. TEST_FILES_PATH . 'BankAccount.php' => [
  103. 'lines' => [
  104. 8 => 1,
  105. 9 => -2,
  106. 13 => -1,
  107. 14 => -1,
  108. 15 => -1,
  109. 16 => -1,
  110. 18 => -1,
  111. 22 => -1,
  112. 24 => -1,
  113. 25 => -2,
  114. 29 => -1,
  115. 31 => -1,
  116. 32 => -2,
  117. ],
  118. 'functions' => [
  119. 'BankAccount->depositMoney' => [
  120. 'branches' => [
  121. 0 => [
  122. 'op_start' => 0,
  123. 'op_end' => 14,
  124. 'line_start' => 20,
  125. 'line_end' => 25,
  126. 'hit' => 0,
  127. 'out' => [
  128. ],
  129. 'out_hit' => [
  130. ],
  131. ],
  132. ],
  133. 'paths' => [
  134. 0 => [
  135. 'path' => [
  136. 0 => 0,
  137. ],
  138. 'hit' => 0,
  139. ],
  140. ],
  141. ],
  142. 'BankAccount->getBalance' => [
  143. 'branches' => [
  144. 0 => [
  145. 'op_start' => 0,
  146. 'op_end' => 5,
  147. 'line_start' => 6,
  148. 'line_end' => 9,
  149. 'hit' => 1,
  150. 'out' => [
  151. ],
  152. 'out_hit' => [
  153. ],
  154. ],
  155. ],
  156. 'paths' => [
  157. 0 => [
  158. 'path' => [
  159. 0 => 0,
  160. ],
  161. 'hit' => 1,
  162. ],
  163. ],
  164. ],
  165. 'BankAccount->withdrawMoney' => [
  166. 'branches' => [
  167. 0 => [
  168. 'op_start' => 0,
  169. 'op_end' => 14,
  170. 'line_start' => 27,
  171. 'line_end' => 32,
  172. 'hit' => 0,
  173. 'out' => [
  174. ],
  175. 'out_hit' => [
  176. ],
  177. ],
  178. ],
  179. 'paths' => [
  180. 0 => [
  181. 'path' => [
  182. 0 => 0,
  183. ],
  184. 'hit' => 0,
  185. ],
  186. ],
  187. ],
  188. '{main}' => [
  189. 'branches' => [
  190. 0 => [
  191. 'op_start' => 0,
  192. 'op_end' => 1,
  193. 'line_start' => 34,
  194. 'line_end' => 34,
  195. 'hit' => 0,
  196. 'out' => [
  197. 0 => 2147483645,
  198. ],
  199. 'out_hit' => [
  200. 0 => 0,
  201. ],
  202. ],
  203. ],
  204. 'paths' => [
  205. 0 => [
  206. 'path' => [
  207. 0 => 0,
  208. ],
  209. 'hit' => 0,
  210. ],
  211. ],
  212. ],
  213. 'BankAccount->setBalance' => [
  214. 'branches' => [
  215. 0 => [
  216. 'op_start' => 0,
  217. 'op_end' => 4,
  218. 'line_start' => 11,
  219. 'line_end' => 13,
  220. 'hit' => 0,
  221. 'out' => [
  222. 0 => 5,
  223. 1 => 9,
  224. ],
  225. 'out_hit' => [
  226. 0 => 0,
  227. 1 => 0,
  228. ],
  229. ],
  230. 5 => [
  231. 'op_start' => 5,
  232. 'op_end' => 8,
  233. 'line_start' => 14,
  234. 'line_end' => 14,
  235. 'hit' => 0,
  236. 'out' => [
  237. 0 => 13,
  238. ],
  239. 'out_hit' => [
  240. 0 => 0,
  241. ],
  242. ],
  243. 9 => [
  244. 'op_start' => 9,
  245. 'op_end' => 12,
  246. 'line_start' => 16,
  247. 'line_end' => 16,
  248. 'hit' => 0,
  249. 'out' => [
  250. 0 => 2147483645,
  251. ],
  252. 'out_hit' => [
  253. 0 => 0,
  254. ],
  255. ],
  256. 13 => [
  257. 'op_start' => 13,
  258. 'op_end' => 14,
  259. 'line_start' => 18,
  260. 'line_end' => 18,
  261. 'hit' => 0,
  262. 'out' => [
  263. 0 => 2147483645,
  264. ],
  265. 'out_hit' => [
  266. 0 => 0,
  267. ],
  268. ],
  269. ],
  270. 'paths' => [
  271. 0 => [
  272. 'path' => [
  273. 0 => 0,
  274. 1 => 5,
  275. 2 => 13,
  276. ],
  277. 'hit' => 0,
  278. ],
  279. 1 => [
  280. 'path' => [
  281. 0 => 0,
  282. 1 => 9,
  283. ],
  284. 'hit' => 0,
  285. ],
  286. ],
  287. ],
  288. ],
  289. ],
  290. ]),
  291. RawCodeCoverageData::fromXdebugWithPathCoverage([
  292. TEST_FILES_PATH . 'BankAccount.php' => [
  293. 'lines' => [
  294. 8 => 1,
  295. 9 => -2,
  296. 13 => 1,
  297. 14 => -1,
  298. 15 => -1,
  299. 16 => 1,
  300. 18 => -1,
  301. 29 => 1,
  302. 31 => -1,
  303. 32 => -2,
  304. ],
  305. 'functions' => [
  306. 'BankAccount->depositMoney' => [
  307. 'branches' => [
  308. 0 => [
  309. 'op_start' => 0,
  310. 'op_end' => 14,
  311. 'line_start' => 20,
  312. 'line_end' => 25,
  313. 'hit' => 0,
  314. 'out' => [
  315. ],
  316. 'out_hit' => [
  317. ],
  318. ],
  319. ],
  320. 'paths' => [
  321. 0 => [
  322. 'path' => [
  323. 0 => 0,
  324. ],
  325. 'hit' => 0,
  326. ],
  327. ],
  328. ],
  329. 'BankAccount->getBalance' => [
  330. 'branches' => [
  331. 0 => [
  332. 'op_start' => 0,
  333. 'op_end' => 5,
  334. 'line_start' => 6,
  335. 'line_end' => 9,
  336. 'hit' => 1,
  337. 'out' => [
  338. ],
  339. 'out_hit' => [
  340. ],
  341. ],
  342. ],
  343. 'paths' => [
  344. 0 => [
  345. 'path' => [
  346. 0 => 0,
  347. ],
  348. 'hit' => 1,
  349. ],
  350. ],
  351. ],
  352. 'BankAccount->withdrawMoney' => [
  353. 'branches' => [
  354. 0 => [
  355. 'op_start' => 0,
  356. 'op_end' => 14,
  357. 'line_start' => 27,
  358. 'line_end' => 32,
  359. 'hit' => 1,
  360. 'out' => [
  361. ],
  362. 'out_hit' => [
  363. ],
  364. ],
  365. ],
  366. 'paths' => [
  367. 0 => [
  368. 'path' => [
  369. 0 => 0,
  370. ],
  371. 'hit' => 1,
  372. ],
  373. ],
  374. ],
  375. '{main}' => [
  376. 'branches' => [
  377. 0 => [
  378. 'op_start' => 0,
  379. 'op_end' => 1,
  380. 'line_start' => 34,
  381. 'line_end' => 34,
  382. 'hit' => 0,
  383. 'out' => [
  384. 0 => 2147483645,
  385. ],
  386. 'out_hit' => [
  387. 0 => 0,
  388. ],
  389. ],
  390. ],
  391. 'paths' => [
  392. 0 => [
  393. 'path' => [
  394. 0 => 0,
  395. ],
  396. 'hit' => 0,
  397. ],
  398. ],
  399. ],
  400. 'BankAccount->setBalance' => [
  401. 'branches' => [
  402. 0 => [
  403. 'op_start' => 0,
  404. 'op_end' => 4,
  405. 'line_start' => 11,
  406. 'line_end' => 13,
  407. 'hit' => 1,
  408. 'out' => [
  409. 0 => 5,
  410. 1 => 9,
  411. ],
  412. 'out_hit' => [
  413. 0 => 0,
  414. 1 => 0,
  415. ],
  416. ],
  417. 5 => [
  418. 'op_start' => 5,
  419. 'op_end' => 8,
  420. 'line_start' => 14,
  421. 'line_end' => 14,
  422. 'hit' => 0,
  423. 'out' => [
  424. 0 => 13,
  425. ],
  426. 'out_hit' => [
  427. 0 => 0,
  428. ],
  429. ],
  430. 9 => [
  431. 'op_start' => 9,
  432. 'op_end' => 12,
  433. 'line_start' => 16,
  434. 'line_end' => 16,
  435. 'hit' => 1,
  436. 'out' => [
  437. 0 => 2147483645,
  438. ],
  439. 'out_hit' => [
  440. 0 => 0,
  441. ],
  442. ],
  443. 13 => [
  444. 'op_start' => 13,
  445. 'op_end' => 14,
  446. 'line_start' => 18,
  447. 'line_end' => 18,
  448. 'hit' => 0,
  449. 'out' => [
  450. 0 => 2147483645,
  451. ],
  452. 'out_hit' => [
  453. 0 => 0,
  454. ],
  455. ],
  456. ],
  457. 'paths' => [
  458. 0 => [
  459. 'path' => [
  460. 0 => 0,
  461. 1 => 5,
  462. 2 => 13,
  463. ],
  464. 'hit' => 0,
  465. ],
  466. 1 => [
  467. 'path' => [
  468. 0 => 0,
  469. 1 => 9,
  470. ],
  471. 'hit' => 1,
  472. ],
  473. ],
  474. ],
  475. ],
  476. ],
  477. ]),
  478. RawCodeCoverageData::fromXdebugWithPathCoverage([
  479. TEST_FILES_PATH . 'BankAccount.php' => [
  480. 'lines' => [
  481. 8 => 1,
  482. 9 => -2,
  483. 13 => 1,
  484. 14 => -1,
  485. 15 => -1,
  486. 16 => 1,
  487. 18 => -1,
  488. 22 => 1,
  489. 24 => -1,
  490. 25 => -2,
  491. ],
  492. 'functions' => [
  493. 'BankAccount->depositMoney' => [
  494. 'branches' => [
  495. 0 => [
  496. 'op_start' => 0,
  497. 'op_end' => 14,
  498. 'line_start' => 20,
  499. 'line_end' => 25,
  500. 'hit' => 1,
  501. 'out' => [
  502. ],
  503. 'out_hit' => [
  504. ],
  505. ],
  506. ],
  507. 'paths' => [
  508. 0 => [
  509. 'path' => [
  510. 0 => 0,
  511. ],
  512. 'hit' => 1,
  513. ],
  514. ],
  515. ],
  516. 'BankAccount->getBalance' => [
  517. 'branches' => [
  518. 0 => [
  519. 'op_start' => 0,
  520. 'op_end' => 5,
  521. 'line_start' => 6,
  522. 'line_end' => 9,
  523. 'hit' => 1,
  524. 'out' => [
  525. ],
  526. 'out_hit' => [
  527. ],
  528. ],
  529. ],
  530. 'paths' => [
  531. 0 => [
  532. 'path' => [
  533. 0 => 0,
  534. ],
  535. 'hit' => 1,
  536. ],
  537. ],
  538. ],
  539. 'BankAccount->withdrawMoney' => [
  540. 'branches' => [
  541. 0 => [
  542. 'op_start' => 0,
  543. 'op_end' => 14,
  544. 'line_start' => 27,
  545. 'line_end' => 32,
  546. 'hit' => 0,
  547. 'out' => [
  548. ],
  549. 'out_hit' => [
  550. ],
  551. ],
  552. ],
  553. 'paths' => [
  554. 0 => [
  555. 'path' => [
  556. 0 => 0,
  557. ],
  558. 'hit' => 0,
  559. ],
  560. ],
  561. ],
  562. '{main}' => [
  563. 'branches' => [
  564. 0 => [
  565. 'op_start' => 0,
  566. 'op_end' => 1,
  567. 'line_start' => 34,
  568. 'line_end' => 34,
  569. 'hit' => 0,
  570. 'out' => [
  571. 0 => 2147483645,
  572. ],
  573. 'out_hit' => [
  574. 0 => 0,
  575. ],
  576. ],
  577. ],
  578. 'paths' => [
  579. 0 => [
  580. 'path' => [
  581. 0 => 0,
  582. ],
  583. 'hit' => 0,
  584. ],
  585. ],
  586. ],
  587. 'BankAccount->setBalance' => [
  588. 'branches' => [
  589. 0 => [
  590. 'op_start' => 0,
  591. 'op_end' => 4,
  592. 'line_start' => 11,
  593. 'line_end' => 13,
  594. 'hit' => 1,
  595. 'out' => [
  596. 0 => 5,
  597. 1 => 9,
  598. ],
  599. 'out_hit' => [
  600. 0 => 0,
  601. 1 => 0,
  602. ],
  603. ],
  604. 5 => [
  605. 'op_start' => 5,
  606. 'op_end' => 8,
  607. 'line_start' => 14,
  608. 'line_end' => 14,
  609. 'hit' => 0,
  610. 'out' => [
  611. 0 => 13,
  612. ],
  613. 'out_hit' => [
  614. 0 => 0,
  615. ],
  616. ],
  617. 9 => [
  618. 'op_start' => 9,
  619. 'op_end' => 12,
  620. 'line_start' => 16,
  621. 'line_end' => 16,
  622. 'hit' => 1,
  623. 'out' => [
  624. 0 => 2147483645,
  625. ],
  626. 'out_hit' => [
  627. 0 => 0,
  628. ],
  629. ],
  630. 13 => [
  631. 'op_start' => 13,
  632. 'op_end' => 14,
  633. 'line_start' => 18,
  634. 'line_end' => 18,
  635. 'hit' => 0,
  636. 'out' => [
  637. 0 => 2147483645,
  638. ],
  639. 'out_hit' => [
  640. 0 => 0,
  641. ],
  642. ],
  643. ],
  644. 'paths' => [
  645. 0 => [
  646. 'path' => [
  647. 0 => 0,
  648. 1 => 5,
  649. 2 => 13,
  650. ],
  651. 'hit' => 0,
  652. ],
  653. 1 => [
  654. 'path' => [
  655. 0 => 0,
  656. 1 => 9,
  657. ],
  658. 'hit' => 1,
  659. ],
  660. ],
  661. ],
  662. ],
  663. ],
  664. ]),
  665. RawCodeCoverageData::fromXdebugWithPathCoverage([
  666. TEST_FILES_PATH . 'BankAccount.php' => [
  667. 'lines' => [
  668. 8 => 1,
  669. 9 => -2,
  670. 13 => 1,
  671. 14 => 1,
  672. 15 => 1,
  673. 16 => -1,
  674. 18 => 1,
  675. 22 => 1,
  676. 24 => 1,
  677. 25 => -2,
  678. 29 => 1,
  679. 31 => 1,
  680. 32 => -2,
  681. ],
  682. 'functions' => [
  683. 'BankAccount->depositMoney' => [
  684. 'branches' => [
  685. 0 => [
  686. 'op_start' => 0,
  687. 'op_end' => 14,
  688. 'line_start' => 20,
  689. 'line_end' => 25,
  690. 'hit' => 1,
  691. 'out' => [
  692. ],
  693. 'out_hit' => [
  694. ],
  695. ],
  696. ],
  697. 'paths' => [
  698. 0 => [
  699. 'path' => [
  700. 0 => 0,
  701. ],
  702. 'hit' => 1,
  703. ],
  704. ],
  705. ],
  706. 'BankAccount->getBalance' => [
  707. 'branches' => [
  708. 0 => [
  709. 'op_start' => 0,
  710. 'op_end' => 5,
  711. 'line_start' => 6,
  712. 'line_end' => 9,
  713. 'hit' => 1,
  714. 'out' => [
  715. ],
  716. 'out_hit' => [
  717. ],
  718. ],
  719. ],
  720. 'paths' => [
  721. 0 => [
  722. 'path' => [
  723. 0 => 0,
  724. ],
  725. 'hit' => 1,
  726. ],
  727. ],
  728. ],
  729. 'BankAccount->withdrawMoney' => [
  730. 'branches' => [
  731. 0 => [
  732. 'op_start' => 0,
  733. 'op_end' => 14,
  734. 'line_start' => 27,
  735. 'line_end' => 32,
  736. 'hit' => 1,
  737. 'out' => [
  738. ],
  739. 'out_hit' => [
  740. ],
  741. ],
  742. ],
  743. 'paths' => [
  744. 0 => [
  745. 'path' => [
  746. 0 => 0,
  747. ],
  748. 'hit' => 1,
  749. ],
  750. ],
  751. ],
  752. '{main}' => [
  753. 'branches' => [
  754. 0 => [
  755. 'op_start' => 0,
  756. 'op_end' => 1,
  757. 'line_start' => 34,
  758. 'line_end' => 34,
  759. 'hit' => 0,
  760. 'out' => [
  761. 0 => 2147483645,
  762. ],
  763. 'out_hit' => [
  764. 0 => 0,
  765. ],
  766. ],
  767. ],
  768. 'paths' => [
  769. 0 => [
  770. 'path' => [
  771. 0 => 0,
  772. ],
  773. 'hit' => 0,
  774. ],
  775. ],
  776. ],
  777. 'BankAccount->setBalance' => [
  778. 'branches' => [
  779. 0 => [
  780. 'op_start' => 0,
  781. 'op_end' => 4,
  782. 'line_start' => 11,
  783. 'line_end' => 13,
  784. 'hit' => 1,
  785. 'out' => [
  786. 0 => 5,
  787. 1 => 9,
  788. ],
  789. 'out_hit' => [
  790. 0 => 0,
  791. 1 => 0,
  792. ],
  793. ],
  794. 5 => [
  795. 'op_start' => 5,
  796. 'op_end' => 8,
  797. 'line_start' => 14,
  798. 'line_end' => 14,
  799. 'hit' => 1,
  800. 'out' => [
  801. 0 => 13,
  802. ],
  803. 'out_hit' => [
  804. 0 => 0,
  805. ],
  806. ],
  807. 9 => [
  808. 'op_start' => 9,
  809. 'op_end' => 12,
  810. 'line_start' => 16,
  811. 'line_end' => 16,
  812. 'hit' => 0,
  813. 'out' => [
  814. 0 => 2147483645,
  815. ],
  816. 'out_hit' => [
  817. 0 => 0,
  818. ],
  819. ],
  820. 13 => [
  821. 'op_start' => 13,
  822. 'op_end' => 14,
  823. 'line_start' => 18,
  824. 'line_end' => 18,
  825. 'hit' => 1,
  826. 'out' => [
  827. 0 => 2147483645,
  828. ],
  829. 'out_hit' => [
  830. 0 => 0,
  831. ],
  832. ],
  833. ],
  834. 'paths' => [
  835. 0 => [
  836. 'path' => [
  837. 0 => 0,
  838. 1 => 5,
  839. 2 => 13,
  840. ],
  841. 'hit' => 1,
  842. ],
  843. 1 => [
  844. 'path' => [
  845. 0 => 0,
  846. 1 => 9,
  847. ],
  848. 'hit' => 0,
  849. ],
  850. ],
  851. ],
  852. ],
  853. ],
  854. ]),
  855. ];
  856. }
  857. protected function getPathCoverageXdebugDataForSourceWithoutNamespace()
  858. {
  859. return [
  860. RawCodeCoverageData::fromXdebugWithPathCoverage(
  861. [
  862. TEST_FILES_PATH . 'source_without_namespace.php' => [
  863. 'lines' => [
  864. 14 => -1,
  865. 15 => -1,
  866. 16 => -1,
  867. 17 => -1,
  868. 18 => -1,
  869. 19 => 1,
  870. ],
  871. 'functions' => [
  872. '{closure:' . TEST_FILES_PATH . 'source_without_namespace.php:14-14}' => [
  873. 'branches' => [
  874. 0 => [
  875. 'op_start' => 0,
  876. 'op_end' => 2,
  877. 'line_start' => 14,
  878. 'line_end' => 14,
  879. 'hit' => 0,
  880. 'out' => [
  881. 0 => 2147483645,
  882. ],
  883. 'out_hit' => [
  884. 0 => 0,
  885. ],
  886. ],
  887. ],
  888. 'paths' => [
  889. 0 => [
  890. 'path' => [
  891. 0 => 0,
  892. ],
  893. 'hit' => 0,
  894. ],
  895. ],
  896. ],
  897. 'foo' => [
  898. 'branches' => [
  899. 0 => [
  900. 'op_start' => 0,
  901. 'op_end' => 6,
  902. 'line_start' => 12,
  903. 'line_end' => 15,
  904. 'hit' => 0,
  905. 'out' => [
  906. 0 => 7,
  907. 1 => 9,
  908. ],
  909. 'out_hit' => [
  910. 0 => 0,
  911. 1 => 0,
  912. ],
  913. ],
  914. 7 => [
  915. 'op_start' => 7,
  916. 'op_end' => 8,
  917. 'line_start' => 15,
  918. 'line_end' => 15,
  919. 'hit' => 0,
  920. 'out' => [
  921. 0 => 10,
  922. ],
  923. 'out_hit' => [
  924. 0 => 0,
  925. ],
  926. ],
  927. 9 => [
  928. 'op_start' => 9,
  929. 'op_end' => 9,
  930. 'line_start' => 15,
  931. 'line_end' => 15,
  932. 'hit' => 0,
  933. 'out' => [
  934. 0 => 10,
  935. ],
  936. 'out_hit' => [
  937. 0 => 0,
  938. ],
  939. ],
  940. 10 => [
  941. 'op_start' => 10,
  942. 'op_end' => 18,
  943. 'line_start' => 15,
  944. 'line_end' => 18,
  945. 'hit' => 0,
  946. 'out' => [
  947. ],
  948. 'out_hit' => [
  949. ],
  950. ],
  951. ],
  952. 'paths' => [
  953. 0 => [
  954. 'path' => [
  955. 0 => 0,
  956. 1 => 7,
  957. 2 => 10,
  958. ],
  959. 'hit' => 0,
  960. ],
  961. 1 => [
  962. 'path' => [
  963. 0 => 0,
  964. 1 => 9,
  965. 2 => 10,
  966. ],
  967. 'hit' => 0,
  968. ],
  969. ],
  970. ],
  971. '{main}' => [
  972. 'branches' => [
  973. 0 => [
  974. 'op_start' => 0,
  975. 'op_end' => 0,
  976. 'line_start' => 19,
  977. 'line_end' => 19,
  978. 'hit' => 1,
  979. 'out' => [
  980. 0 => 2147483645,
  981. ],
  982. 'out_hit' => [
  983. 0 => 0,
  984. ],
  985. ],
  986. ],
  987. 'paths' => [
  988. 0 => [
  989. 'path' => [
  990. 0 => 0,
  991. ],
  992. 'hit' => 1,
  993. ],
  994. ],
  995. ],
  996. ],
  997. ],
  998. ]
  999. ),
  1000. ];
  1001. }
  1002. protected function getLineCoverageForBankAccount(): CodeCoverage
  1003. {
  1004. $data = $this->getLineCoverageXdebugDataForBankAccount();
  1005. $stub = $this->createStub(Driver::class);
  1006. $stub->method('stop')
  1007. ->will($this->onConsecutiveCalls(...$data));
  1008. $filter = new Filter;
  1009. $filter->includeFile(TEST_FILES_PATH . 'BankAccount.php');
  1010. $coverage = new CodeCoverage($stub, $filter);
  1011. $coverage->start(
  1012. new BankAccountTest('testBalanceIsInitiallyZero'),
  1013. true
  1014. );
  1015. $coverage->stop(
  1016. true,
  1017. [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)]
  1018. );
  1019. $coverage->start(
  1020. new BankAccountTest('testBalanceCannotBecomeNegative')
  1021. );
  1022. $coverage->stop(
  1023. true,
  1024. [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)]
  1025. );
  1026. $coverage->start(
  1027. new BankAccountTest('testBalanceCannotBecomeNegative2')
  1028. );
  1029. $coverage->stop(
  1030. true,
  1031. [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)]
  1032. );
  1033. $coverage->start(
  1034. new BankAccountTest('testDepositWithdrawMoney')
  1035. );
  1036. $coverage->stop(
  1037. true,
  1038. [
  1039. TEST_FILES_PATH . 'BankAccount.php' => array_merge(
  1040. range(6, 9),
  1041. range(20, 25),
  1042. range(27, 32)
  1043. ),
  1044. ]
  1045. );
  1046. return $coverage;
  1047. }
  1048. protected function getPathCoverageForBankAccount(): CodeCoverage
  1049. {
  1050. $data = $this->getPathCoverageXdebugDataForBankAccount();
  1051. $stub = $this->createStub(Driver::class);
  1052. $stub->method('collectsBranchAndPathCoverage')->willReturn(true);
  1053. $stub->method('stop')
  1054. ->will($this->onConsecutiveCalls(...$data));
  1055. $filter = new Filter;
  1056. $filter->includeFile(TEST_FILES_PATH . 'BankAccount.php');
  1057. $coverage = new CodeCoverage($stub, $filter);
  1058. $coverage->start(
  1059. new BankAccountTest('testBalanceIsInitiallyZero'),
  1060. true
  1061. );
  1062. $coverage->stop(
  1063. true,
  1064. [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)]
  1065. );
  1066. $coverage->start(
  1067. new BankAccountTest('testBalanceCannotBecomeNegative')
  1068. );
  1069. $coverage->stop(
  1070. true,
  1071. [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)]
  1072. );
  1073. $coverage->start(
  1074. new BankAccountTest('testBalanceCannotBecomeNegative2')
  1075. );
  1076. $coverage->stop(
  1077. true,
  1078. [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)]
  1079. );
  1080. $coverage->start(
  1081. new BankAccountTest('testDepositWithdrawMoney')
  1082. );
  1083. $coverage->stop(
  1084. true,
  1085. [
  1086. TEST_FILES_PATH . 'BankAccount.php' => array_merge(
  1087. range(6, 9),
  1088. range(20, 25),
  1089. range(27, 32)
  1090. ),
  1091. ]
  1092. );
  1093. return $coverage;
  1094. }
  1095. protected function getPathCoverageForSourceWithoutNamespace(): CodeCoverage
  1096. {
  1097. $data = $this->getPathCoverageXdebugDataForSourceWithoutNamespace();
  1098. $stub = $this->createStub(Driver::class);
  1099. $stub->method('collectsBranchAndPathCoverage')->willReturn(true);
  1100. $stub->method('stop')
  1101. ->will($this->onConsecutiveCalls(...$data));
  1102. $filter = new Filter;
  1103. $filter->includeFile(TEST_FILES_PATH . 'source_without_namespace.php');
  1104. $coverage = new CodeCoverage($stub, $filter);
  1105. $coverage->start(
  1106. 'faketest',
  1107. true
  1108. );
  1109. $coverage->stop();
  1110. return $coverage;
  1111. }
  1112. protected function getXdebugDataForNamespacedBankAccount()
  1113. {
  1114. return [
  1115. RawCodeCoverageData::fromXdebugWithoutPathCoverage([
  1116. TEST_FILES_PATH . 'NamespacedBankAccount.php' => [
  1117. 13 => 1,
  1118. 14 => -2,
  1119. 18 => -1,
  1120. 19 => -1,
  1121. 20 => -1,
  1122. 21 => -1,
  1123. 23 => -1,
  1124. 27 => -1,
  1125. 29 => -1,
  1126. 30 => -2,
  1127. 34 => -1,
  1128. 36 => -1,
  1129. 37 => -2,
  1130. ],
  1131. ]),
  1132. RawCodeCoverageData::fromXdebugWithoutPathCoverage([
  1133. TEST_FILES_PATH . 'NamespacedBankAccount.php' => [
  1134. 13 => 1,
  1135. 18 => 1,
  1136. 21 => 1,
  1137. 34 => 1,
  1138. ],
  1139. ]),
  1140. RawCodeCoverageData::fromXdebugWithoutPathCoverage([
  1141. TEST_FILES_PATH . 'NamespacedBankAccount.php' => [
  1142. 13 => 1,
  1143. 18 => 1,
  1144. 21 => 1,
  1145. 27 => 1,
  1146. ],
  1147. ]),
  1148. RawCodeCoverageData::fromXdebugWithoutPathCoverage([
  1149. TEST_FILES_PATH . 'NamespacedBankAccount.php' => [
  1150. 13 => 1,
  1151. 18 => 1,
  1152. 19 => 1,
  1153. 20 => 1,
  1154. 23 => 1,
  1155. 27 => 1,
  1156. 29 => 1,
  1157. 34 => 1,
  1158. 36 => 1,
  1159. ],
  1160. ]),
  1161. ];
  1162. }
  1163. protected function getLineCoverageForNamespacedBankAccount(): CodeCoverage
  1164. {
  1165. $data = $this->getXdebugDataForNamespacedBankAccount();
  1166. $stub = $this->createStub(Driver::class);
  1167. $stub->method('stop')
  1168. ->will($this->onConsecutiveCalls(...$data));
  1169. $filter = new Filter;
  1170. $filter->includeFile(TEST_FILES_PATH . 'NamespacedBankAccount.php');
  1171. $coverage = new CodeCoverage($stub, $filter);
  1172. $coverage->start(
  1173. new BankAccountTest('testBalanceIsInitiallyZero'),
  1174. true
  1175. );
  1176. $coverage->stop(
  1177. true,
  1178. [TEST_FILES_PATH . 'NamespacedBankAccount.php' => range(11, 14)]
  1179. );
  1180. $coverage->start(
  1181. new BankAccountTest('testBalanceCannotBecomeNegative')
  1182. );
  1183. $coverage->stop(
  1184. true,
  1185. [TEST_FILES_PATH . 'NamespacedBankAccount.php' => range(32, 37)]
  1186. );
  1187. $coverage->start(
  1188. new BankAccountTest('testBalanceCannotBecomeNegative2')
  1189. );
  1190. $coverage->stop(
  1191. true,
  1192. [TEST_FILES_PATH . 'NamespacedBankAccount.php' => range(25, 30)]
  1193. );
  1194. $coverage->start(
  1195. new BankAccountTest('testDepositWithdrawMoney')
  1196. );
  1197. $coverage->stop(
  1198. true,
  1199. [
  1200. TEST_FILES_PATH . 'NamespacedBankAccount.php' => array_merge(
  1201. range(11, 14),
  1202. range(25, 30),
  1203. range(32, 37)
  1204. ),
  1205. ]
  1206. );
  1207. return $coverage;
  1208. }
  1209. protected function getLineCoverageForBankAccountForFirstTwoTests(): CodeCoverage
  1210. {
  1211. $data = $this->getLineCoverageXdebugDataForBankAccount();
  1212. $stub = $this->createStub(Driver::class);
  1213. $stub->method('stop')
  1214. ->will($this->onConsecutiveCalls(...$data));
  1215. $filter = new Filter;
  1216. $filter->includeFile(TEST_FILES_PATH . 'BankAccount.php');
  1217. $coverage = new CodeCoverage($stub, $filter);
  1218. $coverage->start(
  1219. new BankAccountTest('testBalanceIsInitiallyZero'),
  1220. true
  1221. );
  1222. $coverage->stop(
  1223. true,
  1224. [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)]
  1225. );
  1226. $coverage->start(
  1227. new BankAccountTest('testBalanceCannotBecomeNegative')
  1228. );
  1229. $coverage->stop(
  1230. true,
  1231. [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)]
  1232. );
  1233. return $coverage;
  1234. }
  1235. protected function getLineCoverageForBankAccountForLastTwoTests(): CodeCoverage
  1236. {
  1237. $data = $this->getLineCoverageXdebugDataForBankAccount();
  1238. $stub = $this->createStub(Driver::class);
  1239. $stub->method('stop')
  1240. ->will($this->onConsecutiveCalls($data[2], $data[3]));
  1241. $filter = new Filter;
  1242. $filter->includeFile(TEST_FILES_PATH . 'BankAccount.php');
  1243. $coverage = new CodeCoverage($stub, $filter);
  1244. $coverage->start(
  1245. new BankAccountTest('testBalanceCannotBecomeNegative2')
  1246. );
  1247. $coverage->stop(
  1248. true,
  1249. [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)]
  1250. );
  1251. $coverage->start(
  1252. new BankAccountTest('testDepositWithdrawMoney')
  1253. );
  1254. $coverage->stop(
  1255. true,
  1256. [
  1257. TEST_FILES_PATH . 'BankAccount.php' => array_merge(
  1258. range(6, 9),
  1259. range(20, 25),
  1260. range(27, 32)
  1261. ),
  1262. ]
  1263. );
  1264. return $coverage;
  1265. }
  1266. protected function getExpectedLineCoverageDataArrayForBankAccount(): array
  1267. {
  1268. return [
  1269. TEST_FILES_PATH . 'BankAccount.php' => [
  1270. 8 => [
  1271. 0 => 'BankAccountTest::testBalanceIsInitiallyZero',
  1272. 1 => 'BankAccountTest::testDepositWithdrawMoney',
  1273. ],
  1274. 13 => [],
  1275. 14 => [],
  1276. 16 => [],
  1277. 22 => [
  1278. 0 => 'BankAccountTest::testBalanceCannotBecomeNegative2',
  1279. 1 => 'BankAccountTest::testDepositWithdrawMoney',
  1280. ],
  1281. 24 => [
  1282. 0 => 'BankAccountTest::testDepositWithdrawMoney',
  1283. ],
  1284. 29 => [
  1285. 0 => 'BankAccountTest::testBalanceCannotBecomeNegative',
  1286. 1 => 'BankAccountTest::testDepositWithdrawMoney',
  1287. ],
  1288. 31 => [
  1289. 0 => 'BankAccountTest::testDepositWithdrawMoney',
  1290. ],
  1291. 32 => null,
  1292. ],
  1293. ];
  1294. }
  1295. protected function getExpectedLineCoverageDataArrayForBankAccountInReverseOrder(): array
  1296. {
  1297. return [
  1298. TEST_FILES_PATH . 'BankAccount.php' => [
  1299. 8 => [
  1300. 0 => 'BankAccountTest::testDepositWithdrawMoney',
  1301. 1 => 'BankAccountTest::testBalanceIsInitiallyZero',
  1302. ],
  1303. 13 => [],
  1304. 14 => [],
  1305. 16 => [],
  1306. 22 => [
  1307. 0 => 'BankAccountTest::testBalanceCannotBecomeNegative2',
  1308. 1 => 'BankAccountTest::testDepositWithdrawMoney',
  1309. ],
  1310. 24 => [
  1311. 0 => 'BankAccountTest::testDepositWithdrawMoney',
  1312. ],
  1313. 29 => [
  1314. 0 => 'BankAccountTest::testDepositWithdrawMoney',
  1315. 1 => 'BankAccountTest::testBalanceCannotBecomeNegative',
  1316. ],
  1317. 31 => [
  1318. 0 => 'BankAccountTest::testDepositWithdrawMoney',
  1319. ],
  1320. 32 => null,
  1321. ],
  1322. ];
  1323. }
  1324. protected function getPathCoverageForBankAccountForFirstTwoTests(): CodeCoverage
  1325. {
  1326. $data = $this->getPathCoverageXdebugDataForBankAccount();
  1327. $stub = $this->createStub(Driver::class);
  1328. $stub->method('stop')
  1329. ->will($this->onConsecutiveCalls(...$data));
  1330. $filter = new Filter;
  1331. $filter->includeFile(TEST_FILES_PATH . 'BankAccount.php');
  1332. $coverage = new CodeCoverage($stub, $filter);
  1333. $coverage->start(
  1334. new BankAccountTest('testBalanceIsInitiallyZero'),
  1335. true
  1336. );
  1337. $coverage->stop(
  1338. true,
  1339. [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)]
  1340. );
  1341. $coverage->start(
  1342. new BankAccountTest('testBalanceCannotBecomeNegative')
  1343. );
  1344. $coverage->stop(
  1345. true,
  1346. [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)]
  1347. );
  1348. return $coverage;
  1349. }
  1350. protected function getPathCoverageForBankAccountForLastTwoTests(): CodeCoverage
  1351. {
  1352. $data = $this->getPathCoverageXdebugDataForBankAccount();
  1353. $stub = $this->createStub(Driver::class);
  1354. $stub->method('stop')
  1355. ->will($this->onConsecutiveCalls($data[2], $data[3]));
  1356. $filter = new Filter;
  1357. $filter->includeFile(TEST_FILES_PATH . 'BankAccount.php');
  1358. $coverage = new CodeCoverage($stub, $filter);
  1359. $coverage->start(
  1360. new BankAccountTest('testBalanceCannotBecomeNegative2')
  1361. );
  1362. $coverage->stop(
  1363. true,
  1364. [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)]
  1365. );
  1366. $coverage->start(
  1367. new BankAccountTest('testDepositWithdrawMoney')
  1368. );
  1369. $coverage->stop(
  1370. true,
  1371. [
  1372. TEST_FILES_PATH . 'BankAccount.php' => array_merge(
  1373. range(6, 9),
  1374. range(20, 25),
  1375. range(27, 32)
  1376. ),
  1377. ]
  1378. );
  1379. return $coverage;
  1380. }
  1381. protected function getExpectedPathCoverageDataArrayForBankAccount(): array
  1382. {
  1383. return [
  1384. TEST_FILES_PATH . 'BankAccount.php' => [
  1385. 'BankAccount->depositMoney' => [
  1386. 'branches' => [
  1387. 0 => [
  1388. 'op_start' => 0,
  1389. 'op_end' => 14,
  1390. 'line_start' => 20,
  1391. 'line_end' => 25,
  1392. 'hit' => [
  1393. 0 => 'BankAccountTest::testBalanceCannotBecomeNegative2',
  1394. 1 => 'BankAccountTest::testDepositWithdrawMoney',
  1395. ],
  1396. 'out' => [
  1397. ],
  1398. 'out_hit' => [
  1399. ],
  1400. ],
  1401. ],
  1402. 'paths' => [
  1403. 0 => [
  1404. 'path' => [
  1405. 0 => 0,
  1406. ],
  1407. 'hit' => [
  1408. 0 => 'BankAccountTest::testBalanceCannotBecomeNegative2',
  1409. 1 => 'BankAccountTest::testDepositWithdrawMoney',
  1410. ],
  1411. ],
  1412. ],
  1413. ],
  1414. 'BankAccount->getBalance' => [
  1415. 'branches' => [
  1416. 0 => [
  1417. 'op_start' => 0,
  1418. 'op_end' => 5,
  1419. 'line_start' => 6,
  1420. 'line_end' => 9,
  1421. 'hit' => [
  1422. 0 => 'BankAccountTest::testBalanceIsInitiallyZero',
  1423. 1 => 'BankAccountTest::testDepositWithdrawMoney',
  1424. ],
  1425. 'out' => [
  1426. ],
  1427. 'out_hit' => [
  1428. ],
  1429. ],
  1430. ],
  1431. 'paths' => [
  1432. 0 => [
  1433. 'path' => [
  1434. 0 => 0,
  1435. ],
  1436. 'hit' => [
  1437. 0 => 'BankAccountTest::testBalanceIsInitiallyZero',
  1438. 1 => 'BankAccountTest::testDepositWithdrawMoney',
  1439. ],
  1440. ],
  1441. ],
  1442. ],
  1443. 'BankAccount->withdrawMoney' => [
  1444. 'branches' => [
  1445. 0 => [
  1446. 'op_start' => 0,
  1447. 'op_end' => 14,
  1448. 'line_start' => 27,
  1449. 'line_end' => 32,
  1450. 'hit' => [
  1451. 0 => 'BankAccountTest::testBalanceCannotBecomeNegative',
  1452. 1 => 'BankAccountTest::testDepositWithdrawMoney',
  1453. ],
  1454. 'out' => [
  1455. ],
  1456. 'out_hit' => [
  1457. ],
  1458. ],
  1459. ],
  1460. 'paths' => [
  1461. 0 => [
  1462. 'path' => [
  1463. 0 => 0,
  1464. ],
  1465. 'hit' => [
  1466. 0 => 'BankAccountTest::testBalanceCannotBecomeNegative',
  1467. 1 => 'BankAccountTest::testDepositWithdrawMoney',
  1468. ],
  1469. ],
  1470. ],
  1471. ],
  1472. '{main}' => [
  1473. 'branches' => [
  1474. 0 => [
  1475. 'op_start' => 0,
  1476. 'op_end' => 1,
  1477. 'line_start' => 34,
  1478. 'line_end' => 34,
  1479. 'hit' => [
  1480. ],
  1481. 'out' => [
  1482. 0 => 2147483645,
  1483. ],
  1484. 'out_hit' => [
  1485. 0 => 0,
  1486. ],
  1487. ],
  1488. ],
  1489. 'paths' => [
  1490. 0 => [
  1491. 'path' => [
  1492. 0 => 0,
  1493. ],
  1494. 'hit' => [
  1495. ],
  1496. ],
  1497. ],
  1498. ],
  1499. 'BankAccount->setBalance' => [
  1500. 'branches' => [
  1501. 0 => [
  1502. 'op_start' => 0,
  1503. 'op_end' => 4,
  1504. 'line_start' => 11,
  1505. 'line_end' => 13,
  1506. 'hit' => [
  1507. ],
  1508. 'out' => [
  1509. 0 => 5,
  1510. 1 => 9,
  1511. ],
  1512. 'out_hit' => [
  1513. 0 => 0,
  1514. 1 => 0,
  1515. ],
  1516. ],
  1517. 5 => [
  1518. 'op_start' => 5,
  1519. 'op_end' => 8,
  1520. 'line_start' => 14,
  1521. 'line_end' => 14,
  1522. 'hit' => [
  1523. ],
  1524. 'out' => [
  1525. 0 => 13,
  1526. ],
  1527. 'out_hit' => [
  1528. 0 => 0,
  1529. ],
  1530. ],
  1531. 9 => [
  1532. 'op_start' => 9,
  1533. 'op_end' => 12,
  1534. 'line_start' => 16,
  1535. 'line_end' => 16,
  1536. 'hit' => [
  1537. ],
  1538. 'out' => [
  1539. 0 => 2147483645,
  1540. ],
  1541. 'out_hit' => [
  1542. 0 => 0,
  1543. ],
  1544. ],
  1545. 13 => [
  1546. 'op_start' => 13,
  1547. 'op_end' => 14,
  1548. 'line_start' => 18,
  1549. 'line_end' => 18,
  1550. 'hit' => [
  1551. ],
  1552. 'out' => [
  1553. 0 => 2147483645,
  1554. ],
  1555. 'out_hit' => [
  1556. 0 => 0,
  1557. ],
  1558. ],
  1559. ],
  1560. 'paths' => [
  1561. 0 => [
  1562. 'path' => [
  1563. 0 => 0,
  1564. 1 => 5,
  1565. 2 => 13,
  1566. ],
  1567. 'hit' => [
  1568. ],
  1569. ],
  1570. 1 => [
  1571. 'path' => [
  1572. 0 => 0,
  1573. 1 => 9,
  1574. ],
  1575. 'hit' => [
  1576. ],
  1577. ],
  1578. ],
  1579. ],
  1580. ],
  1581. ];
  1582. }
  1583. protected function getCoverageForFileWithIgnoredLines(): CodeCoverage
  1584. {
  1585. $filter = new Filter;
  1586. $filter->includeFile(TEST_FILES_PATH . 'source_with_ignore.php');
  1587. $coverage = new CodeCoverage(
  1588. $this->setUpXdebugStubForFileWithIgnoredLines(),
  1589. $filter
  1590. );
  1591. $coverage->start('FileWithIgnoredLines', true);
  1592. $coverage->stop();
  1593. return $coverage;
  1594. }
  1595. protected function setUpXdebugStubForFileWithIgnoredLines(): Driver
  1596. {
  1597. $stub = $this->createStub(Driver::class);
  1598. $stub->method('stop')
  1599. ->willReturn(RawCodeCoverageData::fromXdebugWithoutPathCoverage(
  1600. [
  1601. TEST_FILES_PATH . 'source_with_ignore.php' => [
  1602. 2 => 1,
  1603. 4 => -1,
  1604. 6 => -1,
  1605. ],
  1606. ]
  1607. ));
  1608. return $stub;
  1609. }
  1610. protected function getLineCoverageForFileWithEval(): CodeCoverage
  1611. {
  1612. $filter = new Filter;
  1613. $filter->includeFile(TEST_FILES_PATH . 'source_with_eval.php');
  1614. $coverage = new CodeCoverage(
  1615. $this->setUpXdebugStubForFileWithEval(),
  1616. $filter
  1617. );
  1618. $coverage->start('FileWithEval', true);
  1619. $coverage->stop();
  1620. return $coverage;
  1621. }
  1622. protected function setUpXdebugStubForFileWithEval(): Driver
  1623. {
  1624. $stub = $this->createStub(Driver::class);
  1625. $stub->method('stop')
  1626. ->willReturn(RawCodeCoverageData::fromXdebugWithoutPathCoverage(
  1627. [
  1628. TEST_FILES_PATH . 'source_with_eval.php' => [
  1629. 3 => 1,
  1630. 5 => 1,
  1631. ],
  1632. TEST_FILES_PATH . 'source_with_eval.php(5) : eval()\'d code' => [
  1633. 1 => 1,
  1634. ],
  1635. ]
  1636. ));
  1637. return $stub;
  1638. }
  1639. protected function getCoverageForClassWithAnonymousFunction(): CodeCoverage
  1640. {
  1641. $filter = new Filter;
  1642. $filter->includeFile(TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php');
  1643. $coverage = new CodeCoverage(
  1644. $this->setUpXdebugStubForClassWithAnonymousFunction(),
  1645. $filter
  1646. );
  1647. $coverage->start('ClassWithAnonymousFunction', true);
  1648. $coverage->stop();
  1649. return $coverage;
  1650. }
  1651. protected function setUpXdebugStubForClassWithAnonymousFunction(): Driver
  1652. {
  1653. $stub = $this->createStub(Driver::class);
  1654. $stub->method('stop')
  1655. ->willReturn(RawCodeCoverageData::fromXdebugWithoutPathCoverage(
  1656. [
  1657. TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php' => [
  1658. 7 => 1,
  1659. 9 => 1,
  1660. 10 => -1,
  1661. 11 => 1,
  1662. 12 => 1,
  1663. 13 => 1,
  1664. 14 => 1,
  1665. 17 => 1,
  1666. 18 => 1,
  1667. ],
  1668. ]
  1669. ));
  1670. return $stub;
  1671. }
  1672. protected function getCoverageForClassWithOutsideFunction(): CodeCoverage
  1673. {
  1674. $filter = new Filter;
  1675. $filter->includeFile(TEST_FILES_PATH . 'source_with_class_and_outside_function.php');
  1676. $coverage = new CodeCoverage(
  1677. $this->setUpXdebugStubForClassWithOutsideFunction(),
  1678. $filter
  1679. );
  1680. $coverage->start('ClassWithOutsideFunction', true);
  1681. $coverage->stop();
  1682. return $coverage;
  1683. }
  1684. protected function setUpXdebugStubForClassWithOutsideFunction(): Driver
  1685. {
  1686. $stub = $this->createStub(Driver::class);
  1687. $stub->method('stop')
  1688. ->willReturn(RawCodeCoverageData::fromXdebugWithoutPathCoverage(
  1689. [
  1690. TEST_FILES_PATH . 'source_with_class_and_outside_function.php' => [
  1691. 6 => 1,
  1692. 12 => 1,
  1693. 13 => 1,
  1694. 16 => -1,
  1695. ],
  1696. ]
  1697. ));
  1698. return $stub;
  1699. }
  1700. protected function removeTemporaryFiles(): void
  1701. {
  1702. $tmpFilesIterator = new RecursiveIteratorIterator(
  1703. new RecursiveDirectoryIterator(self::$TEST_TMP_PATH, RecursiveDirectoryIterator::SKIP_DOTS),
  1704. RecursiveIteratorIterator::CHILD_FIRST
  1705. );
  1706. foreach ($tmpFilesIterator as $path => $fileInfo) {
  1707. /* @var \SplFileInfo $fileInfo */
  1708. $pathname = $fileInfo->getPathname();
  1709. $fileInfo->isDir() ? rmdir($pathname) : unlink($pathname);
  1710. }
  1711. }
  1712. protected function getCoverageForFilesWithUncoveredIncluded(): CodeCoverage
  1713. {
  1714. $data = $this->getLineCoverageXdebugDataForBankAccount();
  1715. $stub = $this->createStub(Driver::class);
  1716. $stub->method('stop')
  1717. ->will($this->onConsecutiveCalls(...$data));
  1718. $filter = new Filter;
  1719. $filter->includeFile(TEST_FILES_PATH . 'BankAccount.php');
  1720. $filter->includeFile(TEST_FILES_PATH . 'NamespacedBankAccount.php');
  1721. $coverage = new CodeCoverage($stub, $filter);
  1722. $coverage->includeUncoveredFiles();
  1723. $coverage->start(
  1724. new BankAccountTest('testBalanceIsInitiallyZero'),
  1725. true
  1726. );
  1727. $coverage->stop(
  1728. true,
  1729. [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)]
  1730. );
  1731. $coverage->start(
  1732. new BankAccountTest('testBalanceCannotBecomeNegative')
  1733. );
  1734. $coverage->stop(
  1735. true,
  1736. [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)]
  1737. );
  1738. $coverage->start(
  1739. new BankAccountTest('testBalanceCannotBecomeNegative2')
  1740. );
  1741. $coverage->stop(
  1742. true,
  1743. [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)]
  1744. );
  1745. $coverage->start(
  1746. new BankAccountTest('testDepositWithdrawMoney')
  1747. );
  1748. $coverage->stop(
  1749. true,
  1750. [
  1751. TEST_FILES_PATH . 'BankAccount.php' => array_merge(
  1752. range(6, 9),
  1753. range(20, 25),
  1754. range(27, 32)
  1755. ),
  1756. ]
  1757. );
  1758. return $coverage;
  1759. }
  1760. protected function getCoverageForFilesWithUncoveredExcluded(): CodeCoverage
  1761. {
  1762. $data = $this->getLineCoverageXdebugDataForBankAccount();
  1763. $stub = $this->createStub(Driver::class);
  1764. $stub->method('stop')
  1765. ->will($this->onConsecutiveCalls(...$data));
  1766. $filter = new Filter;
  1767. $filter->includeFile(TEST_FILES_PATH . 'BankAccount.php');
  1768. $filter->includeFile(TEST_FILES_PATH . 'NamespacedBankAccount.php');
  1769. $coverage = new CodeCoverage($stub, $filter);
  1770. $coverage->excludeUncoveredFiles();
  1771. $coverage->start(
  1772. new BankAccountTest('testBalanceIsInitiallyZero'),
  1773. true
  1774. );
  1775. $coverage->stop(
  1776. true,
  1777. [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)]
  1778. );
  1779. $coverage->start(
  1780. new BankAccountTest('testBalanceCannotBecomeNegative')
  1781. );
  1782. $coverage->stop(
  1783. true,
  1784. [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)]
  1785. );
  1786. $coverage->start(
  1787. new BankAccountTest('testBalanceCannotBecomeNegative2')
  1788. );
  1789. $coverage->stop(
  1790. true,
  1791. [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)]
  1792. );
  1793. $coverage->start(
  1794. new BankAccountTest('testDepositWithdrawMoney')
  1795. );
  1796. $coverage->stop(
  1797. true,
  1798. [
  1799. TEST_FILES_PATH . 'BankAccount.php' => array_merge(
  1800. range(6, 9),
  1801. range(20, 25),
  1802. range(27, 32)
  1803. ),
  1804. ]
  1805. );
  1806. return $coverage;
  1807. }
  1808. }