Testing Strategies
Prerequisites: Working with queues & background jobs
A unit test (PHPUnit, from Level 2) verifies one class in isolation; a feature/integration test verifies several real pieces together — in a framework, often a full HTTP request through routing, a controller, and a test database.
class OrderServiceTest extends TestCase
{
public function testAppliesDiscountForLargeOrders(): void
{
$emailSenderMock = $this->createMock(EmailSender::class);
$service = new OrderService($emailSenderMock);
$total = $service->calculateTotal(150.0);
$this->assertEquals(135.0, $total); // 10% off orders over 100
}
}
createMock() stands in for a real dependency, the same role
Mockito/Moq play in Java/C# — letting OrderService's own logic
be tested without a real email provider.