use PHPUnit\Framework\TestCase; function add($a, $b) { return $a + $b; } class SimpleTest extends TestCase { public function testAdd() { $this->assertEquals(4, add(2, 2)); } }
use PHPUnit\Framework\TestCase; class Calculator { public function add($a, $b) { return $a + $b; } } class CalculatorTest extends TestCase { public function testAdd() { $calculator = new Calculator(); $this->assertEquals(4, $calculator->add(2, 2)); } }This example creates a Calculator class with an add() method that adds two numbers. The CalculatorTest class extends the TestCase class and defines a testAdd() method that tests whether the result of the add() method equals 4. PHPUnit is the package library used in both examples above.