Created
May 23, 2011 16:26
-
-
Save bschaeffer/986991 to your computer and use it in GitHub Desktop.
Example of PHPUnit @Covers ClassName and 100% code coverage reporting.
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 | |
# ./MyLib/Exception.php | |
namespace MyLib; | |
class Exception extends \Exception {} |
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 | |
# ./Test/MyLib/ExceptionTest.php | |
class ExceptionTest extends PHPUnit_Framework_TestCase { | |
/** | |
* @test | |
* @covers MyLib\Exception // adding this line (or MyLib\Exception::<public>) | |
* // reports 100% code coverage. Removing it is more accurate. | |
*/ | |
public function exception_class_exists() | |
{ | |
$this->assertTrue(class_exists('MyLib\\Exception')); | |
$this->assertInstanceOf('Exception', new MyLib\Exception); | |
} | |
} |
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
<!-- ./phpunit.xml --> | |
<phpunit | |
colors="true" | |
backupStaticAttributes="true" | |
bootstrap="MyLib.php"> | |
<logging> | |
<log | |
type="coverage-html" | |
target="Reports" | |
yui="true" /> | |
</logging> | |
</phpunit> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment