class MyTest extends PHPUnit_Framework_TestCase { public function testAddition() { $this->assertEquals(2+2, 4); } public function testSubtraction() { $this->assertEquals(5-3, 2); } public function testMultiplication() { $this->assertEquals(2*3, 6); } public function testDivision() { $this->assertEquals(10/2, 5); } } $test = new MyTest(); $test->runBare();
class MyTest extends PHPUnit_Framework_TestCase { public function testAddition() { $result = add(2, 2); $this->assertEquals($result, 4); } public function testSubtraction() { $result = subtract(5, 3); $this->assertEquals($result, 2); } /** * @covers add */ public function testAdditionCodeCoverage() { $this->assertEmpty(0, xdebug_get_code_coverage()); } /** * @covers subtract */ public function testSubtractionCodeCoverage() { $this->assertEmpty(0, xdebug_get_code_coverage()); } } function add($a, $b) { return $a + $b; } function subtract($a, $b) { return $a - $b; } $test = new MyTest(); $test->runBare();In this example, the `MyTest` class defines two tests that each call a simple add or subtract function. The `@covers` annotation is used to specify which function each test is covering, and the `xdebug_get_code_coverage()` function is used to generate a code coverage report. By calling `runBare()`, we can analyze the code coverage of our unit tests without any additional overhead or interference. Package library: PHPUnit.