UrlsRestApiCest::requestNonExistingUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 17
rs 10
c 0
b 0
f 0
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
declare(strict_types = 1);
9
10
namespace PyzTest\Glue\Urls\RestApi;
11
12
use Codeception\Util\HttpCode;
13
use PyzTest\Glue\Urls\UrlsRestApiTester;
14
use Spryker\Glue\UrlsRestApi\UrlsRestApiConfig;
15
16
/**
17
 * Auto-generated group annotations
18
 *
19
 * @group PyzTest
20
 * @group Glue
21
 * @group Urls
22
 * @group RestApi
23
 * @group UrlsRestApiCest
24
 * Add your own group annotations below this line
25
 * @group EndToEnd
26
 */
27
class UrlsRestApiCest
28
{
29
    /**
30
     * @var string
31
     */
32
    protected const DEFAULT_LOCALE = 'en_US';
33
34
    /**
35
     * @var \PyzTest\Glue\Urls\RestApi\UrlsRestApiFixtures
36
     */
37
    protected UrlsRestApiFixtures $fixtures;
38
39
    /**
40
     * @param \PyzTest\Glue\Urls\UrlsRestApiTester $I
41
     *
42
     * @return void
43
     */
44
    public function loadFixtures(UrlsRestApiTester $I): void
45
    {
46
        /** @var \PyzTest\Glue\Urls\RestApi\UrlsRestApiFixtures $fixtures */
47
        $fixtures = $I->loadFixtures(UrlsRestApiFixtures::class);
48
49
        $this->fixtures = $fixtures;
50
    }
51
52
    /**
53
     * @depends loadFixtures
54
     *
55
     * @param \PyzTest\Glue\Urls\UrlsRestApiTester $I
56
     *
57
     * @return void
58
     */
59
    public function requestNonExistingUrl(UrlsRestApiTester $I): void
60
    {
61
        // Act
62
        $I->sendGET(
63
            $I->formatUrl(
64
                '{resource}?url={url}',
65
                [
66
                    'resource' => UrlsRestApiConfig::RESOURCE_URL_RESOLVER,
67
                    'url' => 'none',
68
                ],
69
            ),
70
        );
71
72
        // Assert
73
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
74
        $I->seeResponseIsJson();
75
        $I->seeResponseMatchesOpenApiSchema();
76
    }
77
78
    /**
79
     * @depends loadFixtures
80
     *
81
     * @param \PyzTest\Glue\Urls\UrlsRestApiTester $I
82
     *
83
     * @return void
84
     */
85
    public function requestUrlWithoutUrlParameter(UrlsRestApiTester $I): void
86
    {
87
        // Act
88
        $I->sendGET(
89
            $I->formatUrl(
90
                '{resource}',
91
                [
92
                    'resource' => UrlsRestApiConfig::RESOURCE_URL_RESOLVER,
93
                ],
94
            ),
95
        );
96
97
        // Assert
98
        $I->seeResponseCodeIs(HttpCode::UNPROCESSABLE_ENTITY);
99
        $I->seeResponseIsJson();
100
    }
101
102
    /**
103
     * @depends loadFixtures
104
     *
105
     * @param \PyzTest\Glue\Urls\UrlsRestApiTester $I
106
     *
107
     * @return void
108
     */
109
    public function requestExistingProductAbstractUrl(UrlsRestApiTester $I): void
110
    {
111
        // Arrange
112
        $localizedUrl = '';
113
        foreach ($this->fixtures->getProductUrlTransfer()->getUrls() as $localizedUrlTransfer) {
114
            if ($localizedUrlTransfer->getLocale()->getLocaleName() !== static::DEFAULT_LOCALE) {
115
                continue;
116
            }
117
118
            $localizedUrl = $localizedUrlTransfer->getUrl();
119
        }
120
121
        // Act
122
        $I->sendGET(
123
            $I->formatUrl(
124
                '{resource}?url={url}',
125
                [
126
                    'resource' => UrlsRestApiConfig::RESOURCE_URL_RESOLVER,
127
                    'url' => $localizedUrl,
128
                ],
129
            ),
130
        );
131
132
        // Assert
133
        $I->seeResponseCodeIs(HttpCode::OK);
134
        $I->seeResponseIsJson();
135
        $I->seeResponseMatchesOpenApiSchema();
136
137
        $I->amSure('Returned resource collection consists of 1 item of type url-resolver')
138
            ->whenI()
139
            ->seeResponseDataContainsResourceCollectionOfTypeWithSizeOf(UrlsRestApiConfig::RESOURCE_URL_RESOLVER, 1);
0 ignored issues
show
Bug introduced by
It seems like seeResponseDataContainsR...ctionOfTypeWithSizeOf() 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

139
            ->/** @scrutinizer ignore-call */ seeResponseDataContainsResourceCollectionOfTypeWithSizeOf(UrlsRestApiConfig::RESOURCE_URL_RESOLVER, 1);
Loading history...
140
    }
141
}
142