Completed
Push — master ( f465c8...ce649b )
by Ilya
52s queued 19s
created

requestCreateCartReorder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 60
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 41
c 1
b 1
f 0
dl 0
loc 60
rs 9.264
cc 1
nc 1
nop 1

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace PyzTest\Glue\CartReorder\RestApi;
11
12
use Codeception\Util\HttpCode;
13
use PyzTest\Glue\CartReorder\CartReorderApiTester;
14
use PyzTest\Glue\CartReorder\RestApi\Fixtures\SalesUnitCartReorderRestApiFixtures;
15
use Spryker\DecimalObject\Decimal;
16
use Spryker\Glue\CartReorderRestApi\CartReorderRestApiConfig;
17
18
/**
19
 * Auto-generated group annotations
20
 *
21
 * @group PyzTest
22
 * @group Glue
23
 * @group CartReorder
24
 * @group RestApi
25
 * @group SalesUnitCartReorderRestApiCest
26
 * Add your own group annotations below this line
27
 * @group EndToEnd
28
 */
29
class SalesUnitCartReorderRestApiCest
30
{
31
    /**
32
     * @var \PyzTest\Glue\CartReorder\RestApi\Fixtures\SalesUnitCartReorderRestApiFixtures
33
     */
34
    protected SalesUnitCartReorderRestApiFixtures $fixtures;
35
36
    /**
37
     * @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I
38
     *
39
     * @return void
40
     */
41
    public function loadFixtures(CartReorderApiTester $I): void
42
    {
43
        /** @var \PyzTest\Glue\CartReorder\RestApi\Fixtures\SalesUnitCartReorderRestApiFixtures $fixtures */
44
        $fixtures = $I->loadFixtures(SalesUnitCartReorderRestApiFixtures::class);
45
46
        $this->fixtures = $fixtures;
47
    }
48
49
    /**
50
     * @param \PyzTest\Glue\CartReorder\CartReorderApiTester $I
51
     *
52
     * @return void
53
     */
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);
0 ignored issues
show
Bug introduced by
It seems like seeResponseDataContainsSingleResourceOfType() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsSingleResourceOfType(CartReorderApiTester::RESOURCE_CARTS);
Loading history...
80
81
        $I->amSure('The returned response data contains correct cart name.')
82
            ->whenI()
83
            ->assertResponseContainsCorrectCartName(
0 ignored issues
show
Bug introduced by
It seems like assertResponseContainsCorrectCartName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
            ->/** @scrutinizer ignore-call */ assertResponseContainsCorrectCartName(
Loading history...
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());
0 ignored issues
show
Bug introduced by
It seems like assertResponseContainsItemBySku() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
            ->/** @scrutinizer ignore-call */ assertResponseContainsItemBySku($this->fixtures->getProductConcreteTransfer()->getSkuOrFail());
Loading history...
90
        $I->amSure('The first item has correct quantity.')
91
            ->whenI()
92
            ->assertItemHasCorrectQuantity($this->fixtures->getProductConcreteTransfer()->getSkuOrFail(), 1);
0 ignored issues
show
Bug introduced by
It seems like assertItemHasCorrectQuantity() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
            ->/** @scrutinizer ignore-call */ assertItemHasCorrectQuantity($this->fixtures->getProductConcreteTransfer()->getSkuOrFail(), 1);
Loading history...
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(
0 ignored issues
show
Bug introduced by
It seems like assertItemHasIdSalesUnit() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
            ->/** @scrutinizer ignore-call */ assertItemHasIdSalesUnit(
Loading history...
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(
0 ignored issues
show
Bug introduced by
It seems like assertItemHasSalesUnitAmount() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

111
            ->/** @scrutinizer ignore-call */ assertItemHasSalesUnitAmount(
Loading history...
112
                $this->fixtures->getProductConcreteTransferWithSalesUnit()->getSkuOrFail(),
113
                new Decimal(3),
114
            );
115
    }
116
}
117