testThrowsIfRequestInvalid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 9.296
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bip70\Test\Client;
6
7
use Bip70\Client\Exception\ProtocolException;
8
use Bip70\Client\GuzzleHttpClient;
9
use Bip70\Client\NetworkConfig\BitcoinNetworkConfig;
10
use Bip70\X509\RequestValidation;
11
use Bip70\X509\TrustStoreLoader;
12
use GuzzleHttp\Handler\MockHandler;
13
use GuzzleHttp\HandlerStack;
14
use GuzzleHttp\Middleware;
15
use GuzzleHttp\Psr7\Response;
16
use PHPUnit\Framework\TestCase;
17
use X509\CertificationPath\PathValidation\PathValidationConfig;
18
19
class RejectsInvalidPaymentRequestTest extends TestCase
20
{
21
    public function testThrowsIfRequestInvalid()
22
    {
23
        $container = [];
24
        $history = Middleware::history($container);
25
26
        $handler = new MockHandler([
27
            // response to our GET PAYMENTREQUEST request
28
            new Response(200, [
29
                'Content-Type' => [
30
                    'application/bitcoin-paymentrequest',
31
                ]
32
            ], "GET")
33
        ]);
34
35
        $stack = HandlerStack::create($handler);
36
        $stack->push($history);
37
38
        $mockClient = new \GuzzleHttp\Client([
39
            'handler' => $stack,
40
        ]);
41
42
        $client = new GuzzleHttpClient($mockClient);
43
44
        $requestUrl = "https://development.bip70.local/invoice/1";
45
46
        // 10/12/2017 ish
47
        $now = new \DateTimeImmutable();
48
        $now = $now->setTimestamp(1509692666);
49
50
        $networkConfig = new BitcoinNetworkConfig();
51
52
        $validationConfig = new PathValidationConfig($now, 10);
53
        $validator = new RequestValidation($validationConfig, TrustStoreLoader::fromSystem());
54
55
        $this->expectException(ProtocolException::class);
56
        $this->expectExceptionMessage("Failed to decode payment request");
57
58
        $client->getRequest($requestUrl, $validator, $networkConfig);
59
    }
60
}
61