| Conditions | 1 |
| Paths | 1 |
| Total Lines | 70 |
| Code Lines | 50 |
| 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 declare(strict_types = 1); |
||
| 15 | public function testSend(): void |
||
| 16 | { |
||
| 17 | $apiClient = $this->getMockBuilder(ApiClient::class) |
||
| 18 | ->disableOriginalConstructor() |
||
| 19 | ->getMock(); |
||
| 20 | |||
| 21 | $apiClient->expects(self::once())->method('post') |
||
| 22 | ->with('masterpass/standard/extract', [ |
||
| 23 | 'merchantId' => '012345', |
||
| 24 | 'payId' => '123456789', |
||
| 25 | 'callbackParams' => [ |
||
| 26 | 'mpstatus' => 'success', |
||
| 27 | 'oauthToken' => '6a79bf9e320a0460d08aee7ad154f7dab4e19503', |
||
| 28 | 'checkoutResourceUrl' => 'https://sandbox.api.mastercard.com/masterpass/v6/checkout/616764812', |
||
| 29 | 'oauthVerifier' => 'fc8f41bb76ed7d43ea6d714cb8fdefa606611a7d', |
||
| 30 | ], |
||
| 31 | ]) |
||
| 32 | ->willReturn( |
||
| 33 | new Response(ResponseCode::get(ResponseCode::S200_OK), [ |
||
| 34 | 'payId' => '123456789', |
||
| 35 | 'dttm' => '20140425131559', |
||
| 36 | 'resultCode' => 0, |
||
| 37 | 'resultMessage' => 'OK', |
||
| 38 | 'paymentStatus' => 2, |
||
| 39 | 'checkoutParams' => ['card' => [ |
||
| 40 | 'maskedCln' => '****4145', |
||
| 41 | 'expiration' => '11/19', |
||
| 42 | 'billingAddress' => |
||
| 43 | [ |
||
| 44 | 'city' => 'Praha 1', |
||
| 45 | 'country' => 'CZ', |
||
| 46 | 'line1' => 'Jindřišská 16', |
||
| 47 | 'postalCode' => '11150', |
||
| 48 | ], |
||
| 49 | ], |
||
| 50 | 'shippingAddress' => |
||
| 51 | [ |
||
| 52 | 'recipientName' => 'Jan Novák', |
||
| 53 | 'recipientPhoneNumber' => '+420602123456', |
||
| 54 | 'city' => 'Praha 1', |
||
| 55 | 'country' => 'CZ', |
||
| 56 | 'line1' => 'Dlouhá 23', |
||
| 57 | 'postalCode' => '11150', |
||
| 58 | ], |
||
| 59 | ], |
||
| 60 | ]) |
||
| 61 | ); |
||
| 62 | |||
| 63 | /** @var ApiClient $apiClient */ |
||
| 64 | $paymentRequest = new StandardExtractRequest( |
||
| 65 | '012345', |
||
| 66 | '123456789', |
||
| 67 | [ |
||
| 68 | 'mpstatus' => 'success', |
||
| 69 | 'oauthToken' => '6a79bf9e320a0460d08aee7ad154f7dab4e19503', |
||
| 70 | 'checkoutResourceUrl' => 'https://sandbox.api.mastercard.com/masterpass/v6/checkout/616764812', |
||
| 71 | 'oauthVerifier' => 'fc8f41bb76ed7d43ea6d714cb8fdefa606611a7d', |
||
| 72 | ] |
||
| 73 | ); |
||
| 74 | |||
| 75 | $extractResponse = $paymentRequest->send($apiClient); |
||
| 76 | |||
| 77 | $this->assertInstanceOf(ExtractResponse::class, $extractResponse); |
||
| 78 | $this->assertSame('123456789', $extractResponse->getPayId()); |
||
| 79 | $this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $extractResponse->getResponseDateTime()); |
||
| 80 | $this->assertEquals(ResultCode::get(ResultCode::C0_OK), $extractResponse->getResultCode()); |
||
| 81 | $this->assertSame('OK', $extractResponse->getResultMessage()); |
||
| 82 | $this->assertEquals(PaymentStatus::get(PaymentStatus::S2_IN_PROGRESS), $extractResponse->getPaymentStatus()); |
||
| 83 | $this->assertNotNull($extractResponse->getCheckoutParams()); |
||
| 84 | } |
||
| 85 | |||
| 87 |