From 64764fb9fac0227f8e0443e7c7519d73aec275b9 Mon Sep 17 00:00:00 2001 From: Murilo Ijanc Date: Sun, 26 Jul 2026 14:58:55 -0300 Subject: Initial import --- tests/ConfigurationTest.php | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/ConfigurationTest.php (limited to 'tests/ConfigurationTest.php') 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 @@ +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); + } +} -- cgit v1.3