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

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\ProductLabels\RestApi;
9
10
use Codeception\Util\HttpCode;
11
use PyzTest\Glue\ProductLabels\ProductLabelsApiTester;
12
use Spryker\Glue\ProductLabelsRestApi\ProductLabelsRestApiConfig;
13
14
/**
15
 * Auto-generated group annotations
16
 *
17
 * @group PyzTest
18
 * @group Glue
19
 * @group ProductLabels
20
 * @group RestApi
21
 * @group ProductAbstractProductLabelsRestApiCest
22
 * Add your own group annotations below this line
23
 * @group EndToEnd
24
 */
25
class ProductAbstractProductLabelsRestApiCest
26
{
27
    /**
28
     * @var \PyzTest\Glue\ProductLabels\RestApi\ProductLabelsRestApiFixtures
29
     */
30
    protected ProductLabelsRestApiFixtures $fixtures;
31
32
    /**
33
     * @param \PyzTest\Glue\ProductLabels\ProductLabelsApiTester $I
34
     *
35
     * @return void
36
     */
37
    public function loadFixtures(ProductLabelsApiTester $I): void
38
    {
39
        /** @var \PyzTest\Glue\ProductLabels\RestApi\ProductLabelsRestApiFixtures $fixtures */
40
        $fixtures = $I->loadFixtures(ProductLabelsRestApiFixtures::class);
41
42
        $this->fixtures = $fixtures;
43
    }
44
45
    /**
46
     * @depends loadFixtures
47
     *
48
     * @param \PyzTest\Glue\ProductLabels\ProductLabelsApiTester $I
49
     *
50
     * @return void
51
     */
52
    public function requestProductAbstractWithProductLabelsRelationship(ProductLabelsApiTester $I): void
53
    {
54
        // Arrange
55
        $idProductLabel = $this->fixtures->getProductLabelTransfer()->getIdProductLabel();
56
        $url = $I->buildProductAbstractUrl(
57
            $this->fixtures->getProductConcreteTransferWithLabel()->getAbstractSku(),
58
            [
59
                ProductLabelsRestApiConfig::RESOURCE_PRODUCT_LABELS,
60
            ],
61
        );
62
63
        // Act
64
        $I->sendGET($url);
65
66
        // Assert
67
        $I->seeResponseCodeIs(HttpCode::OK);
68
        $I->seeResponseIsJson();
69
        $I->seeResponseMatchesOpenApiSchema();
70
71
        $I->amSure('The returned resource has product-labels relationship')
72
            ->whenI()
73
            ->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

73
            ->/** @scrutinizer ignore-call */ seeSingleResourceHasRelationshipByTypeAndId(
Loading history...
74
                ProductLabelsRestApiConfig::RESOURCE_PRODUCT_LABELS,
75
                $idProductLabel,
76
            );
77
78
        $I->amSure('The returned resource has product-labels include')
79
            ->whenI()
80
            ->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

80
            ->/** @scrutinizer ignore-call */ seeIncludesContainsResourceByTypeAndId(
Loading history...
81
                ProductLabelsRestApiConfig::RESOURCE_PRODUCT_LABELS,
82
                $idProductLabel,
83
            );
84
85
        $I->amSure('The include has correct self-link')
86
            ->whenI()
87
            ->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

87
            ->/** @scrutinizer ignore-call */ seeIncludedResourceByTypeAndIdHasSelfLink(
Loading history...
88
                ProductLabelsRestApiConfig::RESOURCE_PRODUCT_LABELS,
89
                $idProductLabel,
90
                $I->buildProductLabelUrl($idProductLabel),
91
            );
92
    }
93
94
    /**
95
     * @depends loadFixtures
96
     *
97
     * @param \PyzTest\Glue\ProductLabels\ProductLabelsApiTester $I
98
     *
99
     * @return void
100
     */
101
    public function requestProductAbstractWithoutProductLabelsRelationship(ProductLabelsApiTester $I): void
102
    {
103
        // Arrange
104
        $url = $I->buildProductAbstractUrl(
105
            $this->fixtures->getProductConcreteTransfer()->getAbstractSku(),
106
            [
107
                ProductLabelsRestApiConfig::RESOURCE_PRODUCT_LABELS,
108
            ],
109
        );
110
111
        // Act
112
        $I->sendGET($url);
113
114
        // Assert
115
        $I->seeResponseCodeIs(HttpCode::OK);
116
        $I->seeResponseIsJson();
117
        $I->seeResponseMatchesOpenApiSchema();
118
119
        $I->amSure('The returned resource does not have product-labels includes')
120
            ->whenI()
121
            ->dontSeeIncludesContainResourceOfType(ProductLabelsRestApiConfig::RESOURCE_PRODUCT_LABELS);
0 ignored issues
show
Bug introduced by
It seems like dontSeeIncludesContainResourceOfType() 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

121
            ->/** @scrutinizer ignore-call */ dontSeeIncludesContainResourceOfType(ProductLabelsRestApiConfig::RESOURCE_PRODUCT_LABELS);
Loading history...
122
    }
123
124
    /**
125
     * @depends loadFixtures
126
     *
127
     * @param \PyzTest\Glue\ProductLabels\ProductLabelsApiTester $I
128
     *
129
     * @return void
130
     */
131
    public function requestProductAbstractWithProductLabelsRelationshipByPost(ProductLabelsApiTester $I): void
132
    {
133
        // Arrange
134
        $url = $I->buildProductAbstractUrl(
135
            $this->fixtures->getProductConcreteTransferWithLabel()->getAbstractSku(),
136
            [
137
                ProductLabelsRestApiConfig::RESOURCE_PRODUCT_LABELS,
138
            ],
139
        );
140
141
        // Act
142
        $I->sendPOST($url);
143
144
        // Assert
145
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
146
        $I->seeResponseIsJson();
147
    }
148
149
    /**
150
     * @depends loadFixtures
151
     *
152
     * @param \PyzTest\Glue\ProductLabels\ProductLabelsApiTester $I
153
     *
154
     * @return void
155
     */
156
    public function requestProductAbstractWithProductLabelRelationshipByPatch(ProductLabelsApiTester $I): void
157
    {
158
        // Arrange
159
        $url = $I->buildProductAbstractUrl(
160
            $this->fixtures->getProductConcreteTransferWithLabel()->getAbstractSku(),
161
            [
162
                ProductLabelsRestApiConfig::RESOURCE_PRODUCT_LABELS,
163
            ],
164
        );
165
166
        // Act
167
        $I->sendPATCH($url);
168
169
        // Assert
170
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
171
        $I->seeResponseIsJson();
172
    }
173
}
174