Passed
Pull Request — master (#365)
by Dmitry
21:01
created

requestAddConfigurableItemsToCart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
dl 0
loc 63
c 1
b 0
f 0
rs 9.28
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
namespace PyzTest\Glue\ProductConfigurations\RestApi;
9
10
use Codeception\Util\HttpCode;
11
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Generated\Shared\Transfer\StoreTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use PyzTest\Glue\ProductConfigurations\ProductConfigurationsApiTester;
14
use PyzTest\Glue\ProductConfigurations\RestApi\Fixtures\ProductConfigurationsRestApiFixtures;
15
use Spryker\Glue\CartsRestApi\CartsRestApiConfig;
16
use Spryker\Glue\OrdersRestApi\OrdersRestApiConfig;
17
use Spryker\Glue\ProductsRestApi\ProductsRestApiConfig;
18
use Spryker\Shared\Price\PriceConfig;
19
20
/**
21
 * Auto-generated group annotations
22
 *
23
 * @group PyzTest
24
 * @group Glue
25
 * @group ProductConfigurations
26
 * @group RestApi
27
 * @group ProductConfigurationRestApiCest
28
 * Add your own group annotations below this line
29
 * @group EndToEnd
30
 */
31
class ProductConfigurationRestApiCest
32
{
33
    /**
34
     * @var \PyzTest\Glue\ProductConfigurations\RestApi\Fixtures\ProductConfigurationsRestApiFixtures
35
     */
36
    protected ProductConfigurationsRestApiFixtures $fixtures;
37
38
    /**
39
     * @param \PyzTest\Glue\ProductConfigurations\ProductConfigurationsApiTester $I
40
     *
41
     * @return void
42
     */
43
    public function loadFixtures(ProductConfigurationsApiTester $I): void
44
    {
45
        /** @var \PyzTest\Glue\ProductConfigurations\RestApi\Fixtures\ProductConfigurationsRestApiFixtures $fixtures */
46
        $fixtures = $I->loadFixtures(ProductConfigurationsRestApiFixtures::class);
47
48
        $this->fixtures = $fixtures;
49
    }
50
51
    /**
52
     * @depends loadFixtures
53
     *
54
     * @param \PyzTest\Glue\ProductConfigurations\ProductConfigurationsApiTester $I
55
     *
56
     * @return void
57
     */
58
    public function requestProductConcrete(ProductConfigurationsApiTester $I): void
59
    {
60
        // Act
61
        $I->sendGET($I->formatFullUrl(
62
            '{resourceConcreteProducts}/{productConcreteSku}',
63
            [
64
                'resourceConcreteProducts' => ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
65
                'productConcreteSku' => $this->fixtures->getProductConcreteTransfer()->getSkuOrFail(),
66
            ],
67
        ));
68
69
        // Assert
70
        $I->seeResponseCodeIs(HttpCode::OK);
71
        $I->seeResponseIsJson();
72
        $I->seeResponseMatchesOpenApiSchema();
73
74
        $I->amSure('Returned resource is of type concrete-products')
75
            ->whenI()
76
            ->seeResponseDataContainsSingleResourceOfType(ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS);
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

76
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsSingleResourceOfType(ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS);
Loading history...
77
78
        $I->amSure('Returned resource has correct id')
79
            ->whenI()
80
            ->seeSingleResourceIdEqualTo($this->fixtures->getProductConcreteTransfer()->getSkuOrFail());
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceIdEqualTo() 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

80
            ->/** @scrutinizer ignore-call */ seeSingleResourceIdEqualTo($this->fixtures->getProductConcreteTransfer()->getSkuOrFail());
Loading history...
81
82
        $I->amSure('Returned resource has product configuration instance')
83
            ->whenI()
84
            ->seeSingleResourceHasAttribute($this->fixtures::PRODUCT_CONFIGURATION_INSTANCE_ATTRIBUTE_JSON_PATH);
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceHasAttribute() 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

84
            ->/** @scrutinizer ignore-call */ seeSingleResourceHasAttribute($this->fixtures::PRODUCT_CONFIGURATION_INSTANCE_ATTRIBUTE_JSON_PATH);
Loading history...
85
86
        $I->amSure('Returned product configuration instance is correct')
87
            ->whenI()
88
            ->seeProductConfigurationInstanceEqualToExpectedValue($this->fixtures->getProductConfigurationTransfer());
0 ignored issues
show
Bug introduced by
It seems like seeProductConfigurationI...eEqualToExpectedValue() 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

88
            ->/** @scrutinizer ignore-call */ seeProductConfigurationInstanceEqualToExpectedValue($this->fixtures->getProductConfigurationTransfer());
Loading history...
89
    }
90
91
    /**
92
     * @param \PyzTest\Glue\ProductConfigurations\ProductConfigurationsApiTester $I
93
     *
94
     * @return void
95
     */
96
    public function requestAddConfigurableItemsToCart(ProductConfigurationsApiTester $I): void
97
    {
98
        // Arrange
99
        $I->amAuthorizedCustomer($this->fixtures->getCustomerTransfer());
100
        $quoteTransfer = $I->havePersistentQuote([
101
            QuoteTransfer::CUSTOMER => $this->fixtures->getCustomerTransfer(),
102
            QuoteTransfer::STORE => [StoreTransfer::NAME => $this->fixtures::STORE_NAME_DE],
103
            QuoteTransfer::PRICE_MODE => PriceConfig::PRICE_MODE_GROSS,
104
        ]);
105
        $quoteUuid = $quoteTransfer->getUuidOrFail();
106
        $productConcreteSku = $this->fixtures->getProductConcreteTransfer()->getSkuOrFail();
107
108
        // Act
109
        $I->sendPOST(
110
            $I->formatUrl(
111
                '{resourceCarts}/{cartUuid}/{resourceCartItems}?include={resourceCartItems}',
112
                [
113
                    'resourceCarts' => CartsRestApiConfig::RESOURCE_CARTS,
114
                    'cartUuid' => $quoteUuid,
115
                    'resourceCartItems' => CartsRestApiConfig::RESOURCE_CART_ITEMS,
116
                ],
117
            ),
118
            [
119
                'data' => [
120
                    'type' => CartsRestApiConfig::RESOURCE_CART_ITEMS,
121
                    'attributes' => [
122
                        'sku' => $productConcreteSku,
123
                        'quantity' => 1,
124
                        'productConfigurationInstance' => $this->fixtures::PRODUCT_CONFIGURATION_CART_ITEM_DATA,
125
                    ],
126
                ],
127
            ],
128
        );
129
130
        // Assert
131
        $I->seeResponseCodeIs(HttpCode::CREATED);
132
        $I->seeResponseMatchesOpenApiSchema();
133
134
        $I->amSure('Returned resource has correct id')
135
            ->whenI()
136
            ->seeSingleResourceIdEqualTo($quoteUuid);
137
138
        $I->amSure(sprintf('Returned resource is of type %s', CartsRestApiConfig::RESOURCE_CARTS))
139
            ->whenI()
140
            ->seeResponseDataContainsSingleResourceOfType(CartsRestApiConfig::RESOURCE_CARTS);
141
142
        $I->amSure('Returned resource has include of type items')
143
            ->whenI()
144
            ->seeIncludesContainResourceOfType(CartsRestApiConfig::RESOURCE_CART_ITEMS);
0 ignored issues
show
Bug introduced by
It seems like seeIncludesContainResourceOfType() 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

144
            ->/** @scrutinizer ignore-call */ seeIncludesContainResourceOfType(CartsRestApiConfig::RESOURCE_CART_ITEMS);
Loading history...
145
146
        $I->amSure('Included resource has product configuration instance')
147
            ->whenI()
148
            ->seeCartItemContainsProductConfigurationInstance(
0 ignored issues
show
Bug introduced by
It seems like seeCartItemContainsProductConfigurationInstance() 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

148
            ->/** @scrutinizer ignore-call */ seeCartItemContainsProductConfigurationInstance(
Loading history...
149
                CartsRestApiConfig::RESOURCE_CART_ITEMS,
150
                $productConcreteSku,
151
            );
152
153
        $I->seeSingleResourceHasSelfLink(
154
            $I->formatFullUrl(
155
                '{resourceCarts}/{cartUuid}',
156
                [
157
                    'resourceCarts' => CartsRestApiConfig::RESOURCE_CARTS,
158
                    'cartUuid' => $I->getDataFromResponseByJsonPath('$.data')['id'],
159
                ],
160
            ),
161
        );
162
    }
163
164
    /**
165
     * @param \PyzTest\Glue\ProductConfigurations\ProductConfigurationsApiTester $I
166
     *
167
     * @return void
168
     */
169
    public function requestGetOrderDetails(ProductConfigurationsApiTester $I): void
170
    {
171
        // Arrange
172
        $I->amAuthorizedCustomer($this->fixtures->getCustomerTransfer());
173
        $orderReference = $this->fixtures->getSaveOrderTransfer()->getOrderReferenceOrFail();
174
175
        // Act
176
        $I->sendGET(
177
            $I->formatUrl(
178
                '{orders}/{customerOrderReference}?include=items',
179
                [
180
                    'orders' => OrdersRestApiConfig::RESOURCE_ORDERS,
181
                    'customerOrderReference' => $orderReference,
182
                ],
183
            ),
184
        );
185
186
        // Assert
187
        $I->seeResponseCodeIs(HttpCode::OK);
188
        $I->seeResponseIsJson();
189
        $I->seeResponseMatchesOpenApiSchema();
190
191
        $I->amSure('The returned resource is of correct type')
192
            ->whenI()
193
            ->seeResponseDataContainsSingleResourceOfType('orders');
194
195
        $I->amSure('The returned resource has correct id')
196
            ->whenI()
197
            ->seeSingleResourceIdEqualTo($orderReference);
198
199
        $I->amSure('Order item contains product configuration data')
200
            ->whenI()
201
            ->seeOrderItemContainProductConfigurationInstance($this->fixtures->getProductConfigurationTransfer());
0 ignored issues
show
Bug introduced by
It seems like seeOrderItemContainProductConfigurationInstance() 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

201
            ->/** @scrutinizer ignore-call */ seeOrderItemContainProductConfigurationInstance($this->fixtures->getProductConfigurationTransfer());
Loading history...
202
    }
203
}
204