1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace PhpLightningTest\Feature; |
||
6 | |||
7 | use Gacela\Framework\AbstractProvider; |
||
8 | use Gacela\Framework\Bootstrap\GacelaConfig; |
||
9 | use Gacela\Framework\Container\Container; |
||
10 | use Gacela\Framework\Gacela; |
||
11 | use PhpLightning\Config\LightningConfig; |
||
12 | use PhpLightning\Invoice\InvoiceDependencyProvider; |
||
13 | use PhpLightning\Invoice\InvoiceFacade; |
||
14 | use PhpLightningTest\Feature\Fake\FakeHttpApi; |
||
15 | use PHPUnit\Framework\TestCase; |
||
16 | |||
17 | final class InvoiceFacadeTest extends TestCase |
||
18 | { |
||
19 | private InvoiceFacade $facade; |
||
20 | |||
21 | protected function setUp(): void |
||
22 | { |
||
23 | $this->facade = new InvoiceFacade(); |
||
24 | } |
||
25 | |||
26 | public function test_get_get_callback_url(): void |
||
27 | { |
||
28 | $this->bootstrapGacela(); |
||
29 | $this->mockLnPaymentRequest(); |
||
30 | |||
31 | $json = $this->facade->getCallbackUrl('bob'); |
||
32 | |||
33 | self::assertEquals([ |
||
34 | 'callback' => 'https://callback.url/receiver', |
||
35 | 'maxSendable' => 10_000, |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
36 | 'minSendable' => 1_000, |
||
37 | 'metadata' => '[["text/plain","Pay to [email protected]"],["text/identifier","[email protected]"]]', |
||
38 | 'tag' => 'payRequest', |
||
39 | 'commentAllowed' => false, |
||
40 | ], $json); |
||
41 | } |
||
42 | |||
43 | public function test_ln_bits_feature(): void |
||
44 | { |
||
45 | $this->bootstrapGacela(); |
||
46 | $this->mockLnPaymentRequest(); |
||
47 | |||
48 | $json = $this->facade->generateInvoice('alice', 2_000); |
||
49 | |||
50 | self::assertEquals([ |
||
51 | 'bolt11' => 'lnbc10u1p5r9lmwpp53magnx9u5m3f3tnrm36ztj9rfdfhx5ga3zns7mefh2v0svax8uzqcqzyssp54twf429a8cvz6tflw5lt705gfnvuykhdeewey009tugjcuamt38q9q7sqqqqqqqqqqqqqqqqqqqsqqqqqysgqdqqmqz9gxqrrssrzjqwryaup9lh50kkranzgcdnn2fgvx390wgj5jd07rwr3vxeje0glclll4ttz7sp6kpvqqqqlgqqqqqeqqjq0uu89sejjllry5ye43x0v42jn48c6alfc9mfnjla2u6kmwy444pzrjmtu25nk2shshuh2mrqtehygmzya9xg89ppszuuhd9296vvcxspkpwc68', |
||
52 | 'status' => 'pending', |
||
53 | 'successAction' => [ |
||
54 | 'tag' => 'message', |
||
55 | 'message' => 'Payment received!', |
||
56 | ], |
||
57 | 'routes' => [], |
||
58 | 'disposable' => false, |
||
59 | 'memo' => '', |
||
60 | 'error' => null, |
||
61 | ], $json); |
||
62 | } |
||
63 | |||
64 | private function bootstrapGacela(): void |
||
65 | { |
||
66 | Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { |
||
67 | $config->resetInMemoryCache(); |
||
68 | $config->addAppConfigKeyValues( |
||
69 | (new LightningConfig()) // @phpstan-ignore-line |
||
70 | ->setCallbackUrl('https://callback.url/receiver') |
||
71 | ->setDomain('domain.com') |
||
72 | ->setReceiver('receiver') |
||
73 | ->setSendableRange(1_000, 10_000) |
||
74 | ->addBackendsFile(__DIR__ . DIRECTORY_SEPARATOR . 'nostr.json') |
||
75 | ->jsonSerialize(), |
||
76 | ); |
||
77 | }); |
||
78 | } |
||
79 | |||
80 | private function mockLnPaymentRequest(): void |
||
81 | { |
||
82 | Gacela::overrideExistingResolvedClass( |
||
83 | InvoiceDependencyProvider::class, |
||
84 | new class() extends AbstractProvider { |
||
85 | public function provideModuleDependencies(Container $container): void |
||
86 | { |
||
87 | $container->set(InvoiceDependencyProvider::HTTP_API, static fn () => new FakeHttpApi()); |
||
88 | } |
||
89 | }, |
||
90 | ); |
||
91 | } |
||
92 | } |
||
93 |