Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 39 |
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/checkout', [ |
||
23 | 'merchantId' => '012345', |
||
24 | 'payId' => '123456789', |
||
25 | 'callbackUrl' => 'https://www.vasobchod.cz/masterpass/callback', |
||
26 | 'shippingLocationProfile' => 'SP-0001', |
||
27 | ]) |
||
28 | ->willReturn( |
||
29 | new Response(ResponseCode::get(ResponseCode::S200_OK), [ |
||
30 | 'payId' => '123456789', |
||
31 | 'dttm' => '20140425131559', |
||
32 | 'resultCode' => 0, |
||
33 | 'resultMessage' => 'OK', |
||
34 | 'paymentStatus' => 1, |
||
35 | 'lightboxParams' => [ |
||
36 | 'requestToken' => '6a79bf9e320a0460d08aee7ad154f7dab4e19503', |
||
37 | 'callbackUrl' => 'https://www.vasobchod.cz/masterpass/callback', |
||
38 | 'merchantCheckoutId' => 'a4a6w4vzajswviqy5oeu11irc2e3yb51ws', |
||
39 | 'allowedCardTypes' => 'master,visa', |
||
40 | 'suppressShippingAddressEnable' => 'true', |
||
41 | 'loyaltyEnabled' => 'false', |
||
42 | 'version' => 'v6', |
||
43 | 'shippingLocationProfile' => 'SP-0001', |
||
44 | ], |
||
45 | ]) |
||
46 | ); |
||
47 | |||
48 | /** @var ApiClient $apiClient */ |
||
49 | $paymentRequest = new StandardCheckoutRequest( |
||
50 | '012345', |
||
51 | '123456789', |
||
52 | 'https://www.vasobchod.cz/masterpass/callback', |
||
53 | 'SP-0001' |
||
54 | ); |
||
55 | |||
56 | $checkoutResponse = $paymentRequest->send($apiClient); |
||
57 | |||
58 | $this->assertInstanceOf(CheckoutResponse::class, $checkoutResponse); |
||
59 | $this->assertSame('123456789', $checkoutResponse->getPayId()); |
||
60 | $this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $checkoutResponse->getResponseDateTime()); |
||
61 | $this->assertEquals(ResultCode::get(ResultCode::C0_OK), $checkoutResponse->getResultCode()); |
||
62 | $this->assertSame('OK', $checkoutResponse->getResultMessage()); |
||
63 | $this->assertEquals(PaymentStatus::get(PaymentStatus::S1_CREATED), $checkoutResponse->getPaymentStatus()); |
||
64 | $this->assertNotNull($checkoutResponse->getLightboxParams()); |
||
65 | } |
||
66 | |||
68 |