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