-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigTest.php
More file actions
58 lines (47 loc) · 1.68 KB
/
Copy pathConfigTest.php
File metadata and controls
58 lines (47 loc) · 1.68 KB
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
<?php
declare(strict_types=1);
namespace Stack0\Tests\Unit;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Stack0\Config;
final class ConfigTest extends TestCase
{
#[Test]
public function it_creates_config_from_array_with_defaults(): void
{
$config = Config::from(['apiKey' => 'sk_test_123']);
$this->assertSame('sk_test_123', $config->apiKey);
$this->assertSame('https://api.stack0.dev/v1', $config->baseUrl);
$this->assertNull($config->cdnUrl);
}
#[Test]
public function it_creates_config_from_array_with_custom_values(): void
{
$config = Config::from([
'apiKey' => 'sk_test_456',
'baseUrl' => 'https://custom.api.dev/v1/',
'cdnUrl' => 'https://cdn.custom.dev/',
]);
$this->assertSame('sk_test_456', $config->apiKey);
$this->assertSame('https://custom.api.dev/v1', $config->baseUrl);
$this->assertSame('https://cdn.custom.dev', $config->cdnUrl);
}
#[Test]
public function it_returns_same_instance_when_given_config_object(): void
{
$original = new Config(apiKey: 'sk_test_789', baseUrl: 'https://api.example.com');
$result = Config::from($original);
$this->assertSame($original, $result);
}
#[Test]
public function it_strips_trailing_slashes_from_urls(): void
{
$config = new Config(
apiKey: 'sk_test',
baseUrl: 'https://api.stack0.dev/v1///',
cdnUrl: 'https://cdn.stack0.dev///',
);
$this->assertSame('https://api.stack0.dev/v1', $config->baseUrl);
$this->assertSame('https://cdn.stack0.dev', $config->cdnUrl);
}
}