59 lines
1.7 KiB
PHP
59 lines
1.7 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 Illuminate\Support\Facades\Config;
|
|
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;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
use CreatesApplication;
|
|
|
|
#[\Override]
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Config::set('purifier.cachePath', sys_get_temp_dir() . '/purifier-testing-' . get_current_user());
|
|
|
|
$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);
|
|
}
|
|
}
|