Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
92 | public function testGetsSignedRequest() |
||
93 | { |
||
94 | $keySigned = PrivateKeyInfo::fromPEM(PEM::fromFile(__DIR__ . "/../../../data/testnet-only-cert-not-valid.key")); |
||
95 | $certs = CertificateBundle::fromPEMBundle(PEMBundle::fromFile(__DIR__ . "/../../../data/testnet-only-cert-not-valid.cabundle.pem")); |
||
96 | $certSigned = $certs->all()[0]; |
||
97 | $certBundle = new CertificateBundle(...array_slice($certs->all(), 1)); |
||
98 | |||
99 | $now = 1509692666; |
||
100 | $details = new PaymentDetails(); |
||
101 | $details->setTime($now); |
||
102 | |||
103 | $requestSigner = new RequestSigner(); |
||
104 | $request = $requestSigner->sign($details, PKIType::X509_SHA256, $keySigned, $certSigned, $certBundle); |
||
105 | $serializedRequest = $request->serialize(); |
||
106 | |||
107 | $container = []; |
||
108 | $history = Middleware::history($container); |
||
109 | |||
110 | $handler = new MockHandler([ |
||
111 | // response to our GET PAYMENTREQUEST request |
||
112 | new Response(200, [ |
||
113 | 'Content-Type' => [ |
||
114 | 'application/bitcoin-paymentrequest', |
||
115 | ] |
||
116 | ], $serializedRequest) |
||
117 | ]); |
||
118 | |||
119 | $stack = HandlerStack::create($handler); |
||
120 | $stack->push($history); |
||
121 | |||
122 | $mockClient = new \GuzzleHttp\Client([ |
||
123 | 'handler' => $stack, |
||
124 | ]); |
||
125 | |||
126 | $client = new GuzzleHttpClient($mockClient); |
||
127 | |||
128 | $requestUrl = "https://development.bip70.local/invoice/1"; |
||
129 | |||
130 | // 10/12/2017 ish |
||
131 | $dtnow = new \DateTimeImmutable(); |
||
132 | $dtnow = $dtnow->setTimestamp($now); |
||
133 | $networkConfig = new BitcoinNetworkConfig(); |
||
134 | $validationConfig = new PathValidationConfig($dtnow, 10); |
||
135 | $validator = new RequestValidation($validationConfig, TrustStoreLoader::fromSystem()); |
||
136 | $data = $client->getRequest($requestUrl, $validator, $networkConfig); |
||
137 | |||
138 | $this->assertInstanceOf(PaymentRequestInfo::class, $data); |
||
139 | $this->assertEquals($serializedRequest, $data->request()->serialize()); |
||
140 | $this->assertCount(1, $container); |
||
141 | $this->assertInstanceOf(PathValidationResult::class, $data->pathValidation()); |
||
142 | |||
143 | /** @var RequestInterface $req1 */ |
||
144 | $req1 = $container[0]['request']; |
||
145 | $this->assertEquals($requestUrl, $req1->getUri()); |
||
146 | $this->assertTrue($req1->hasHeader('Accept')); |
||
147 | $this->assertEquals($networkConfig->getPaymentRequestMimeType(), $req1->getHeader('Accept')[0]); |
||
148 | |||
149 | /** @var ResponseInterface $res1 */ |
||
150 | $res1 = $container[0]['response']; |
||
151 | $res1->getBody()->rewind(); |
||
152 | $this->assertEquals($serializedRequest, $res1->getBody()->getContents()); |
||
153 | } |
||
154 | } |
||
155 |