Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
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 |
||
32 | public function testPerformsX509IfPkiTypeNotNone() |
||
33 | { |
||
34 | $keySigned = PrivateKeyInfo::fromPEM(PEM::fromFile(__DIR__ . "/../../../data/testnet-only-cert-not-valid.key")); |
||
35 | $certs = CertificateBundle::fromPEMBundle(PEMBundle::fromFile(__DIR__ . "/../../../data/testnet-only-cert-not-valid.cabundle.pem")); |
||
36 | $certSigned = $certs->all()[0]; |
||
37 | $certBundle = new CertificateBundle(...array_slice($certs->all(), 1)); |
||
38 | |||
39 | $now = 1509692666; |
||
40 | $details = new PaymentDetails(); |
||
41 | $details->setTime($now); |
||
42 | |||
43 | $requestSigner = new RequestSigner(); |
||
44 | $request = $requestSigner->sign($details, PKIType::X509_SHA256, $keySigned, $certSigned, $certBundle); |
||
45 | $serializedRequest = $request->serialize(); |
||
46 | |||
47 | $container = []; |
||
48 | $history = Middleware::history($container); |
||
49 | |||
50 | $handler = new MockHandler([ |
||
51 | // response to our GET PAYMENTREQUEST request |
||
52 | new Response(200, [ |
||
53 | 'Content-Type' => [ |
||
54 | 'application/bitcoin-paymentrequest', |
||
55 | ] |
||
56 | ], $serializedRequest) |
||
57 | ]); |
||
58 | |||
59 | $stack = HandlerStack::create($handler); |
||
60 | $stack->push($history); |
||
61 | |||
62 | $mockClient = new \GuzzleHttp\Client([ |
||
63 | 'handler' => $stack, |
||
64 | ]); |
||
65 | |||
66 | $client = new GuzzleHttpClient($mockClient); |
||
67 | |||
68 | $requestUrl = "https://development.bip70.local/invoice/1"; |
||
69 | |||
70 | $networkConfig = new BitcoinNetworkConfig(); |
||
71 | |||
72 | $validator = $this->getMockBuilder(RequestValidation::class) |
||
73 | ->disableOriginalConstructor() |
||
74 | ->getMock(); |
||
75 | |||
76 | $validator->expects($this->once()) |
||
77 | ->method('verifyX509Details') |
||
78 | ->withAnyParameters() |
||
79 | ->willReturnCallback(function () { |
||
80 | return $this->getMockBuilder(PathValidationResult::class) |
||
81 | ->disableOriginalConstructor() |
||
82 | ->getMock(); |
||
83 | }); |
||
84 | $data = $client->getRequest($requestUrl, $validator, $networkConfig); |
||
85 | |||
86 | $this->assertInstanceOf(PaymentRequestInfo::class, $data); |
||
87 | $this->assertEquals($serializedRequest, $data->request()->serialize()); |
||
88 | $this->assertCount(1, $container); |
||
89 | $this->assertInstanceOf(PathValidationResult::class, $data->pathValidation()); |
||
90 | } |
||
91 | |||
155 |