83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Factory;
|
|
|
|
use GuzzleHttp\Psr7\Uri;
|
|
use Psr\Log\NullLogger;
|
|
use Uwil\ArcadiaApiPhpClient\Auth\ClientIdentifier;
|
|
use Uwil\ArcadiaApiPhpClient\Auth\ClientSecret;
|
|
use Uwil\ArcadiaApiPhpClient\Factory\ApiClientFactory;
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiConfig;
|
|
use Uwil\ArcadiaKiotaOpenApiClient\ApiClient;
|
|
|
|
describe('ApiClientFactory', function () {
|
|
it('creates ApiClient with default configuration', function () {
|
|
// GIVEN
|
|
$config = new ApiConfig(
|
|
endpoint: new Uri('https://api.example.com'),
|
|
apiKey: new ClientIdentifier('my-client-id'),
|
|
secret: new ClientSecret('my-secret-key'),
|
|
);
|
|
$factory = new ApiClientFactory($config);
|
|
|
|
// WHEN
|
|
$client = $factory->createClient();
|
|
|
|
// THEN
|
|
expect($client)->toBeInstanceOf(ApiClient::class);
|
|
});
|
|
|
|
it('creates ApiClient with logger attached', function () {
|
|
// GIVEN
|
|
$config = new ApiConfig(
|
|
endpoint: new Uri('https://api.example.com'),
|
|
apiKey: new ClientIdentifier('my-client-id'),
|
|
secret: new ClientSecret('my-secret-key'),
|
|
logger: new NullLogger(),
|
|
);
|
|
$factory = new ApiClientFactory($config);
|
|
|
|
// WHEN
|
|
$client = $factory->createClient();
|
|
|
|
// THEN
|
|
expect($client)->toBeInstanceOf(ApiClient::class);
|
|
});
|
|
|
|
it('creates ApiClient with self-signed certificates allowed', function () {
|
|
// GIVEN
|
|
$config = new ApiConfig(
|
|
endpoint: new Uri('https://api.example.com'),
|
|
apiKey: new ClientIdentifier('my-client-id'),
|
|
secret: new ClientSecret('my-secret-key'),
|
|
ignoreSelfSignedCert: true,
|
|
);
|
|
$factory = new ApiClientFactory($config);
|
|
|
|
// WHEN
|
|
$client = $factory->createClient();
|
|
|
|
// THEN
|
|
expect($client)->toBeInstanceOf(ApiClient::class);
|
|
});
|
|
|
|
it('creates ApiClient with custom retry options', function () {
|
|
// GIVEN
|
|
$config = new ApiConfig(
|
|
endpoint: new Uri('https://api.example.com'),
|
|
apiKey: new ClientIdentifier('my-client-id'),
|
|
secret: new ClientSecret('my-secret-key'),
|
|
maxRetries: 5,
|
|
retryDelaySeconds: 2,
|
|
);
|
|
$factory = new ApiClientFactory($config);
|
|
|
|
// WHEN
|
|
$client = $factory->createClient();
|
|
|
|
// THEN
|
|
expect($client)->toBeInstanceOf(ApiClient::class);
|
|
});
|
|
});
|