From f3f13f5d016f0e30d4be1c034c49933945fbae27 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 22 Jun 2026 02:15:59 -0400 Subject: [PATCH] fix: bind AttendanceMailerService mock in setUp to prevent controller resolution failure The previous approach of only mocking AttendanceTrackingService in individual tests was not sufficient. The controller is resolved during route middleware gathering (controllerMiddleware), which happens before the test method body executes. By binding the AttendanceMailerService interface to a mock in setUp, the full dependency chain is satisfied regardless of whether the service-level mock is used. --- .../AttendanceTrackingControllerTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Feature/Api/V1/AttendanceTracking/AttendanceTrackingControllerTest.php b/tests/Feature/Api/V1/AttendanceTracking/AttendanceTrackingControllerTest.php index 92969735..37e92e9b 100644 --- a/tests/Feature/Api/V1/AttendanceTracking/AttendanceTrackingControllerTest.php +++ b/tests/Feature/Api/V1/AttendanceTracking/AttendanceTrackingControllerTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Api\V1\AttendanceTracking; +use App\Services\AttendanceTracking\AttendanceMailerService; use App\Services\AttendanceTracking\AttendanceTrackingService; use Mockery; use Mockery\MockInterface; @@ -15,6 +16,19 @@ class AttendanceTrackingControllerTest extends TestCase parent::tearDown(); } + protected function setUp(): void + { + parent::setUp(); + + // Bind the AttendanceMailerService interface to a mock so the + // controller can be instantiated during route middleware gathering + // even when the full service chain is not mocked. + $this->app->instance( + AttendanceMailerService::class, + Mockery::mock(AttendanceMailerService::class) + ); + } + protected function mockService(): MockInterface { $service = Mockery::mock(AttendanceTrackingService::class);