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

ProductConcreteRestApiCest::loadFixtures()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 6
c 1
b 0
f 0
rs 10
cc 1
nc 1
nop 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
namespace PyzTest\Glue\Products\RestApi;
9
10
use Codeception\Util\HttpCode;
11
use Pyz\Glue\ProductPricesRestApi\ProductPricesRestApiConfig;
12
use PyzTest\Glue\Products\ProductsApiTester;
13
use PyzTest\Glue\Products\RestApi\Fixtures\ProductsRestApiFixtures;
14
use Spryker\Glue\ProductsRestApi\ProductsRestApiConfig;
15
16
/**
17
 * Auto-generated group annotations
18
 *
19
 * @group PyzTest
20
 * @group Glue
21
 * @group Products
22
 * @group RestApi
23
 * @group ProductConcreteRestApiCest
24
 * Add your own group annotations below this line
25
 * @group EndToEnd
26
 */
27
class ProductConcreteRestApiCest
28
{
29
    /**
30
     * @var \PyzTest\Glue\Products\RestApi\Fixtures\ProductsRestApiFixtures
31
     */
32
    protected ProductsRestApiFixtures $fixtures;
33
34
    /**
35
     * @param \PyzTest\Glue\Products\ProductsApiTester $I
36
     *
37
     * @return void
38
     */
39
    public function loadFixtures(ProductsApiTester $I): void
40
    {
41
        /** @var \PyzTest\Glue\Products\RestApi\Fixtures\ProductsRestApiFixtures $fixtures */
42
        $fixtures = $I->loadFixtures(ProductsRestApiFixtures::class);
43
44
        $this->fixtures = $fixtures;
45
    }
46
47
    /**
48
     * @depends loadFixtures
49
     *
50
     * @param \PyzTest\Glue\Products\ProductsApiTester $I
51
     *
52
     * @return void
53
     */
54
    public function requestProductConcrete(ProductsApiTester $I): void
55
    {
56
        // Arrange
57
        $productConcreteSku = $this->fixtures->getProductConcreteTransfer()->getSku();
58
        $url = $I->buildProductConcreteUrl($productConcreteSku);
59
60
        // Act
61
        $I->sendGET($url);
62
63
        // Assert
64
        $I->seeResponseCodeIs(HttpCode::OK);
65
        $I->seeResponseIsJson();
66
        $I->seeResponseMatchesOpenApiSchema();
67
68
        $I->amSure('The returned resource is of correct type')
69
            ->whenI()
70
            ->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

70
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsSingleResourceOfType(ProductsRestApiConfig::RESOURCE_CONCRETE_PRODUCTS);
Loading history...
71
72
        $I->amSure('The returned resource has correct id')
73
            ->whenI()
74
            ->seeSingleResourceIdEqualTo($productConcreteSku);
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

74
            ->/** @scrutinizer ignore-call */ seeSingleResourceIdEqualTo($productConcreteSku);
Loading history...
75
76
        $I->amSure('The returned resource has correct self-link')
77
            ->whenI()
78
            ->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

78
            ->/** @scrutinizer ignore-call */ seeSingleResourceHasSelfLink($url);
Loading history...
79
    }
80
81
    /**
82
     * @depends loadFixtures
83
     *
84
     * @param \PyzTest\Glue\Products\ProductsApiTester $I
85
     *
86
     * @return void
87
     */
88
    public function requestProductConcreteWithProductPriceRelationship(ProductsApiTester $I): void
89
    {
90
        // Arrange
91
        $productConcreteSku = $this->fixtures->getProductConcreteTransfer()->getSku();
92
        $url = $I->buildProductConcreteUrl($productConcreteSku, [ProductPricesRestApiConfig::RESOURCE_CONCRETE_PRODUCT_PRICES]);
93
94
        // Act
95
        $I->sendGET($url);
96
97
        // Assert
98
        $I->seeResponseCodeIs(HttpCode::OK);
99
        $I->seeResponseIsJson();
100
        $I->seeResponseMatchesOpenApiSchema();
101
102
        $I->amSure('The returned resource has relationship')
103
            ->whenI()
104
            ->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

104
            ->/** @scrutinizer ignore-call */ seeSingleResourceHasRelationshipByTypeAndId(
Loading history...
105
                ProductPricesRestApiConfig::RESOURCE_CONCRETE_PRODUCT_PRICES,
106
                $productConcreteSku,
107
            );
108
109
        $I->amSure('The returned resource has include')
110
            ->whenI()
111
            ->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

111
            ->/** @scrutinizer ignore-call */ seeIncludesContainsResourceByTypeAndId(
Loading history...
112
                ProductPricesRestApiConfig::RESOURCE_CONCRETE_PRODUCT_PRICES,
113
                $productConcreteSku,
114
            );
115
116
        $I->amSure('The include has correct self-link')
117
            ->whenI()
118
            ->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

118
            ->/** @scrutinizer ignore-call */ seeIncludedResourceByTypeAndIdHasSelfLink(
Loading history...
119
                ProductPricesRestApiConfig::RESOURCE_CONCRETE_PRODUCT_PRICES,
120
                $productConcreteSku,
121
                $I->buildProductConcretePricesUrl($productConcreteSku),
122
            );
123
    }
124
125
    /**
126
     * @depends loadFixtures
127
     *
128
     * @param \PyzTest\Glue\Products\ProductsApiTester $I
129
     *
130
     * @return void
131
     */
132
    public function requestProductConcreteByNotExistingProductConcreteSku(ProductsApiTester $I): void
133
    {
134
        // Act
135
        $I->sendGET($I->buildProductConcreteUrl('NotExistingSku'));
136
137
        // Assert
138
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
139
        $I->seeResponseIsJson();
140
        $I->seeResponseMatchesOpenApiSchema();
141
    }
142
}
143