dependencyMock = Mockery::mock('DependencyInterface'); $this->service = new {{ClassName}}($this->dependencyMock); } protected function tearDown(): void { Mockery::close(); parent::tearDown(); } #[Test] public function it_executes_successfully_with_valid_input(): void { // 1. Arrange $input = 'valid_input'; $expectedResult = 'expected_output'; $this->dependencyMock ->shouldReceive('execute') ->once() ->with($input) ->andReturn($expectedResult); // 2. Act $actualResult = $this->service->process($input); // 3. Assert $this->assertSame($expectedResult, $actualResult); } #[Test] public function it_handles_edge_cases_with_null_or_empty_input(): void { // 1. Arrange - Test kịch bản biên với giá trị rỗng/mặc định $fallbackResult = 'default_fallback'; $this->dependencyMock ->shouldReceive('execute') ->once() ->with('') ->andReturn($fallbackResult); // 2. Act $result = $this->service->process(''); // 3. Assert - Xác minh xử lý đúng giá trị biên $this->assertSame($fallbackResult, $result); } #[Test] public function it_throws_exception_and_handles_error_when_dependency_fails(): void { // 1. Arrange - Ép mock ném ngoại lệ để kiểm thử khối catch / exception handling $this->dependencyMock ->shouldReceive('execute') ->once() ->andThrow(new \RuntimeException('Service unavailable')); // 2. Assert Expectation $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Service unavailable'); // 3. Act $this->service->process('invalid_trigger'); } }