Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // PHPUnit example use PHPUnit\Framework\TestCase; class OrderServiceTest extends TestCase { public function test_sends_confirmation_email(): void { // Create mock for the interface $mailer = $this->createMock(MailerInterface::class); // Expect send() to be called once with specific args $mailer->expects($this->once()) ->method("send") ->with("user@example.com", "Order Confirmed", $this->anything()) ->willReturn(true); $service = new OrderService($mailer); $service->processOrder(["id" => 1, "email" => "user@example.com"]); // PHPUnit verifies the mock expectations automatically } }
Result
Open