Created
October 4, 2010 12:42
-
-
Save yannooo/609633 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo { | |
public function tested() { | |
return true; | |
} | |
public function untested() { | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'Foo.php'; | |
class FooTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testTested() { | |
$foo = new Foo(); | |
$this->assertEquals(true, $foo->tested()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'FooTest.php'; | |
class FooTestSuite extends PHPUnit_Framework_TestSuite { | |
public static function suite() { | |
$suite = new FooTestSuite('Foo test suite'); | |
$suite->addTestSuite('FooTest'); | |
$suite->addTestSuite('FooTest'); | |
return $suite; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Generating the code coverage report from FooTest.php is fine: statements="2" coveredstatements="1". | |
phpunit --coverage-clover coverage.xml FooTest.php | |
<?xml version="1.0" encoding="UTF-8"?> | |
<coverage generated="1286194796"> | |
<project timestamp="1286194796"> | |
<file name="/Users/yannooo/testcase/Foo.php"> | |
<class name="Foo" namespace="global"> | |
<metrics methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="2" coveredstatements="1" elements="4" coveredelements="2"/> | |
</class> | |
<line num="3" type="method" name="tested" crap="1" count="1"/> | |
<line num="4" type="stmt" count="1"/> | |
<line num="7" type="method" name="untested" crap="2" count="0"/> | |
<line num="8" type="stmt" count="0"/> | |
<metrics loc="9" ncloc="9" classes="1" methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="2" coveredstatements="1" elements="4" coveredelements="2"/> | |
</file> | |
<metrics files="1" loc="9" ncloc="9" classes="1" methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="2" coveredstatements="1" elements="4" coveredelements="2"/> | |
</project> | |
</coverage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When the TestCase is run twice from the test suite the results doesn't account for uncovered statements: statements="1" coveredstatements="1" | |
phpunit --coverage-clover coverage.xml FooTestSuite.php | |
<?xml version="1.0" encoding="UTF-8"?> | |
<coverage generated="1286194842"> | |
<project timestamp="1286194842"> | |
<file name="/Users/yannooo/testcase/Foo.php"> | |
<class name="Foo" namespace="global"> | |
<metrics methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="1" coveredstatements="1" elements="3" coveredelements="2"/> | |
</class> | |
<line num="3" type="method" name="tested" crap="1" count="1"/> | |
<line num="4" type="stmt" count="1"/> | |
<line num="7" type="method" name="untested" crap="1" count="0"/> | |
<metrics loc="9" ncloc="9" classes="1" methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="1" coveredstatements="1" elements="3" coveredelements="2"/> | |
</file> | |
<metrics files="1" loc="9" ncloc="9" classes="1" methods="2" coveredmethods="1" conditionals="0" coveredconditionals="0" statements="1" coveredstatements="1" elements="3" coveredelements="2"/> | |
</project> | |
</coverage> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment