|
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 PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
final class LightningConfigTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function test_default_values(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$config = new LightningConfig(); |
|
16
|
|
|
|
|
17
|
|
|
self::assertSame([ |
|
18
|
|
|
'mode' => 'test', |
|
19
|
|
|
'backends' => [], |
|
20
|
|
|
], $config->jsonSerialize()); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function test_mode(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$config = (new LightningConfig()) |
|
26
|
|
|
->setMode('prod'); |
|
27
|
|
|
|
|
28
|
|
|
self::assertSame([ |
|
29
|
|
|
'mode' => 'prod', |
|
30
|
|
|
'backends' => [], |
|
31
|
|
|
], $config->jsonSerialize()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function test_domain_with_scheme(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$config = (new LightningConfig()) |
|
37
|
|
|
->setDomain('https://your-domain.com'); |
|
38
|
|
|
|
|
39
|
|
|
self::assertSame([ |
|
40
|
|
|
'mode' => 'test', |
|
41
|
|
|
'backends' => [], |
|
42
|
|
|
'domain' => 'your-domain.com', |
|
43
|
|
|
], $config->jsonSerialize()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function test_domain_without_scheme(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$config = (new LightningConfig()) |
|
49
|
|
|
->setDomain('your-domain.com'); |
|
50
|
|
|
|
|
51
|
|
|
self::assertSame([ |
|
52
|
|
|
'mode' => 'test', |
|
53
|
|
|
'backends' => [], |
|
54
|
|
|
'domain' => 'your-domain.com', |
|
55
|
|
|
], $config->jsonSerialize()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function test_receiver(): void |
|
59
|
|
|
{ |
|
60
|
|
|
$config = (new LightningConfig()) |
|
61
|
|
|
->setReceiver('custom-receiver'); |
|
62
|
|
|
|
|
63
|
|
|
self::assertSame([ |
|
64
|
|
|
'mode' => 'test', |
|
65
|
|
|
'backends' => [], |
|
66
|
|
|
'receiver' => 'custom-receiver', |
|
67
|
|
|
], $config->jsonSerialize()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function test_min_sendable(): void |
|
71
|
|
|
{ |
|
72
|
|
|
$config = (new LightningConfig()) |
|
73
|
|
|
->setMinSendable(100_000); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
self::assertSame([ |
|
76
|
|
|
'mode' => 'test', |
|
77
|
|
|
'backends' => [], |
|
78
|
|
|
'min-sendable' => 100_000, |
|
79
|
|
|
], $config->jsonSerialize()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function test_max_sendable(): void |
|
83
|
|
|
{ |
|
84
|
|
|
$config = (new LightningConfig()) |
|
85
|
|
|
->setMaxSendable(10_000_000_000); |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
self::assertSame([ |
|
88
|
|
|
'mode' => 'test', |
|
89
|
|
|
'backends' => [], |
|
90
|
|
|
'max-sendable' => 10_000_000_000, |
|
91
|
|
|
], $config->jsonSerialize()); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function test_ln_bits_backend(): void |
|
95
|
|
|
{ |
|
96
|
|
|
$config = (new LightningConfig()) |
|
97
|
|
|
->addBackend( |
|
98
|
|
|
(new LnBitsBackendConfig()) |
|
99
|
|
|
->setApiEndpoint('http://localhost:5000') |
|
100
|
|
|
->setApiKey('XYZ'), |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
self::assertSame([ |
|
104
|
|
|
'mode' => 'test', |
|
105
|
|
|
'backends' => [ |
|
106
|
|
|
'lnbits' => [ |
|
107
|
|
|
'api_endpoint' => 'http://localhost:5000', |
|
108
|
|
|
'api_key' => 'XYZ', |
|
109
|
|
|
], |
|
110
|
|
|
], |
|
111
|
|
|
], $config->jsonSerialize()); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|