Skip to content

Commit adc7223

Browse files
baidubaidu
authored andcommitted
liulu
1 parent a02682e commit adc7223

File tree

14 files changed

+849
-149
lines changed

14 files changed

+849
-149
lines changed

src/.DS_Store

6 KB
Binary file not shown.

src/CodeCoverage.php

Lines changed: 77 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ class PHP_CodeCoverage
8080
*/
8181
private $ignoredLines = array();
8282

83-
/**
84-
* @var bool
85-
*/
86-
private $disableIgnoredLines = false;
87-
8883
/**
8984
* Test data.
9085
*
@@ -104,11 +99,13 @@ public function __construct(PHP_CodeCoverage_Driver $driver = null, PHP_CodeCove
10499
if ($driver === null) {
105100
$runtime = new Runtime;
106101

107-
if (!$runtime->hasXdebug()) {
102+
if ($runtime->isHHVM()) {
103+
$driver = new PHP_CodeCoverage_Driver_HHVM;
104+
} elseif ($runtime->hasXdebug()) {
105+
$driver = new PHP_CodeCoverage_Driver_Xdebug;
106+
} else {
108107
throw new PHP_CodeCoverage_Exception('No code coverage driver available');
109108
}
110-
111-
$driver = new PHP_CodeCoverage_Driver_Xdebug;
112109
}
113110

114111
if ($filter === null) {
@@ -231,9 +228,35 @@ public function start($id, $clear = false)
231228

232229
$this->currentId = $id;
233230

234-
$this->driver->start();
231+
$this->driver->start_new();
235232
}
233+
234+
/**
235+
* Start collection of code coverage information.
236+
*
237+
* @param mixed $id
238+
* @param boolean $clear
239+
* @throws PHP_CodeCoverage_Exception
240+
*/
241+
public function start_new($id, $clear = false)
242+
{
243+
"CodeCoveage.php : echo Start success \n";
244+
245+
if (!is_bool($clear)) {
246+
throw PHP_CodeCoverage_Util_InvalidArgumentHelper::factory(
247+
1,
248+
'boolean'
249+
);
250+
}
236251

252+
if ($clear) {
253+
$this->clear();
254+
}
255+
256+
$this->currentId = $id;
257+
"CodeCoveage.php : echo Start success \n";
258+
$this->driver->start_new();
259+
}
237260
/**
238261
* Stop collection of code coverage information.
239262
*
@@ -260,10 +283,49 @@ public function stop($append = true, $linesToBeCovered = array(), array $linesTo
260283
}
261284

262285
$data = $this->driver->stop();
263-
$this->append($data, null, $append, $linesToBeCovered, $linesToBeUsed);
264-
286+
$data2 = array();
287+
288+
foreach ($data as $key => $arr_data){
289+
if(isset($arr_data['lines'])){
290+
//var_dump(strstr($key , "/vendor/"));
291+
if(strstr($key , "vendor")){
292+
continue;
293+
} else {
294+
//echo "$key\n\n";
295+
$data2[$key] = $arr_data['lines'];
296+
}
297+
}
298+
299+
}
300+
$this->append($data2, null, $append, $linesToBeCovered, $linesToBeUsed);
265301
$this->currentId = null;
266302

303+
304+
$arr_data = array();
305+
306+
if(file_exists(dirname(__FILE__) . "/data.json")){
307+
$str_data = file_get_contents(dirname(__FILE__) . "/data.json");
308+
$arr_data = json_decode($str_data , true);
309+
}
310+
if(is_array($arr_data)){
311+
//$data2 = array_merge($arr_data, $data2);
312+
foreach ($data as $key => $value) {
313+
if(!isset($arr_data[$key])){
314+
$arr_data[$key] = $value;
315+
} else {
316+
$arr_data[$key] = $value;
317+
}
318+
319+
}
320+
321+
}
322+
323+
$fp = fopen(dirname(__FILE__) . "/data.json", "w+");
324+
//var_dump($arr_data);
325+
//echo "\n\n\n\n";
326+
$str = json_encode($arr_data);
327+
fwrite($fp, $str);
328+
fclose($fp);
267329
return $data;
268330
}
269331

@@ -294,7 +356,8 @@ public function append(array $data, $id = null, $append = true, $linesToBeCovere
294356
if (!$append) {
295357
return;
296358
}
297-
359+
//var_dump($data);
360+
298361
if ($id != 'UNCOVERED_FILES_FROM_WHITELIST') {
299362
$this->applyCoversAnnotationFilter(
300363
$data,
@@ -343,6 +406,7 @@ public function append(array $data, $id = null, $append = true, $linesToBeCovere
343406
}
344407
}
345408
}
409+
//var_dump($data);
346410
}
347411

348412
/**
@@ -375,14 +439,6 @@ public function merge(PHP_CodeCoverage $that)
375439
}
376440

377441
$this->tests = array_merge($this->tests, $that->getTests());
378-
379-
$this->filter->setBlacklistedFiles(
380-
array_merge($this->filter->getBlacklistedFiles(), $that->filter()->getBlacklistedFiles())
381-
);
382-
383-
$this->filter->setWhitelistedFiles(
384-
array_merge($this->filter->getWhitelistedFiles(), $that->filter()->getWhitelistedFiles())
385-
);
386442
}
387443

388444
/**
@@ -491,22 +547,6 @@ public function setProcessUncoveredFilesFromWhitelist($flag)
491547
$this->processUncoveredFilesFromWhitelist = $flag;
492548
}
493549

494-
/**
495-
* @param boolean $flag
496-
* @throws PHP_CodeCoverage_Exception
497-
*/
498-
public function setDisableIgnoredLines($flag)
499-
{
500-
if (!is_bool($flag)) {
501-
throw PHP_CodeCoverage_Util_InvalidArgumentHelper::factory(
502-
1,
503-
'boolean'
504-
);
505-
}
506-
507-
$this->disableIgnoredLines = $flag;
508-
}
509-
510550
/**
511551
* Applies the @covers annotation filtering.
512552
*
@@ -682,10 +722,6 @@ private function getLinesToBeIgnored($filename)
682722
$lines = file($filename);
683723
$numLines = count($lines);
684724

685-
if ($this->disableIgnoredLines) {
686-
return $this->ignoredLines[$filename];
687-
}
688-
689725
foreach ($lines as $index => $line) {
690726
if (!trim($line)) {
691727
$this->ignoredLines[$filename][] = $index + 1;
@@ -736,7 +772,7 @@ private function getLinesToBeIgnored($filename)
736772

737773
// A DOC_COMMENT token or a COMMENT token starting with "/*"
738774
// does not contain the final \n character in its text
739-
if (isset($lines[$i-1]) && 0 === strpos($_token, '/*') && '*/' === substr(trim($lines[$i-1]), -2)) {
775+
if (0 === strpos($_token, '/*') && '*/' === substr(trim($lines[$i-1]), -2)) {
740776
$this->ignoredLines[$filename][] = $i;
741777
}
742778
}

src/CodeCoverage/.DS_Store

6 KB
Binary file not shown.

src/CodeCoverage/Driver/HHVM.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/*
3+
* This file is part of the PHP_CodeCoverage package.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
/**
12+
* Driver for HHVM's code coverage functionality.
13+
*
14+
* @category PHP
15+
* @package CodeCoverage
16+
* @author Sebastian Bergmann <[email protected]>
17+
* @copyright Sebastian Bergmann <[email protected]>
18+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
19+
* @link http://github.com/sebastianbergmann/php-code-coverage
20+
* @since Class available since Release 1.3.0
21+
* @codeCoverageIgnore
22+
*/
23+
class PHP_CodeCoverage_Driver_HHVM implements PHP_CodeCoverage_Driver
24+
{
25+
/**
26+
* Constructor.
27+
*/
28+
public function __construct()
29+
{
30+
if (!defined('HHVM_VERSION')) {
31+
throw new PHP_CodeCoverage_Exception('This driver requires HHVM');
32+
}
33+
}
34+
35+
/**
36+
* Start collection of code coverage information.
37+
*/
38+
public function start()
39+
{
40+
fb_enable_code_coverage();
41+
}
42+
43+
/**
44+
* Stop collection of code coverage information.
45+
*
46+
* @return array
47+
*/
48+
public function stop()
49+
{
50+
$codeCoverage = fb_get_code_coverage(true);
51+
52+
fb_disable_code_coverage();
53+
54+
return $codeCoverage;
55+
}
56+
}

src/CodeCoverage/Driver/Xdebug.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* @since Class available since Release 1.0.0
2121
* @codeCoverageIgnore
2222
*/
23+
24+
ini_set('memory_limit','1024M');
2325
class PHP_CodeCoverage_Driver_Xdebug implements PHP_CodeCoverage_Driver
2426
{
2527
/**
@@ -44,7 +46,18 @@ public function __construct()
4446
*/
4547
public function start()
4648
{
47-
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
49+
// xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
50+
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );
51+
}
52+
53+
/**
54+
* Start collection of code coverage information.
55+
* with xdebug cc branch check
56+
*/
57+
public function start_new()
58+
{
59+
// xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
60+
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE |XDEBUG_CC_BRANCH_CHECK);
4861
}
4962

5063
/**

src/CodeCoverage/Report/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)