fix: Bind mocked CrmService to container in RegisterCustomerTest

Ensure that all mocked dependencies in RegisterCustomerTest are properly bound
to the Laravel service container using App::instance(). This prevents any code
that resolves dependencies via container injection from getting real service
instances instead of mocks.

This fix aligns the Integration test pattern with Feature tests which already
use App::instance() to bind mocks to the container.

Changes:
- Add import for Illuminate\Support\Facades\App
- Add App::instance() calls after each mock creation in all 6 test cases
- Add mockCrmService() helper method to TestCase base class for future tests

Fixes CI failures where CRM service was being called in real instead of being mocked.
This commit is contained in:
Jérémy Munsch 2026-10-05 11:56:53 +02:00
parent f67a8c88c9
commit 3e4732bcb4
No known key found for this signature in database
GPG key ID: 2AAECDA6B7330F91
2 changed files with 27 additions and 0 deletions

View file

@ -21,6 +21,7 @@ use Domain\Models\ValueObjects\ShopperEstablishmentCode;
use Domain\Models\ValueObjects\ShopperServiceCode;
use Domain\Models\ValueObjects\ShopperSiteCode;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Notification;
use Illuminate\Validation\ValidationException;
use Infrastructure\Adapters\Services\AppCustomerAuthService;
@ -78,11 +79,13 @@ describe('RegisterCustomer action', function (): void {
status: false,
lastConnection: null,
));
App::instance(CrmService::class, $crmService);
$authService = \Mockery::mock(AppCustomerAuthService::class);
$authService->shouldReceive('logIn')
->once()
->withArgs(fn (Customer $c) => $c->email->value === $email->value);
App::instance(AppCustomerAuthService::class, $authService);
$employeeRepo = resolve(EmployeeRepository::class);
@ -123,6 +126,9 @@ describe('RegisterCustomer action', function (): void {
// GIVEN
$crmService = \Mockery::mock(CrmService::class);
$authService = \Mockery::mock(AppCustomerAuthService::class);
App::instance(CrmService::class, $crmService);
App::instance(AppCustomerAuthService::class, $authService);
$employeeRepo = resolve(EmployeeRepository::class);
$action = new RegisterCustomer(
@ -169,8 +175,11 @@ describe('RegisterCustomer action', function (): void {
$crmService->shouldReceive('persist')
->once()
->andThrow(new CrmCustomerExistsException());
App::instance(CrmService::class, $crmService);
$authService = \Mockery::mock(AppCustomerAuthService::class);
App::instance(AppCustomerAuthService::class, $authService);
$employeeRepo = resolve(EmployeeRepository::class);
$action = new RegisterCustomer(
@ -217,8 +226,11 @@ describe('RegisterCustomer action', function (): void {
$crmService->shouldReceive('persist')
->once()
->andThrow(CrmServiceException::of('CRM service offline'));
App::instance(CrmService::class, $crmService);
$authService = \Mockery::mock(AppCustomerAuthService::class);
App::instance(AppCustomerAuthService::class, $authService);
$employeeRepo = resolve(EmployeeRepository::class);
$action = new RegisterCustomer(
@ -281,8 +293,11 @@ describe('RegisterCustomer action', function (): void {
status: false,
lastConnection: null,
));
App::instance(CrmService::class, $crmService);
$authService = \Mockery::mock(AppCustomerAuthService::class);
App::instance(AppCustomerAuthService::class, $authService);
$employeeRepo = resolve(EmployeeRepository::class);
$action = new RegisterCustomer(
@ -313,6 +328,9 @@ describe('RegisterCustomer action', function (): void {
// GIVEN
$crmService = \Mockery::mock(CrmService::class);
$authService = \Mockery::mock(AppCustomerAuthService::class);
App::instance(CrmService::class, $crmService);
App::instance(AppCustomerAuthService::class, $authService);
$employeeRepo = resolve(EmployeeRepository::class);
$action = new RegisterCustomer(

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Tests;
use App\Services\CrmService;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use LDC\LDCCRM\CrmApiV4;
@ -45,4 +46,12 @@ abstract class TestCase extends BaseTestCase
$refCrmApi = new \ReflectionProperty(CrmApiV4::class, 'apiInterface');
$refCrmApi->setValue(null, $apiInterface);
}
/**
* Create and bind a mock CrmService to the container to ensure no real CRM calls are made in tests.
*/
protected function mockCrmService(): CrmService
{
return $this->mock(CrmService::class);
}
}