1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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);
}
}
|