diff options
Diffstat (limited to 'tests/ConfigurationTest.php')
| -rw-r--r-- | tests/ConfigurationTest.php | 60 |
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); + } +} |