Passed
Push — main ( 756af1...e120fa )
by Chema
03:55 queued 01:19
created

ies()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
cc 1
rs 10
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\Invoice\InvoiceDependencyProvider;
15
use PhpLightning\Invoice\InvoiceFacade;
16
use PhpLightningTest\Feature\Fake\FakeHttpApi;
17
use PHPUnit\Framework\TestCase;
18
19
final class InvoiceFacadeTest extends TestCase
20
{
21
    private InvoiceFacade $facade;
22
23
    protected function setUp(): void
24
    {
25
        $this->facade = new InvoiceFacade();
26
    }
27
28
    public function test_get_get_callback_url(): void
29
    {
30
        $this->bootstrapGacela();
31
        $this->mockLnPaymentRequest();
32
33
        $json = $this->facade->getCallbackUrl('username');
34
35
        self::assertEquals([
36
            'callback' => 'https://callback.url/receiver',
37
            'maxSendable' => 10_000,
0 ignored issues
show
Bug introduced by
The constant PhpLightningTest\Feature\10_000 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38
            'minSendable' => 1_000,
0 ignored issues
show
Bug introduced by
The constant PhpLightningTest\Feature\1_000 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
39
            'metadata' => '[["text/plain","Pay to [email protected]"],["text/identifier","[email protected]"]]',
40
            'tag' => 'payRequest',
41
            'commentAllowed' => false,
42
        ], $json);
43
    }
44
45
    public function test_ln_bits_feature(): void
46
    {
47
        $this->bootstrapGacela();
48
        $this->mockLnPaymentRequest();
49
50
        $json = $this->facade->generateInvoice('username', 2_000, 'lnbits');
0 ignored issues
show
Bug introduced by
The constant PhpLightningTest\Feature\2_000 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Unused Code introduced by
The call to PhpLightning\Invoice\Inv...cade::generateInvoice() has too many arguments starting with 'lnbits'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        /** @scrutinizer ignore-call */ 
51
        $json = $this->facade->generateInvoice('username', 2_000, 'lnbits');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
51
52
        self::assertEquals([
53
            'pr' => 'lnbc10u1pjzh489...fake payment_request',
54
            'status' => 'OK',
55
            'successAction' => [
56
                'tag' => 'message',
57
                'message' => 'Payment received!',
58
            ],
59
            'routes' => [],
60
            'disposable' => false,
61
            'reason' => '',
62
        ], $json);
63
    }
64
65
    private function bootstrapGacela(): void
66
    {
67
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
68
            $config->resetInMemoryCache();
69
            $config->addAppConfigKeyValues(
70
                (new LightningConfig())
0 ignored issues
show
Bug introduced by
The call to PhpLightning\Config\LightningConfig::addBackend() has too few arguments starting with backendConfig. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
                    ->/** @scrutinizer ignore-call */ addBackend(

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
71
                    ->setCallbackUrl('https://callback.url/receiver')
72
                    ->setDomain('domain.com')
73
                    ->setReceiver('receiver')
74
                    ->setSendableRange(1_000, 10_000)
0 ignored issues
show
Bug introduced by
The constant PhpLightningTest\Feature\1_000 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PhpLightningTest\Feature\10_000 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
75
                    ->addBackend(
76
                        (new LnBitsBackendConfig())
0 ignored issues
show
Bug introduced by
new PhpLightning\Config\...000')->setApiKey('XYZ') of type PhpLightning\Config\Backend\LnBitsBackendConfig is incompatible with the type string expected by parameter $username of PhpLightning\Config\LightningConfig::addBackend(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
                        /** @scrutinizer ignore-type */ (new LnBitsBackendConfig())
Loading history...
77
                            ->setApiEndpoint('http://localhost:5000')
78
                            ->setApiKey('XYZ'),
79
                    )->jsonSerialize(),
80
            );
81
        });
82
    }
83
84
    private function mockLnPaymentRequest(): void
85
    {
86
        AnonymousGlobal::overrideExistingResolvedClass(
87
            InvoiceDependencyProvider::class,
88
            new class() extends AbstractDependencyProvider {
89
                public function provideModuleDependencies(Container $container): void
90
                {
91
                    $container->set(InvoiceDependencyProvider::HTTP_API, static fn () => new FakeHttpApi());
92
                }
93
            },
94
        );
95
    }
96
}
97