ldc-boutique-cnc-sable/tests/TestCase.php

58 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2020-10-30 17:26:00 +01:00
<?php
2026-06-14 21:32:07 +02:00
declare(strict_types=1);
2020-10-30 17:26:00 +01:00
namespace Tests;
use App\Services\CrmService;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
2020-10-30 17:26:00 +01:00
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;
2020-10-30 17:26:00 +01:00
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);
}
2020-10-30 17:26:00 +01:00
}