1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpLightningTest\Feature; |
6
|
|
|
|
7
|
|
|
use Gacela\Framework\AbstractDependencyProvider; |
8
|
|
|
use Gacela\Framework\Bootstrap\GacelaConfig; |
9
|
|
|
use Gacela\Framework\ClassResolver\GlobalInstance\AnonymousGlobal; |
10
|
|
|
use Gacela\Framework\Container\Container; |
11
|
|
|
use Gacela\Framework\Gacela; |
12
|
|
|
use PhpLightning\Config\Backend\LnBitsBackendConfig; |
13
|
|
|
use PhpLightning\Config\LightningConfig; |
14
|
|
|
use PhpLightning\Http\Domain\HttpClientInterface; |
15
|
|
|
use PhpLightning\Http\HttpDependencyProvider; |
16
|
|
|
use PhpLightning\Lightning; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
final class LightningFeature extends TestCase |
20
|
|
|
{ |
21
|
|
|
public function test_ln_bits_feature(): void |
22
|
|
|
{ |
23
|
|
|
$this->bootstrapGacela(); |
24
|
|
|
$this->mockLnPaymentRequest(); |
25
|
|
|
|
26
|
|
|
$json = Lightning::generateInvoice(amount: 2_000); |
|
|
|
|
27
|
|
|
|
28
|
|
|
self::assertEquals([ |
29
|
|
|
'pr' => 'lnbc10u1pjzh489...CUSTOM PAYMENT REQUEST', |
30
|
|
|
'status' => 'OK', |
31
|
|
|
'successAction' => [ |
32
|
|
|
'tag' => 'message', |
33
|
|
|
'message' => 'Payment received!', |
34
|
|
|
], |
35
|
|
|
'routes' => [], |
36
|
|
|
'disposable' => false, |
37
|
|
|
], json_decode($json, true)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
private function bootstrapGacela(): void |
41
|
|
|
{ |
42
|
|
|
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { |
43
|
|
|
$config->resetInMemoryCache(); |
44
|
|
|
$config->addAppConfigKeyValues( |
45
|
|
|
(new LightningConfig()) |
46
|
|
|
->setSendableRange(1_000, 10_000) |
|
|
|
|
47
|
|
|
->addBackend( |
48
|
|
|
(new LnBitsBackendConfig()) |
49
|
|
|
->setApiEndpoint('http://localhost:5000') |
50
|
|
|
->setApiKey('XYZ'), |
51
|
|
|
)->jsonSerialize(), |
52
|
|
|
); |
53
|
|
|
}); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function mockLnPaymentRequest(): void |
57
|
|
|
{ |
58
|
|
|
AnonymousGlobal::overrideExistingResolvedClass( |
59
|
|
|
HttpDependencyProvider::class, |
60
|
|
|
new class() extends AbstractDependencyProvider { |
61
|
|
|
public function provideModuleDependencies(Container $container): void |
62
|
|
|
{ |
63
|
|
|
$container->set( |
64
|
|
|
HttpDependencyProvider::HTTP_CLIENT, |
65
|
|
|
static fn () => new class() implements HttpClientInterface { |
66
|
|
|
public function post(string $url, array $options = []): string |
67
|
|
|
{ |
68
|
|
|
return json_encode([ |
69
|
|
|
'payment_request' => 'lnbc10u1pjzh489...CUSTOM PAYMENT REQUEST', |
70
|
|
|
], JSON_THROW_ON_ERROR); |
71
|
|
|
} |
72
|
|
|
}, |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
}, |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|