Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php use PHPUnit\Framework\TestCase; class UserServiceTest extends TestCase { public function test_throws_not_found_exception(): void { $service = new UserService($this->createMock(UserRepository::class)); $this->expectException(NotFoundException::class); $this->expectExceptionMessage("User 999 not found"); $this->expectExceptionCode(404); $service->getUser(999); } public function test_throws_on_invalid_email(): void { $this->expectException(ValidationException::class); new User("", "not-an-email"); } }
Result
Open