Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
31 | public function testGetsSignedRequest() |
||
32 | { |
||
33 | $keySigned = PrivateKeyInfo::fromPEM(PEM::fromFile(__DIR__ . "/../../../data/testnet-only-cert-not-valid.key")); |
||
34 | $certs = CertificateBundle::fromPEMBundle(PEMBundle::fromFile(__DIR__ . "/../../../data/testnet-only-cert-not-valid.cabundle.pem")); |
||
35 | $certSigned = $certs->all()[0]; |
||
36 | $certBundle = new CertificateBundle(...array_slice($certs->all(), 1)); |
||
37 | |||
38 | $now = 1509692666; |
||
39 | $details = new PaymentDetails(); |
||
40 | $details->setTime($now); |
||
41 | |||
42 | $requestSigner = new RequestSigner(); |
||
43 | $request = $requestSigner->sign($details, PKIType::X509_SHA256, $keySigned, $certSigned, $certBundle); |
||
44 | $serializedRequest = $request->serialize(); |
||
45 | |||
46 | $container = []; |
||
47 | $history = Middleware::history($container); |
||
48 | |||
49 | $handler = new MockHandler([ |
||
50 | // response to our GET PAYMENTREQUEST request |
||
51 | new Response(200, [ |
||
52 | 'Content-Type' => [ |
||
53 | 'application/bitcoin-paymentrequest', |
||
54 | ] |
||
55 | ], $serializedRequest) |
||
56 | ]); |
||
57 | |||
58 | $stack = HandlerStack::create($handler); |
||
59 | $stack->push($history); |
||
60 | |||
61 | $mockClient = new \GuzzleHttp\Client([ |
||
62 | 'handler' => $stack, |
||
63 | ]); |
||
64 | |||
65 | $client = new GuzzleHttpClient($mockClient); |
||
66 | |||
67 | $requestUrl = "https://development.bip70.local/invoice/1"; |
||
68 | |||
69 | // 10/12/2017 ish |
||
70 | $dtnow = new \DateTimeImmutable(); |
||
71 | $dtnow = $dtnow->setTimestamp($now); |
||
72 | |||
73 | $validationConfig = new PathValidationConfig($dtnow, 10); |
||
74 | $validator = new RequestValidation($validationConfig, TrustStoreLoader::fromSystem()); |
||
75 | $data = $client->getRequest($requestUrl, $validator); |
||
76 | |||
77 | $this->assertInstanceOf(PaymentRequestInfo::class, $data); |
||
78 | $this->assertCount(1, $container); |
||
79 | $this->assertInstanceOf(PathValidationResult::class, $data->pathValidation()); |
||
80 | |||
81 | /** @var RequestInterface $req1 */ |
||
82 | $req1 = $container[0]['request']; |
||
83 | $this->assertEquals($requestUrl, $req1->getUri()); |
||
84 | $this->assertTrue($req1->hasHeader('Accept')); |
||
85 | $this->assertEquals(MIMEType::PAYMENT_REQUEST, $req1->getHeader('Accept')[0]); |
||
86 | |||
87 | /** @var ResponseInterface $res1 */ |
||
88 | $res1 = $container[0]['response']; |
||
89 | $res1->getBody()->rewind(); |
||
90 | $this->assertEquals($serializedRequest, $res1->getBody()->getContents()); |
||
91 | } |
||
92 | } |
||
93 |