ldc-boutique-cnc-sable/tests/TestCase.php
Jérémy Munsch 3e4732bcb4
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.
2026-10-27 09:58:59 +01:00

57 lines
1.5 KiB
PHP

<?php
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;
use LDC\LDCCRM\Enums\ApiStatus;
use LDC\LDCCRM\Models\ClientModel;
use LDC\LDCCRM\Transport\ApiInterface;
use LDC\LDCCRM\Transport\Response as CrmResponse;
use LDC\LDCCRM\Utils;
use Mockery;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
#[\Override]
protected function setUp(): void
{
parent::setUp();
$this->mockCrmTransport();
}
private function mockCrmTransport(): void
{
$apiInterface = Mockery::mock(ApiInterface::class);
$apiInterface->shouldReceive('call')->byDefault()->andReturn(
new CrmResponse(
ApiStatus::OK,
new GuzzleResponse(200, [], (string) json_encode([
'version' => Utils::getPackageInfo()['version'],
'data' => [],
]))
)
);
$refClientModel = new \ReflectionProperty(ClientModel::class, 'apiInterface');
$refClientModel->setValue(null, $apiInterface);
$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);
}
}