Skip to content

Instantly share code, notes, and snippets.

@bschaeffer
Created May 23, 2011 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bschaeffer/986991 to your computer and use it in GitHub Desktop.
Save bschaeffer/986991 to your computer and use it in GitHub Desktop.
Example of PHPUnit @Covers ClassName and 100% code coverage reporting.
<?php
# ./MyLib/Exception.php
namespace MyLib;
class Exception extends \Exception {}
<?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);
}
}
<!-- ./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