Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
d1a9e7a7
Commit
d1a9e7a7
authored
Aug 11, 2007
by
meus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding coverage CLI flag to testrunner and updating coverage report
parent
c67cfaf2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
40 deletions
+102
-40
cc.php
tests/cc.php
+89
-24
coverage.txt
tests/coverage.txt
+1
-1
run.php
tests/run.php
+12
-15
No files found.
tests/cc.php
View file @
d1a9e7a7
...
...
@@ -67,10 +67,18 @@ if(isset($_GET["file"])){
class
Doctrine_Coverage_Report
{
const
COVERED
=
1
;
const
MAYBE
=
-
2
;
const
NOTCOVERED
=
-
1
;
private
$path
;
private
$coverage
;
private
$key
;
private
$covered
;
private
$totallines
=
0
;
private
$totalcovered
=
0
;
private
$totalmaybe
=
0
;
private
$totalnotcovered
=
0
;
public
function
__construct
(
$file
)
{
...
...
@@ -87,7 +95,7 @@ class Doctrine_Coverage_Report
$html
=
'<div id="coverage">'
;
if
(
!
isset
(
$this
->
coverage
[
$key
]))
{
echo
'
No coverage for this file</div
>'
;
echo
'
<h2>This file has not been tested!</h2
>'
;
}
$coveredLines
=
$this
->
coverage
[
$key
];
$fileArray
=
file
(
Doctrine
::
getPath
()
.
"/"
.
$fileName
);
...
...
@@ -109,16 +117,84 @@ class Doctrine_Coverage_Report
echo
$html
;
}
public
function
generateNotCoveredFiles
()
{
$it
=
new
RecursiveDirectoryIterator
(
Doctrine
::
getPath
());
$notCoveredArray
=
array
();
foreach
(
new
RecursiveIteratorIterator
(
$it
)
as
$file
){
if
(
strpos
(
$file
->
getPathname
(),
".svn"
)){
continue
;
}
$path
=
Doctrine
::
getPath
()
.
DIRECTORY_SEPERATOR
;
$coveredPath
=
str_replace
(
$path
,
$this
->
path
,
$file
->
getPathname
());
if
(
isset
(
$this
->
coverage
[
$coveredPath
])){
continue
;
}
$class
=
str_replace
(
DIRECTORY_SEPARATOR
,
'_'
,
substr
(
$file
,
strlen
(
$this
->
path
),
-
4
));
if
(
strpos
(
$class
,
'_Interface'
))
{
continue
;
}
if
(
!
class_exists
(
$class
)){
continue
;
}
try
{
$refClass
=
new
ReflectionClass
(
$class
);
}
catch
(
Exception
$e
){
echo
$e
->
getMessage
();
continue
;
}
$lines
=
0
;
$methodLines
=
0
;
foreach
(
$refClass
->
getMethods
()
as
$refMethod
){
if
(
$refMethod
->
getDeclaringClass
()
!=
$refClass
){
continue
;
}
$methodLines
=
$refMethod
->
getEndLine
()
-
$refMethod
->
getStartLine
();
$lines
+=
$methodLines
;
}
if
(
$methodLines
==
0
){
$notCoveredArray
[
$class
]
=
array
(
"covered"
=>
0
,
"maybe"
=>
0
,
"notcovered"
=>
$lines
,
"total"
=>
$lines
,
"percentage"
=>
100
);
}
else
{
$notCoveredArray
[
$class
]
=
array
(
"covered"
=>
0
,
"maybe"
=>
0
,
"notcovered"
=>
$lines
,
"total"
=>
$lines
,
"percentage"
=>
0
);
}
$this
->
totallines
+=
$lines
;
$this
->
totalnotcovered
+=
$lines
;
}
return
$notCoveredArray
;
}
public
function
showSummary
()
{
if
(
isset
(
$_GET
[
"order"
])){
$this
->
sortBy
=
$_GET
[
"order"
];
}
$totallines
=
0
;
$totalcovered
=
0
;
$totalmaybe
=
0
;
$totalnotcovered
=
0
;
$coveredArray
=
$this
->
generateCoverage
();
$notcoveredArray
=
$this
->
generateNotCoveredFiles
();
$coveredArray
=
array_merge
(
$coveredArray
,
$notcoveredArray
);
//lets sort it.
uasort
(
$coveredArray
,
array
(
$this
,
"sortArray"
));
//and flip if it perhaps?
if
(
isset
(
$_GET
[
"desc"
])
&&
$_GET
[
"desc"
]
==
"true"
){
$coveredArray
=
array_reverse
(
$coveredArray
,
true
);
}
//ugly code to print out the result:
echo
"<tr><td>"
.
TOTAL
.
"</td><td>"
.
round
(((
$this
->
totalcovered
+
$this
->
totalmaybe
)
/
$this
->
totallines
)
*
100
,
2
)
.
" % </td><td>
$this->totallines
</td><td>
$this->totalcovered
</td><td>
$this->totalmaybe
</td><td>
$this->totalnotcovered
</td><td></td></tr>"
;
foreach
(
$coveredArray
as
$class
=>
$info
){
$fileName
=
str_replace
(
"_"
,
"/"
,
$class
)
.
".php"
;
echo
"<tr><td>"
.
$class
.
"</td><td>"
.
$info
[
"percentage"
]
.
" % </td><td>"
.
$info
[
"total"
]
.
"</td><td>"
.
$info
[
"covered"
]
.
"</td><td>"
.
$info
[
"maybe"
]
.
"</td><td>"
.
$info
[
"notcovered"
]
.
"</td><td><a href=
\"
cc.php?file="
.
$fileName
.
"
\"
>coverage</a></td></tr>"
;
}
}
public
function
generateCoverage
()
{
$coveredArray
=
array
();
foreach
(
$this
->
coverage
as
$file
=>
$lines
)
{
$pos
=
strpos
(
$file
,
$this
->
path
);
...
...
@@ -142,22 +218,22 @@ class Doctrine_Coverage_Report
$notcovered
=
0
;
foreach
(
$lines
as
$result
){
switch
(
$result
){
case
"1"
:
case
self
::
COVERED
:
$covered
++
;
break
;
case
"-1"
:
case
self
::
NOTCOVERED
:
$notcovered
++
;
break
;
case
"-2"
:
case
self
::
MAYBE
:
$maybe
++
;
break
;
}
}
$covered
--
;
//again we have to remove that last line.
$totallines
+=
$total
;
$totalcovered
+=
$covered
;
$totalnotcovered
+=
$notcovered
;
$totalmaybe
+=
$maybe
;
$t
his
->
t
otallines
+=
$total
;
$t
his
->
t
otalcovered
+=
$covered
;
$t
his
->
t
otalnotcovered
+=
$notcovered
;
$t
his
->
t
otalmaybe
+=
$maybe
;
if
(
$total
===
0
)
{
$total
=
1
;
...
...
@@ -165,18 +241,7 @@ class Doctrine_Coverage_Report
$percentage
=
round
(((
$covered
+
$maybe
)
/
$total
)
*
100
,
2
);
$coveredArray
[
$class
]
=
array
(
"covered"
=>
$covered
,
"maybe"
=>
$maybe
,
"notcovered"
=>
$notcovered
,
"total"
=>
$total
,
"percentage"
=>
$percentage
);
}
//lets sort it
uasort
(
$coveredArray
,
array
(
$this
,
"sortArray"
));
if
(
isset
(
$_GET
[
"desc"
])
&&
$_GET
[
"desc"
]
==
"true"
){
$coveredArray
=
array_reverse
(
$coveredArray
,
true
);
}
echo
"<tr><td>"
.
TOTAL
.
"</td><td>"
.
round
(((
$totalcovered
+
$totalmaybe
)
/
$totallines
)
*
100
,
2
)
.
" % </td><td>
$totallines
</td><td>
$totalcovered
</td><td>
$totalmaybe
</td><td>
$totalnotcovered
</td><td></td></tr>"
;
foreach
(
$coveredArray
as
$class
=>
$info
){
$fileName
=
str_replace
(
"_"
,
"/"
,
$class
)
.
".php"
;
echo
"<tr><td>"
.
$class
.
"</td><td>"
.
$info
[
"percentage"
]
.
" % </td><td>"
.
$info
[
"total"
]
.
"</td><td>"
.
$info
[
"covered"
]
.
"</td><td>"
.
$info
[
"maybe"
]
.
"</td><td>"
.
$info
[
"notcovered"
]
.
"</td><td><a href=
\"
cc.php?file="
.
$fileName
.
"
\"
>coverage</a></td></tr>"
;
}
return
$coveredArray
;
}
public
function
sortArray
(
$a
,
$b
)
...
...
tests/coverage.txt
View file @
d1a9e7a7
This source diff could not be displayed because it is too large. You can
view the blob
instead.
tests/run.php
View file @
d1a9e7a7
...
...
@@ -419,18 +419,15 @@ if(PHP_SAPI === "cli"){
$reporter
=
new
MyReporter
();
}
//use this for normal testing
$test
->
run
(
$reporter
);
/*
*
* Use this code to get code coverage. Then goto cc.php file to see resul
*
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
$test->run($reporter);
$result["path"] = Doctrine::getPath() . DIRECTORY_SEPARATOR;
$result["coverage"] = xdebug_get_code_coverage();
xdebug_stop_code_coverage();
file_put_contents("coverage.txt", serialize($result));
//look at the cc.php file in a browser to see the report
//*/
$argv
=
$_SERVER
[
"argv"
];
if
(
isset
(
$argv
[
1
])
&&
$argv
[
1
]
==
"coverage"
){
xdebug_start_code_coverage
(
XDEBUG_CC_UNUSED
|
XDEBUG_CC_DEAD_CODE
);
$test
->
run
(
$reporter
);
$result
[
"path"
]
=
Doctrine
::
getPath
()
.
DIRECTORY_SEPARATOR
;
$result
[
"coverage"
]
=
xdebug_get_code_coverage
();
xdebug_stop_code_coverage
();
file_put_contents
(
"coverage.txt"
,
serialize
(
$result
));
}
else
{
$test
->
run
(
$reporter
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment