| Conditions | 1 |
| Paths | 1 |
| Total Lines | 60 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 54 | public function requestCreateCartReorder(CartReorderApiTester $I): void |
||
| 55 | { |
||
| 56 | // Arrange |
||
| 57 | $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer()); |
||
| 58 | |||
| 59 | $saveOrderTransfer = $this->fixtures->getOrderWithSalesUnit(); |
||
| 60 | $requestPayload = [ |
||
| 61 | 'data' => [ |
||
| 62 | 'type' => CartReorderRestApiConfig::RESOURCE_CART_REORDER, |
||
| 63 | 'attributes' => [ |
||
| 64 | 'orderReference' => $saveOrderTransfer->getOrderReferenceOrFail(), |
||
| 65 | ], |
||
| 66 | ], |
||
| 67 | ]; |
||
| 68 | |||
| 69 | // Act |
||
| 70 | $I->sendPost($I->getCartReorderUrl(), $requestPayload); |
||
| 71 | |||
| 72 | // Assert |
||
| 73 | $I->seeResponseCodeIs(HttpCode::CREATED); |
||
| 74 | $I->seeResponseIsJson(); |
||
| 75 | $I->seeResponseMatchesOpenApiSchema(); |
||
| 76 | |||
| 77 | $I->amSure('The returned resource is of correct type.') |
||
| 78 | ->whenI() |
||
| 79 | ->seeResponseDataContainsSingleResourceOfType(CartReorderApiTester::RESOURCE_CARTS); |
||
|
|
|||
| 80 | |||
| 81 | $I->amSure('The returned response data contains correct cart name.') |
||
| 82 | ->whenI() |
||
| 83 | ->assertResponseContainsCorrectCartName( |
||
| 84 | sprintf('Reorder from Order %s', $saveOrderTransfer->getOrderReferenceOrFail()), |
||
| 85 | ); |
||
| 86 | |||
| 87 | $I->amSure('The returned response includes first item.') |
||
| 88 | ->whenI() |
||
| 89 | ->assertResponseContainsItemBySku($this->fixtures->getProductConcreteTransfer()->getSkuOrFail()); |
||
| 90 | $I->amSure('The first item has correct quantity.') |
||
| 91 | ->whenI() |
||
| 92 | ->assertItemHasCorrectQuantity($this->fixtures->getProductConcreteTransfer()->getSkuOrFail(), 1); |
||
| 93 | |||
| 94 | $I->amSure('The returned response includes second item.') |
||
| 95 | ->whenI() |
||
| 96 | ->assertResponseContainsItemBySku($this->fixtures->getProductConcreteTransferWithSalesUnit()->getSkuOrFail()); |
||
| 97 | $I->amSure('The second item has correct quantity.') |
||
| 98 | ->whenI() |
||
| 99 | ->assertItemHasCorrectQuantity( |
||
| 100 | $this->fixtures->getProductConcreteTransferWithSalesUnit()->getSkuOrFail(), |
||
| 101 | 2, |
||
| 102 | ); |
||
| 103 | $I->amSure('The second item has correct sales unit id.') |
||
| 104 | ->whenI() |
||
| 105 | ->assertItemHasIdSalesUnit( |
||
| 106 | $this->fixtures->getProductConcreteTransferWithSalesUnit()->getSkuOrFail(), |
||
| 107 | $this->fixtures->getProductMeasurementSalesUnitTransfer()->getIdProductMeasurementSalesUnitOrFail(), |
||
| 108 | ); |
||
| 109 | $I->amSure('The second item has correct sales unit amount.') |
||
| 110 | ->whenI() |
||
| 111 | ->assertItemHasSalesUnitAmount( |
||
| 112 | $this->fixtures->getProductConcreteTransferWithSalesUnit()->getSkuOrFail(), |
||
| 113 | new Decimal(3), |
||
| 114 | ); |
||
| 117 |