ProductAbstractRestApiCest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 182
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 74
dl 0
loc 182
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A loadFixtures() 0 6 1
A requestProductAbstractWithoutId() 0 8 1
A requestProductAbstractWithProductConcreteRelationship() 0 39 1
A requestProductAbstract() 0 28 1
A requestProductAbstractWithProductPriceRelationship() 0 34 1
A requestProductAbstractByNotExistingProductAbstractSku() 0 9 1
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\Products\RestApi;
11
12
use Codeception\Util\HttpCode;
13
use Generated\Shared\Transfer\AbstractProductsRestAttributesTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...sRestAttributesTransfer 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...
14
use PyzTest\Glue\Products\ProductsApiTester;
15
use PyzTest\Glue\Products\RestApi\Fixtures\ProductsRestApiFixtures;
16
use Spryker\Glue\ProductPricesRestApi\ProductPricesRestApiConfig;
17
use Spryker\Glue\ProductsRestApi\ProductsRestApiConfig;
18
19
/**
20
 * Auto-generated group annotations
21
 *
22
 * @group PyzTest
23
 * @group Glue
24
 * @group Products
25
 * @group RestApi
26
 * @group ProductAbstractRestApiCest
27
 * Add your own group annotations below this line
28
 * @group EndToEnd
29
 */
30
class ProductAbstractRestApiCest
31
{
32
    /**
33
     * @var \PyzTest\Glue\Products\RestApi\Fixtures\ProductsRestApiFixtures
34
     */
35
    protected ProductsRestApiFixtures $fixtures;
36
37
    /**
38
     * @param \PyzTest\Glue\Products\ProductsApiTester $I
39
     *
40
     * @return void
41
     */
42
    public function loadFixtures(ProductsApiTester $I): void
43
    {
44
        /** @var \PyzTest\Glue\Products\RestApi\Fixtures\ProductsRestApiFixtures $fixtures */
45
        $fixtures = $I->loadFixtures(ProductsRestApiFixtures::class);
46
47
        $this->fixtures = $fixtures;
48
    }
49
50
    /**
51
     * @depends loadFixtures
52
     *
53
     * @param \PyzTest\Glue\Products\ProductsApiTester $I
54
     *
55
     * @return void
56
     */
57
    public function requestProductAbstractByNotExistingProductAbstractSku(ProductsApiTester $I): void
58
    {
59
        // Act
60
        $I->sendGET($I->buildProductAbstractUrl('NotExistingSku'));
61
62
        // Assert
63
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
64
        $I->seeResponseIsJson();
65
        $I->seeResponseMatchesOpenApiSchema();
66
    }
67
68
    /**
69
     * @depends loadFixtures
70
     *
71
     * @param \PyzTest\Glue\Products\ProductsApiTester $I
72
     *
73
     * @return void
74
     */
75
    public function requestProductAbstractWithoutId(ProductsApiTester $I): void
76
    {
77
        // Act
78
        $I->sendGET($I->buildProductAbstractUrl(''));
79
80
        // Assert
81
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
82
        $I->seeResponseIsJson();
83
    }
84
85
    /**
86
     * @depends loadFixtures
87
     *
88
     * @param \PyzTest\Glue\Products\ProductsApiTester $I
89
     *
90
     * @return void
91
     */
92
    public function requestProductAbstract(ProductsApiTester $I): void
93
    {
94
        // Arrange
95
        $url = $I->buildProductAbstractUrl($this->fixtures->getProductConcreteTransfer()->getAbstractSku());
96
97
        // Act
98
        $I->sendGET($url);
99
100
        // Assert
101
        $I->seeResponseCodeIs(HttpCode::OK);
102
        $I->seeResponseIsJson();
103
        $I->seeResponseMatchesOpenApiSchema();
104
105
        $I->amSure('The returned resource is of correct type')
106
            ->whenI()
107
            ->seeResponseDataContainsSingleResourceOfType(ProductsRestApiConfig::RESOURCE_ABSTRACT_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

107
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsSingleResourceOfType(ProductsRestApiConfig::RESOURCE_ABSTRACT_PRODUCTS);
Loading history...
108
109
        $I->amSure('The returned resource has correct id')
110
            ->whenI()
111
            ->seeSingleResourceIdEqualTo($this->fixtures->getProductConcreteTransfer()->getAbstractSku());
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

111
            ->/** @scrutinizer ignore-call */ seeSingleResourceIdEqualTo($this->fixtures->getProductConcreteTransfer()->getAbstractSku());
Loading history...
112
113
        $I->amSure('The returned resource has correct self-link')
114
            ->whenI()
115
            ->seeSingleResourceHasSelfLink($url);
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceHasSelfLink() 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

115
            ->/** @scrutinizer ignore-call */ seeSingleResourceHasSelfLink($url);
Loading history...
116
117
        $I->amSure('The returned resource contains attribute')
118
            ->whenI()
119
            ->seeSingleResourceHasAttribute(AbstractProductsRestAttributesTransfer::URL);
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

119
            ->/** @scrutinizer ignore-call */ seeSingleResourceHasAttribute(AbstractProductsRestAttributesTransfer::URL);
Loading history...
120
    }
121
122
    /**
123
     * @depends loadFixtures
124
     *
125
     * @param \PyzTest\Glue\Products\ProductsApiTester $I
126
     *
127
     * @return void
128
     */
129
    public function requestProductAbstractWithProductConcreteRelationship(ProductsApiTester $I): void
130
    {
131
        // Arrange
132
        $productConcreteTransfer = $this->fixtures->getProductConcreteTransfer();
133
        $url = $I->buildProductAbstractUrl(
134
            $productConcreteTransfer->getAbstractSku(),
135
            [
136
                ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
137
            ],
138
        );
139
140
        // Act
141
        $I->sendGET($url);
142
143
        // Assert
144
        $I->seeResponseCodeIs(HttpCode::OK);
145
        $I->seeResponseIsJson();
146
        $I->seeResponseMatchesOpenApiSchema();
147
148
        $I->amSure('The returned resource has relationship')
149
            ->whenI()
150
            ->seeSingleResourceHasRelationshipByTypeAndId(
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceHasRelationshipByTypeAndId() 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

150
            ->/** @scrutinizer ignore-call */ seeSingleResourceHasRelationshipByTypeAndId(
Loading history...
151
                ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
152
                $productConcreteTransfer->getSku(),
153
            );
154
155
        $I->amSure('The returned resource has include')
156
            ->whenI()
157
            ->seeIncludesContainsResourceByTypeAndId(
0 ignored issues
show
Bug introduced by
It seems like seeIncludesContainsResourceByTypeAndId() 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

157
            ->/** @scrutinizer ignore-call */ seeIncludesContainsResourceByTypeAndId(
Loading history...
158
                ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
159
                $productConcreteTransfer->getSku(),
160
            );
161
162
        $I->amSure('The include has correct self-link')
163
            ->whenI()
164
            ->seeIncludedResourceByTypeAndIdHasSelfLink(
0 ignored issues
show
Bug introduced by
It seems like seeIncludedResourceByTypeAndIdHasSelfLink() 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

164
            ->/** @scrutinizer ignore-call */ seeIncludedResourceByTypeAndIdHasSelfLink(
Loading history...
165
                ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS,
166
                $productConcreteTransfer->getSku(),
167
                $I->buildProductConcreteUrl($productConcreteTransfer->getSku()),
168
            );
169
    }
170
171
    /**
172
     * @depends loadFixtures
173
     *
174
     * @param \PyzTest\Glue\Products\ProductsApiTester $I
175
     *
176
     * @return void
177
     */
178
    public function requestProductAbstractWithProductPriceRelationship(ProductsApiTester $I): void
179
    {
180
        // Arrange
181
        $productAbstractSku = $this->fixtures->getProductConcreteTransfer()->getAbstractSku();
182
        $url = $I->buildProductAbstractUrl($productAbstractSku, [ProductPricesRestApiConfig::RESOURCE_ABSTRACT_PRODUCT_PRICES]);
183
184
        // Act
185
        $I->sendGET($url);
186
187
        // Assert
188
        $I->seeResponseCodeIs(HttpCode::OK);
189
        $I->seeResponseIsJson();
190
        $I->seeResponseMatchesOpenApiSchema();
191
192
        $I->amSure('The returned resource has relationship')
193
            ->whenI()
194
            ->seeSingleResourceHasRelationshipByTypeAndId(
195
                ProductPricesRestApiConfig::RESOURCE_ABSTRACT_PRODUCT_PRICES,
196
                $productAbstractSku,
197
            );
198
199
        $I->amSure('The returned resource has include')
200
            ->whenI()
201
            ->seeIncludesContainsResourceByTypeAndId(
202
                ProductPricesRestApiConfig::RESOURCE_ABSTRACT_PRODUCT_PRICES,
203
                $productAbstractSku,
204
            );
205
206
        $I->amSure('The include has correct self-link')
207
            ->whenI()
208
            ->seeIncludedResourceByTypeAndIdHasSelfLink(
209
                ProductPricesRestApiConfig::RESOURCE_ABSTRACT_PRODUCT_PRICES,
210
                $productAbstractSku,
211
                $I->buildProductAbstractPricesUrl($productAbstractSku),
212
            );
213
    }
214
}
215