Test Failed
Push — main ( 117601...63d9b1 )
by Chema
11:24
created

InvoiceGeneratorTest::test_successful_payment_request_with_amount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 20
c 3
b 0
f 0
nc 1
nop 0
dl 0
loc 26
rs 9.6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightningTest\Unit\Invoice\Domain\LnAddress;
6
7
use PhpLightning\Invoice\Application\InvoiceGenerator;
8
use PhpLightning\Invoice\Domain\BackendInvoice\BackendInvoiceInterface;
9
use PhpLightning\Shared\Transfer\BackendInvoiceResponse;
10
use PhpLightning\Shared\Value\SendableRange;
11
use PHPUnit\Framework\TestCase;
12
13
final class InvoiceGeneratorTest extends TestCase
14
{
15
    public function test_invalid_amount(): void
16
    {
17
        $invoiceFacade = $this->createStub(BackendInvoiceInterface::class);
18
        $invoiceFacade->method('requestInvoice')->willReturn(new BackendInvoiceResponse());
19
20
        $invoice = new InvoiceGenerator(
21
            $invoiceFacade,
22
            SendableRange::withMinMax(1_000, 3_000),
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting ',' or ')' on line 22 at column 39
Loading history...
23
            'ln@address',
24
        );
25
        $actual = $invoice->generateInvoice(100);
26
27
        self::assertSame([
28
            'status' => 'ERROR',
29
            'reason' => 'Amount is not between minimum and maximum sendable amount',
30
        ], $actual);
31
    }
32
33
    public function test_unknown_backend(): void
34
    {
35
        $invoiceFacade = $this->createStub(BackendInvoiceInterface::class);
36
        $invoiceFacade->method('requestInvoice')
37
            ->willReturn((new BackendInvoiceResponse())
38
                ->setStatus('ERROR')
39
                ->setReason('some reason'));
40
41
        $invoice = new InvoiceGenerator(
42
            $invoiceFacade,
43
            SendableRange::withMinMax(1_000, 3_000),
44
            'ln@address',
45
        );
46
        $actual = $invoice->generateInvoice(2_000);
47
48
        self::assertEquals([
49
            'pr' => '',
50
            'status' => 'ERROR',
51
            'successAction' => [
52
                'tag' => 'message',
53
                'message' => 'Payment received!',
54
            ],
55
            'routes' => [],
56
            'disposable' => false,
57
            'reason' => 'some reason',
58
        ], $actual);
59
    }
60
61
    public function test_successful_payment_request_with_amount(): void
62
    {
63
        $invoiceFacade = $this->createStub(BackendInvoiceInterface::class);
64
        $invoiceFacade->method('requestInvoice')
65
            ->willReturn((new BackendInvoiceResponse())
66
                ->setStatus('OK')
67
                ->setPaymentRequest('ln123456789'));
68
69
        $invoice = new InvoiceGenerator(
70
            $invoiceFacade,
71
            SendableRange::withMinMax(1_000, 3_000),
72
            'ln@address',
73
        );
74
        $actual = $invoice->generateInvoice(2_000);
75
76
        self::assertSame([
77
            'pr' => 'ln123456789',
78
            'status' => 'OK',
79
            'successAction' => [
80
                'tag' => 'message',
81
                'message' => 'Payment received!',
82
            ],
83
            'routes' => [],
84
            'disposable' => false,
85
            'reason' => '',
86
        ], $actual);
87
    }
88
}
89