toBeInstanceOf(ApiConfig::class); }); it('can instance ApiConfig whit logger and tracer', function () { // GIVEN $logger = new NullLogger(); $tracer = $this->createMock(TracerInterface::class); // WHEN $apiConfig = new ApiConfig( endpoint: new Uri('https://example.com'), apiKey: new ClientIdentifier('test_id'), secret: new ClientSecret('test_secret'), ignoreSelfSignedCert: true, logger: $logger, tracer: $tracer ); // THEN expect($apiConfig)->toBeInstanceOf(ApiConfig::class); }); }); describe('ApiConfig validation rules', function () { it('throws an exception when endpoint is not http or https', function () { // GIVEN $invalidEndpoint = new Uri('ftp://example.com'); $validApiKey = new ClientIdentifier('valid-client-id'); $validSecret = new ClientSecret('valid-client-secret'); // WHEN $createInvalidApiConfig = function () use ($invalidEndpoint, $validApiKey, $validSecret) { new ApiConfig( endpoint: $invalidEndpoint, apiKey: $validApiKey, secret: $validSecret, ignoreSelfSignedCert: true ); }; // THEN expect($createInvalidApiConfig)->toThrow(\InvalidArgumentException::class); }); it('throws an exception when curlTimeOut is not positive', function () { // GIVEN $invalidEndpoint = new Uri('https://example.com'); $validApiKey = new ClientIdentifier('valid-client-id'); $validSecret = new ClientSecret('valid-client-secret'); // WHEN $createInvalidApiConfig = function () use ($invalidEndpoint, $validApiKey, $validSecret) { new ApiConfig( endpoint: $invalidEndpoint, apiKey: $validApiKey, secret: $validSecret, ignoreSelfSignedCert: true, curlTimeOut: 0 ); }; $createInvalidApiConfig2 = function () use ($invalidEndpoint, $validApiKey, $validSecret) { new ApiConfig( endpoint: $invalidEndpoint, apiKey: $validApiKey, secret: $validSecret, ignoreSelfSignedCert: true, curlTimeOut: -1 ); }; // THEN expect($createInvalidApiConfig)->toThrow(\InvalidArgumentException::class); expect($createInvalidApiConfig2)->toThrow(\InvalidArgumentException::class); }); it('throws an exception when maxRetries is negative', function () { // GIVEN $invalidEndpoint = new Uri('https://example.com'); $validApiKey = new ClientIdentifier('valid-client-id'); $validSecret = new ClientSecret('valid-client-secret'); $invalidMaxRetries = -1; // WHEN $createInvalidApiConfig = function () use ($invalidEndpoint, $validApiKey, $validSecret, $invalidMaxRetries) { new ApiConfig( endpoint: $invalidEndpoint, apiKey: $validApiKey, secret: $validSecret, ignoreSelfSignedCert: true, curlTimeOut: 30, maxRetries: $invalidMaxRetries ); }; // THEN expect($createInvalidApiConfig)->toThrow(\InvalidArgumentException::class); }); it('throws an exception when retryDelaySeconds is negative', function () { // GIVEN $invalidEndpoint = new Uri('https://example.com'); $validApiKey = new ClientIdentifier('valid-client-id'); $validSecret = new ClientSecret('valid-client-secret'); $invalidRetryDelaySeconds = -1; // WHEN $createInvalidApiConfig = function () use ($invalidEndpoint, $validApiKey, $validSecret, $invalidRetryDelaySeconds) { new ApiConfig( endpoint: $invalidEndpoint, apiKey: $validApiKey, secret: $validSecret, ignoreSelfSignedCert: true, curlTimeOut: 30, maxRetries: 3, retryDelaySeconds: $invalidRetryDelaySeconds ); }; // THEN expect($createInvalidApiConfig)->toThrow(\InvalidArgumentException::class); }); });