fix: bind AttendanceMailerService mock in setUp to prevent controller resolution failure
API CI/CD / Validate (composer + pint) (push) Successful in 2m13s
API CI/CD / Test (PHPUnit) (push) Failing after 2m29s
API CI/CD / Build frontend assets (push) Successful in 2m22s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been cancelled
API CI/CD / Security audit (push) Has been cancelled
API CI/CD / Validate (composer + pint) (push) Successful in 2m13s
API CI/CD / Test (PHPUnit) (push) Failing after 2m29s
API CI/CD / Build frontend assets (push) Successful in 2m22s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been cancelled
API CI/CD / Security audit (push) Has been cancelled
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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user