class MathTest extends PHPUnit_Framework_TestCase { public function testAddition() { $this->assertEquals(2, 1+1); } public function testMultiplication() { $this->assertEquals(6, 2*3); } }
class UserManagerTest extends PHPUnit_Framework_TestCase { public function testUserCreation() { $mailerMock = $this->getMock('Mailer'); $mailerMock->expects($this->once()) ->method('send') ->will($this->returnValue(true)); $userManager = new UserManager($mailerMock); $this->assertTrue($userManager->createUser('example@example.com')); } }In this example, the UserManager class depends on a Mailer class to send email notifications. We create a mock Mailer object using `getMock` and set expectations on its behavior using `expects` and `will`. Then, we pass the mock object to the UserManager constructor to verify that creating a new user triggers the expected behavior. Package library: PHPUnit (mocking functionality)