Conditions | 1 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 43 |
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); |
||
20 | public function testSend(): void |
||
21 | { |
||
22 | $apiClient = $this->getMockBuilder(ApiClient::class) |
||
23 | ->disableOriginalConstructor() |
||
24 | ->getMock(); |
||
25 | |||
26 | $apiClient->expects(self::once())->method('post') |
||
27 | ->with('button/init', [ |
||
28 | 'merchantId' => '012345', |
||
29 | 'orderNo' => '123456789', |
||
30 | 'clientIp' => '127.0.0.1', |
||
31 | 'totalAmount' => 12000, |
||
32 | 'currency' => 'CZK', |
||
33 | 'returnUrl' => 'https://www.example.com/return', |
||
34 | 'returnMethod' => 'GET', |
||
35 | 'brand' => 'csob', |
||
36 | 'language' => 'EN', |
||
37 | ]) |
||
38 | ->willReturn( |
||
39 | new Response(ResponseCode::get(ResponseCode::S200_OK), [ |
||
40 | 'payId' => '123456789', |
||
41 | 'dttm' => '20140425131559', |
||
42 | 'resultCode' => 0, |
||
43 | 'resultMessage' => 'OK', |
||
44 | 'paymentStatus' => 1, |
||
45 | 'redirect' => [ |
||
46 | 'method' => 'GET', |
||
47 | 'url' => 'https://platebnibrana.csob.cz/pay/vasobchod.cz/2c72d818-9788-45a1-878a-9db2a706edc5/pt-detect/csob', |
||
48 | ], |
||
49 | ]) |
||
50 | ); |
||
51 | |||
52 | /** @var ApiClient $apiClient */ |
||
53 | $paymentRequest = new PaymentButtonRequest( |
||
54 | '012345', |
||
55 | '123456789', |
||
56 | '127.0.0.1', |
||
57 | new Price(12000, Currency::get(Currency::CZK)), |
||
58 | 'https://www.example.com/return', |
||
59 | HttpMethod::get(HttpMethod::GET), |
||
60 | PaymentButtonBrand::get(PaymentButtonBrand::CSOB), |
||
61 | null, |
||
62 | Language::get(Language::EN) |
||
63 | ); |
||
64 | |||
65 | $paymentButtonResponse = $paymentRequest->send($apiClient); |
||
66 | |||
67 | self::assertSame('123456789', $paymentButtonResponse->getPayId()); |
||
68 | self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentButtonResponse->getResponseDateTime()); |
||
69 | self::assertEquals(ResultCode::get(ResultCode::C0_OK), $paymentButtonResponse->getResultCode()); |
||
70 | self::assertSame('OK', $paymentButtonResponse->getResultMessage()); |
||
71 | self::assertEquals(PaymentStatus::get(PaymentStatus::S1_CREATED), $paymentButtonResponse->getPaymentStatus()); |
||
72 | self::assertSame('https://platebnibrana.csob.cz/pay/vasobchod.cz/2c72d818-9788-45a1-878a-9db2a706edc5/pt-detect/csob', $paymentButtonResponse->getRedirectUrl()); |
||
73 | self::assertSame(HttpMethod::get(HttpMethod::GET), $paymentButtonResponse->getRedirectMethod()); |
||
74 | self::assertNull($paymentButtonResponse->getRedirectParams()); |
||
75 | } |
||
78 |