1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpLightningTest\Unit\Invoice\Domain\BackendInvoice; |
6
|
|
|
|
7
|
|
|
use PhpLightning\Invoice\Domain\BackendInvoice\LnbitsBackendInvoice; |
8
|
|
|
use PhpLightning\Invoice\Domain\Http\HttpApiInterface; |
9
|
|
|
use PhpLightning\Shared\Transfer\InvoiceTransfer; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
final class LnbitsBackendInvoiceTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function test_request_invoice_when_api_returns_null(): void |
15
|
|
|
{ |
16
|
|
|
$httpApi = $this->createStub(HttpApiInterface::class); |
17
|
|
|
$httpApi->method('postRequestInvoice')->willReturn(null); |
18
|
|
|
|
19
|
|
|
$invoice = new LnbitsBackendInvoice($httpApi, [ |
20
|
|
|
'api_endpoint' => 'endpoint', |
21
|
|
|
'api_key' => 'key', |
22
|
|
|
]); |
23
|
|
|
|
24
|
|
|
$actual = $invoice->requestInvoice(100); |
25
|
|
|
$expected = new InvoiceTransfer(error: 'Backend "LnBits" unreachable', status: 'ERROR'); |
26
|
|
|
|
27
|
|
|
self::assertEquals($expected, $actual); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function test_request_invoice_when_api_returns_payment_request(): void |
31
|
|
|
{ |
32
|
|
|
$httpApi = $this->createStub(HttpApiInterface::class); |
33
|
|
|
$httpApi->method('postRequestInvoice')->willReturn([ |
34
|
|
|
'bolt11' => 'ln1234567890', |
35
|
|
|
'status' => 'OK', |
36
|
|
|
]); |
37
|
|
|
|
38
|
|
|
$invoice = new LnbitsBackendInvoice($httpApi, [ |
39
|
|
|
'api_endpoint' => 'endpoint', |
40
|
|
|
'api_key' => 'key', |
41
|
|
|
]); |
42
|
|
|
|
43
|
|
|
$actual = $invoice->requestInvoice(100); |
44
|
|
|
$expected = new InvoiceTransfer(bolt11: 'ln1234567890'); |
45
|
|
|
|
46
|
|
|
self::assertEquals($expected, $actual); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|