1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpLightningTest\Unit\Config; |
6
|
|
|
|
7
|
|
|
use PhpLightning\Config\Backend\LnBitsBackendConfig; |
8
|
|
|
use PhpLightning\Config\LightningConfig; |
9
|
|
|
use PhpLightning\Shared\Value\SendableRange; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
final class LightningConfigTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function test_default_values(): void |
15
|
|
|
{ |
16
|
|
|
$config = new LightningConfig(); |
17
|
|
|
|
18
|
|
|
self::assertSame([], $config->jsonSerialize()); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function test_mode(): void |
22
|
|
|
{ |
23
|
|
|
$config = (new LightningConfig()) |
24
|
|
|
->setMode('test'); |
25
|
|
|
|
26
|
|
|
self::assertSame([ |
27
|
|
|
'mode' => 'test', |
28
|
|
|
], $config->jsonSerialize()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function test_domain_with_scheme(): void |
32
|
|
|
{ |
33
|
|
|
$config = (new LightningConfig()) |
34
|
|
|
->setDomain('https://your-domain.com'); |
35
|
|
|
|
36
|
|
|
self::assertSame([ |
37
|
|
|
'domain' => 'your-domain.com', |
38
|
|
|
], $config->jsonSerialize()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function test_domain_without_scheme(): void |
42
|
|
|
{ |
43
|
|
|
$config = (new LightningConfig()) |
44
|
|
|
->setDomain('your-domain.com'); |
45
|
|
|
|
46
|
|
|
self::assertSame([ |
47
|
|
|
'domain' => 'your-domain.com', |
48
|
|
|
], $config->jsonSerialize()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function test_receiver(): void |
52
|
|
|
{ |
53
|
|
|
$config = (new LightningConfig()) |
54
|
|
|
->setReceiver('custom-receiver'); |
55
|
|
|
|
56
|
|
|
self::assertSame([ |
57
|
|
|
'receiver' => 'custom-receiver', |
58
|
|
|
], $config->jsonSerialize()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function test_sendable_range(): void |
62
|
|
|
{ |
63
|
|
|
$config = (new LightningConfig()) |
64
|
|
|
->setSendableRange(1_000, 5_000); |
|
|
|
|
65
|
|
|
|
66
|
|
|
self::assertEquals([ |
67
|
|
|
'sendable-range' => SendableRange::withMinMax(1_000, 5_000), |
68
|
|
|
], $config->jsonSerialize()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function test_ln_bits_backend(): void |
72
|
|
|
{ |
73
|
|
|
$config = (new LightningConfig()) |
74
|
|
|
->addBackend( |
75
|
|
|
(new LnBitsBackendConfig()) |
76
|
|
|
->setApiEndpoint('http://localhost:5000') |
77
|
|
|
->setApiKey('XYZ'), |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
self::assertEquals([ |
81
|
|
|
'backends' => [ |
82
|
|
|
'lnbits' => [ |
83
|
|
|
'api_endpoint' => 'http://localhost:5000', |
84
|
|
|
'api_key' => 'XYZ', |
85
|
|
|
], |
86
|
|
|
], |
87
|
|
|
], $config->jsonSerialize()); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|