LnbitsBackendInvoiceTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 35
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_request_invoice_when_api_returns_payment_request() 0 17 1
A test_request_invoice_when_api_returns_null() 0 14 1
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