Completed
Push — master ( f64a2b...48aedc )
by thomas
05:58
created

GetsUnsignedRequestTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 0
loc 46
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testGetsUnsignedRequest() 0 43 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bip70\Test\Client;
6
7
use Bip70\Client\GuzzleHttpClient;
8
use Bip70\Client\MIMEType;
9
use Bip70\Client\PaymentRequestInfo;
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 Psr\Http\Message\RequestInterface;
18
use X509\CertificationPath\PathValidation\PathValidationConfig;
19
20
class GetsUnsignedRequestTest extends TestCase
21
{
22
    public function testGetsUnsignedRequest()
23
    {
24
        $container = [];
25
        $history = Middleware::history($container);
26
27
        $handler = new MockHandler([
28
            // response to our GET PAYMENTREQUEST request
29
            new Response(200, [
30
                'Content-Type' => [
31
                    'application/bitcoin-paymentrequest',
32
                ]
33
            ], '')
34
        ]);
35
36
        $stack = HandlerStack::create($handler);
37
        $stack->push($history);
38
39
        $mockClient = new \GuzzleHttp\Client([
40
            'handler' => $stack,
41
        ]);
42
43
        $client = new GuzzleHttpClient($mockClient);
44
45
        $requestUrl = "https://development.bip70.local/invoice/1";
46
47
        // 10/12/2017 ish
48
        $now = new \DateTimeImmutable();
49
        $now = $now->setTimestamp(1509692666);
50
51
        $validationConfig = new PathValidationConfig($now, 10);
52
        $validator = new RequestValidation($validationConfig, TrustStoreLoader::fromSystem());
53
        $data = $client->getRequest($requestUrl, $validator);
54
55
        $this->assertInstanceOf(PaymentRequestInfo::class, $data);
56
        $this->assertCount(1, $container);
57
58
        /** @var RequestInterface $req1 */
59
        $req1 = $container[0]['request'];
60
        $this->assertEquals($requestUrl, $req1->getUri());
61
        $this->assertTrue($req1->hasHeader('Accept'));
62
        $this->assertEquals(MIMEType::PAYMENT_REQUEST, $req1->getHeader('Accept')[0]);
63
        $this->assertNull($data->pathValidation());
64
    }
65
}
66