summaryrefslogtreecommitdiffstats
path: root/tests/ConfigurationTest.php
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-26 14:58:55 -0300
committerMurilo Ijanc <[email protected]>2026-07-26 14:58:55 -0300
commit64764fb9fac0227f8e0443e7c7519d73aec275b9 (patch)
treecb4fc56eeb6ecce53854f9c530609cf01ab3349f /tests/ConfigurationTest.php
downloadphp-1fd1470890518a68130b3b9058fe1bebddca9f07.tar.gz
Initial importv0.1.0
Diffstat (limited to 'tests/ConfigurationTest.php')
-rw-r--r--tests/ConfigurationTest.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/ConfigurationTest.php b/tests/ConfigurationTest.php
new file mode 100644
index 0000000..158d911
--- /dev/null
+++ b/tests/ConfigurationTest.php
@@ -0,0 +1,60 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Cepis\Tests;
+
+use Cepis\Client;
+use PHPUnit\Framework\TestCase;
+
+final class ConfigurationTest extends TestCase
+{
+ public function testTrailingSlashIsNotDuplicated(): void
+ {
+ self::assertSame('http://x', (new Client(baseUrl: 'http://x/'))->baseUrl);
+ self::assertSame('http://x', (new Client(baseUrl: 'http://x///'))->baseUrl);
+ }
+
+ public function testDefaults(): void
+ {
+ $client = new Client();
+
+ self::assertSame(Client::DEFAULT_URL, $client->baseUrl);
+ self::assertSame(3, $client->maxAttempts);
+ self::assertSame(0.5, $client->backoffBase);
+ self::assertSame(8.0, $client->backoffMax);
+ self::assertNull($client->totalTimeout);
+ }
+
+ public function testUserAgentIdentifiesTheLibrary(): void
+ {
+ self::assertStringContainsString(
+ 'cepis-php/' . Client::VERSION,
+ (new Client())->userAgent,
+ );
+ self::assertSame('myapp/1.0', (new Client(userAgent: 'myapp/1.0'))->userAgent);
+ }
+
+ public function testInvalidParameters(): void
+ {
+ foreach ([['maxAttempts' => 0], ['timeout' => 0.0], ['backoffBase' => -1.0]] as $bad) {
+ try {
+ new Client(...$bad);
+ self::fail('expected InvalidArgumentException for ' . json_encode($bad));
+ } catch (\InvalidArgumentException) {
+ self::assertTrue(true);
+ }
+ }
+ }
+
+ public function testDefaultClientIsShared(): void
+ {
+ self::assertSame(Client::default(), Client::default());
+ self::assertSame(Client::DEFAULT_URL, Client::default()->baseUrl);
+ }
+
+ public function testMaxBatchMatchesTheApiLimit(): void
+ {
+ self::assertSame(500, Client::MAX_BATCH);
+ }
+}