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;
|
|
|
|
|
|
2026-10-05 11:56:53 +02:00
|
|
|
use App\Services\CrmService;
|
2026-10-02 12:14:48 +02:00
|
|
|
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
2020-10-30 17:26:00 +01:00
|
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
2026-10-02 12:14:48 +02:00
|
|
|
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;
|
2026-10-02 12:14:48 +02:00
|
|
|
|
|
|
|
|
#[\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);
|
|
|
|
|
}
|
2026-10-05 11:56:53 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
}
|