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
|
|
|
} |
67
|
|
|
|
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.