diff --git a/tests/Integration/WithApp/App/Actions/Customers/RegisterCustomerTest.php b/tests/Integration/WithApp/App/Actions/Customers/RegisterCustomerTest.php index 9451fca6..241f65bd 100644 --- a/tests/Integration/WithApp/App/Actions/Customers/RegisterCustomerTest.php +++ b/tests/Integration/WithApp/App/Actions/Customers/RegisterCustomerTest.php @@ -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( diff --git a/tests/TestCase.php b/tests/TestCase.php index d5ffe68f..7de55c2f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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); + } }