Completed
Push — master ( 8da333...8f94e6 )
by Kamil
05:27 queued 12s
created

ManagingShippingMethodsContext   B

Complexity

Total Complexity 52

Size/Duplication

Total Lines 562
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 52
lcom 1
cbo 5
dl 0
loc 562
rs 7.44
c 0
b 0
f 0

51 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A iAmBrowsingArchivalShippingMethods() 0 6 1
A iSwitchTheLocaleToTheLocale() 0 10 1
A iBrowseShippingMethods() 0 4 1
A iDeleteShippingMethod() 0 4 1
A iWantToCreateANewShippingMethod() 0 4 1
A iAddIt() 0 4 1
A iSpecifyItsCodeAs() 0 4 1
A iSpecifyItsPositionAs() 0 4 1
A iNameItIn() 0 4 1
A iDescribeItAsIn() 0 7 1
A iDefineItForTheZone() 0 6 2
A iDisableIt() 0 4 1
A iEnableIt() 0 4 1
A iMakeItAvailableInChannel() 0 4 1
A iChooseCalculator() 0 4 1
A iArchiveTheShippingMethod() 0 5 1
A iRestoreTheShippingMethod() 0 5 1
A iSpecifyItsAmountAsForChannel() 0 4 1
A iWantToModifyShippingMethod() 0 4 1
A iSaveMyChanges() 0 4 1
A iSortShippingMethodsByCode() 0 4 1
A iSortShippingMethodsByName() 0 7 1
A iSwitchTheWayShippingMethodsAreSortedByCode() 0 4 1
A iSwitchTheWayShippingMethodsAreSortedByName() 0 4 1
A iFilterArchivalShippingMethods() 0 5 1
A iShouldSeeShippingMethodsInTheList() 0 4 1
A theShippingMethodShouldAppearInTheRegistry() 0 7 1
A thisShippingMethodShouldAppearInTheRegistry() 0 9 1
A iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted() 0 7 1
A thisShippingMethodShouldNoLongerExistInTheRegistry() 0 9 1
A iShouldBeNotifiedThatItHasBeenSuccessfullyCreated() 0 7 1
A theShippingMethodShouldBeAvailableInChannel() 0 11 1
A thisShippingMethodNameShouldBe() 0 12 1
A thisShippingMethodShouldBeDisabled() 0 11 1
A thisShippingMethodShouldBeEnabled() 0 11 1
A iShouldNotBeAbleToEditItsCode() 0 9 1
A iShouldBeNotifiedThatItHasBeenSuccessfullyEdited() 0 7 1
A iShouldBeNotifiedThatShippingMethodWithThisCodeAlreadyExists() 0 12 1
A thereShouldStillBeOnlyOneShippingMethodWith() 0 8 1
A theOnlyShippingMethodOnTheListShouldBe() 0 8 1
A iShouldSeeShippingMethodOnTheList() 0 7 1
A iShouldBeNotifiedThatItIsInUse() 0 7 1
A iShouldBeNotifiedThatElementIsRequired() 0 7 1
A iShouldBeNotifiedThatZoneHasToBeSelected() 0 7 1
A theShippingMethodWithElementValueShouldNotBeAdded() 0 7 1
A theFirstProductOnTheListShouldHave() 0 6 1
A theFirstShippingMethodOnTheListShouldHave() 0 6 1
A theLastShippingMethodOnTheListShouldHave() 0 6 1
A iShouldBeViewingNonArchivalShippingMethods() 0 4 1
A getAdminLocaleCode() 0 9 1

How to fix   Complexity   

Complex Class

Complex classes like ManagingShippingMethodsContext often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ManagingShippingMethodsContext, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Behat\Context\Api\Admin;
15
16
use ApiPlatform\Core\Api\IriConverterInterface;
17
use Behat\Behat\Context\Context;
18
use Sylius\Behat\Client\ApiClientInterface;
19
use Sylius\Behat\Client\ResponseCheckerInterface;
20
use Sylius\Behat\Service\SharedStorageInterface;
21
use Sylius\Component\Addressing\Model\ZoneInterface;
22
use Sylius\Component\Core\Model\AdminUserInterface;
23
use Sylius\Component\Core\Model\ChannelInterface;
24
use Sylius\Component\Core\Model\ShippingMethodInterface;
25
use Symfony\Component\HttpFoundation\Request as HttpRequest;
26
use Webmozart\Assert\Assert;
27
28
final class ManagingShippingMethodsContext implements Context
29
{
30
    public const SORT_TYPES = ['ascending' => 'asc', 'descending' => 'desc'];
31
32
    /** @var ApiClientInterface */
33
    private $client;
34
35
    /** @var ApiClientInterface */
36
    private $adminUsersClient;
37
38
    /** @var ResponseCheckerInterface */
39
    private $responseChecker;
40
41
    /** @var IriConverterInterface */
42
    private $iriConverter;
43
44
    /** @var SharedStorageInterface */
45
    private $sharedStorage;
46
47
    public function __construct(
48
        ApiClientInterface $client,
49
        ApiClientInterface $adminUsersClient,
50
        ResponseCheckerInterface $responseChecker,
51
        IriConverterInterface $iriConverter,
52
        SharedStorageInterface $sharedStorage
53
    ) {
54
        $this->client = $client;
55
        $this->adminUsersClient = $adminUsersClient;
56
        $this->responseChecker = $responseChecker;
57
        $this->iriConverter = $iriConverter;
58
        $this->sharedStorage = $sharedStorage;
59
    }
60
61
    /**
62
     * @Given I am browsing archival shipping methods
63
     */
64
    public function iAmBrowsingArchivalShippingMethods(): void
65
    {
66
        $this->client->index();
67
        $this->client->addFilter('exists[archivedAt]', true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
        $this->client->filter();
69
    }
70
71
    /**
72
     * @When I change my locale to :localeCode
73
     */
74
    public function iSwitchTheLocaleToTheLocale(string $localeCode): void
75
    {
76
        /** @var AdminUserInterface $adminUser */
77
        $adminUser = $this->sharedStorage->get('administrator');
78
79
        $this->adminUsersClient->buildUpdateRequest((string) $adminUser->getId());
80
81
        $this->adminUsersClient->updateRequestData(['localeCode' => $localeCode]);
82
        $this->adminUsersClient->update();
83
    }
84
85
    /**
86
     * @When I am browsing shipping methods
87
     * @When I want to browse shipping methods
88
     * @When I browse shipping methods
89
     */
90
    public function iBrowseShippingMethods(): void
91
    {
92
        $this->client->index();
93
    }
94
95
    /**
96
     * @When I (try to )delete shipping method :shippingMethod
97
     */
98
    public function iDeleteShippingMethod(ShippingMethodInterface $shippingMethod): void
99
    {
100
        $this->client->delete($shippingMethod->getCode());
101
    }
102
103
    /**
104
     * @When I want to create a new shipping method
105
     */
106
    public function iWantToCreateANewShippingMethod(): void
107
    {
108
        $this->client->buildCreateRequest();
109
    }
110
111
    /**
112
     * @When I add it
113
     * @When I try to add it
114
     */
115
    public function iAddIt(): void
116
    {
117
        $this->client->create();
118
    }
119
120
    /**
121
     * @When I specify its code as :code
122
     * @When I do not specify its code
123
     */
124
    public function iSpecifyItsCodeAs(?string $code = ''): void
125
    {
126
        $this->client->addRequestData('code', $code);
127
    }
128
129
    /**
130
     * @When I specify its position as :position
131
     */
132
    public function iSpecifyItsPositionAs(int $position): void
133
    {
134
        $this->client->addRequestData('position', $position);
135
    }
136
137
    /**
138
     * @When I name it :name in :localeCode
139
     * @When I rename it to :name in :localeCode
140
     * @When I do not name it
141
     * @When I remove its name from :localeCode translation
142
     */
143
    public function iNameItIn(?string $name = '', ?string $localeCode = 'en_US'): void
144
    {
145
        $this->client->updateRequestData(['translations' => [$localeCode => ['name' => $name, 'locale' => $localeCode]]]);
146
    }
147
148
    /**
149
     * @When I describe it as :description in :localeCode
150
     */
151
    public function iDescribeItAsIn(string $description, string $localeCode): void
152
    {
153
        $data = ['translations' => [$localeCode => ['locale' => $localeCode]]];
154
        $data['translations'][$localeCode]['description'] = $description;
155
156
        $this->client->updateRequestData($data);
157
    }
158
159
    /**
160
     * @When /^I define it for the (zone named "[^"]+")$/
161
     * @When I do not specify its zone
162
     */
163
    public function iDefineItForTheZone(ZoneInterface $zone = null): void
164
    {
165
        if (null !== $zone) {
166
            $this->client->addRequestData('zone', $this->iriConverter->getIriFromItem($zone));
167
        }
168
    }
169
170
    /**
171
     * @When I disable it
172
     */
173
    public function iDisableIt(): void
174
    {
175
        $this->client->addRequestData('enabled', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string|integer|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
176
    }
177
178
    /**
179
     * @When I enable it
180
     */
181
    public function iEnableIt(): void
182
    {
183
        $this->client->addRequestData('enabled', true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string|integer|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
184
    }
185
186
    /**
187
     * @When I make it available in channel :channel
188
     */
189
    public function iMakeItAvailableInChannel(ChannelInterface $channel): void
190
    {
191
        $this->client->addRequestData('channels', [$this->iriConverter->getIriFromItem($channel)]);
192
    }
193
194
    /**
195
     * @When I choose :shippingCalculator calculator
196
     */
197
    public function iChooseCalculator(string $shippingCalculator): void
198
    {
199
        $this->client->addRequestData('calculator', $shippingCalculator);
200
    }
201
202
    /**
203
     * @When I archive the :shippingMethod shipping method
204
     */
205
    public function iArchiveTheShippingMethod(ShippingMethodInterface $shippingMethod): void
206
    {
207
        $this->client->customItemAction($shippingMethod->getCode(), HttpRequest::METHOD_PATCH, 'archive');
208
        $this->client->index();
209
    }
210
211
    /**
212
     * @When I restore the :shippingMethod shipping method
213
     */
214
    public function iRestoreTheShippingMethod(ShippingMethodInterface $shippingMethod): void
215
    {
216
        $this->client->customItemAction($shippingMethod->getCode(), HttpRequest::METHOD_PATCH, 'restore');
217
        $this->client->index();
218
    }
219
220
    /**
221
     * @When I specify its amount as :amount for :channel channel
222
     */
223
    public function iSpecifyItsAmountAsForChannel(ChannelInterface $channel, int $amount): void
224
    {
225
        $this->client->addRequestData('configuration', [$channel->getCode() => ['amount' => $amount]]);
226
    }
227
228
    /**
229
     * @When I want to modify a shipping method :shippingMethod
230
     * @When /^I want to modify (this shipping method)$/
231
     */
232
    public function iWantToModifyShippingMethod(ShippingMethodInterface $shippingMethod): void
233
    {
234
        $this->client->buildUpdateRequest($shippingMethod->getCode());
235
    }
236
237
    /**
238
     * @When I save my changes
239
     * @When I try to save my changes
240
     */
241
    public function iSaveMyChanges(): void
242
    {
243
        $this->client->update();
244
    }
245
246
    /**
247
     * @When I sort the shipping methods :sortType by code
248
     * @When I switch the way shipping methods are sorted :sortType by code
249
     */
250
    public function iSortShippingMethodsByCode(string $sortType = 'ascending'): void
251
    {
252
        $this->client->sort(['code' => self::SORT_TYPES[$sortType]]);
253
    }
254
255
    /**
256
     * @When I sort the shipping methods :sortType by name
257
     * @When I switch the way shipping methods are sorted :sortType by name
258
     * @Given the shipping methods are already sorted :sortType by name
259
     */
260
    public function iSortShippingMethodsByName(string $sortType = 'ascending'): void
261
    {
262
        $this->client->sort([
263
            'translation.name' => self::SORT_TYPES[$sortType],
264
            'localeCode' => $this->getAdminLocaleCode(),
265
        ]);
266
    }
267
268
    /**
269
     * @When I switch the way shipping methods are sorted by code
270
     */
271
    public function iSwitchTheWayShippingMethodsAreSortedByCode(): void
272
    {
273
        $this->client->sort(['code' => 'desc']);
274
    }
275
276
    /**
277
     * @When I switch the way shipping methods are sorted by name
278
     */
279
    public function iSwitchTheWayShippingMethodsAreSortedByName(): void
280
    {
281
        $this->client->sort(['translation.name' => 'desc']);
282
    }
283
284
    /**
285
     * @When I filter archival shipping methods
286
     */
287
    public function iFilterArchivalShippingMethods(): void
288
    {
289
        $this->client->addFilter('exists[archivedAt]', true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
290
        $this->client->filter();
291
    }
292
293
    /**
294
     * @Then I should see :count shipping methods in the list
295
     */
296
    public function iShouldSeeShippingMethodsInTheList(int $count): void
297
    {
298
        Assert::count($this->responseChecker->getCollection($this->client->getLastResponse()), $count);
299
    }
300
301
    /**
302
     * @Then the shipping method :name should be in the registry
303
     * @Then the shipping method :name should appear in the registry
304
     */
305
    public function theShippingMethodShouldAppearInTheRegistry(string $name): void
306
    {
307
        Assert::true(
308
            $this->responseChecker->hasItemWithTranslation($this->client->index(), 'en_US', 'name', $name),
309
            sprintf('Shipping method with name %s does not exists', $name)
310
        );
311
    }
312
313
    /**
314
     * @Then /^(this shipping method) should still be in the registry$/
315
     */
316
    public function thisShippingMethodShouldAppearInTheRegistry(ShippingMethodInterface $shippingMethod): void
317
    {
318
        $name = $shippingMethod->getName();
319
320
        Assert::true(
321
            $this->responseChecker->hasItemWithTranslation($this->client->index(), 'en_US', 'name', $name),
322
            sprintf('Shipping method with name %s does not exists', $name)
323
        );
324
    }
325
326
    /**
327
     * @Then I should be notified that it has been successfully deleted
328
     */
329
    public function iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted(): void
330
    {
331
        Assert::true(
332
            $this->responseChecker->isDeletionSuccessful($this->client->getLastResponse()),
333
            'Shipping method could not be deleted'
334
        );
335
    }
336
337
    /**
338
     * @Then /^(this shipping method) should no longer exist in the registry$/
339
     */
340
    public function thisShippingMethodShouldNoLongerExistInTheRegistry(ShippingMethodInterface $shippingMethod): void
341
    {
342
        $shippingMethodName = $shippingMethod->getName();
343
344
        Assert::false(
345
            $this->responseChecker->hasItemWithTranslation($this->client->index(), 'en_US', 'name', $shippingMethodName),
346
            sprintf('Shipping method with name %s does not exists', $shippingMethodName)
347
        );
348
    }
349
350
    /**
351
     * @Then I should be notified that it has been successfully created
352
     */
353
    public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void
354
    {
355
        Assert::true(
356
            $this->responseChecker->isCreationSuccessful($this->client->getLastResponse()),
357
            'Shipping method could not be created'
358
        );
359
    }
360
361
    /**
362
     * @Then the shipping method :shippingMethod should be available in channel :channel
363
     */
364
    public function theShippingMethodShouldBeAvailableInChannel(ShippingMethodInterface $shippingMethod, ChannelInterface $channel): void
365
    {
366
        Assert::true(
367
            $this->responseChecker->hasValueInCollection(
368
                $this->client->show($shippingMethod->getCode()),
369
                'channels',
370
                $this->iriConverter->getIriFromItem($channel)
371
            ),
372
            sprintf('Shipping method is not assigned to %s channel', $channel->getName())
373
        );
374
    }
375
376
    /**
377
     * @Then /^(this shipping method) name should be "([^"]+)"$/
378
     * @Then /^(this shipping method) should still be named "([^"]+)"$/
379
     */
380
    public function thisShippingMethodNameShouldBe(ShippingMethodInterface $shippingMethod, string $name): void
381
    {
382
        Assert::true(
383
            $this->responseChecker->hasTranslation(
384
                $this->client->show($shippingMethod->getCode()),
385
                'en_US',
386
                'name',
387
                $name
388
            ),
389
            'Shipping method name has not been changed'
390
        );
391
    }
392
393
    /**
394
     * @Then /^(this shipping method) should be disabled$/
395
     */
396
    public function thisShippingMethodShouldBeDisabled(ShippingMethodInterface $shippingMethod): void
397
    {
398
        Assert::true(
399
            $this->responseChecker->hasValue(
400
                $this->client->show($shippingMethod->getCode()),
401
                'enabled',
402
                false
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
403
            ),
404
            'Shipping method name is not disabled'
405
        );
406
    }
407
408
    /**
409
     * @Then /^(this shipping method) should be enabled$/
410
     */
411
    public function thisShippingMethodShouldBeEnabled(ShippingMethodInterface $shippingMethod): void
412
    {
413
        Assert::true(
414
            $this->responseChecker->hasValue(
415
                $this->client->show($shippingMethod->getCode()),
416
                'enabled',
417
                true
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
418
            ),
419
            'Shipping method name is not disabled'
420
        );
421
    }
422
423
    /**
424
     * @Then I should not be able to edit its code
425
     */
426
    public function iShouldNotBeAbleToEditItsCode(): void
427
    {
428
        $this->client->addRequestData('code', 'NEW_CODE');
429
430
        Assert::false(
431
            $this->responseChecker->hasValue($this->client->update(), 'code', 'NEW_CODE'),
432
            'The code field with value NEW_CODE exist'
433
        );
434
    }
435
436
    /**
437
     * @Then I should be notified that it has been successfully edited
438
     */
439
    public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void
440
    {
441
        Assert::true(
442
            $this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()),
443
            'Shipping method could not be edited'
444
        );
445
    }
446
447
    /**
448
     * @Then I should be notified that shipping method with this code already exists
449
     */
450
    public function iShouldBeNotifiedThatShippingMethodWithThisCodeAlreadyExists(): void
451
    {
452
        $response = $this->client->getLastResponse();
453
        Assert::false(
454
            $this->responseChecker->isCreationSuccessful($response),
455
            'Shipping method  has been created successfully, but it should not'
456
        );
457
        Assert::same(
458
            $this->responseChecker->getError($response),
459
            'code: The shipping method with given code already exists.'
460
        );
461
    }
462
463
    /**
464
     * @Then there should still be only one shipping method with code :value
465
     */
466
    public function thereShouldStillBeOnlyOneShippingMethodWith(string $value): void
467
    {
468
        $response = $this->client->index();
469
        $itemsCount = $this->responseChecker->countCollectionItems($response);
470
471
        Assert::same($itemsCount, 1, sprintf('Expected 1 shipping method, but got %d', $itemsCount));
472
        Assert::true($this->responseChecker->hasItemWithValue($response, 'code', $value));
473
    }
474
475
    /**
476
     * @Then the only shipping method on the list should be :name
477
     */
478
    public function theOnlyShippingMethodOnTheListShouldBe(string $name): void
479
    {
480
        $response = $this->client->getLastResponse();
481
        $itemsCount = $this->responseChecker->countCollectionItems($response);
482
483
        Assert::same($itemsCount, 1, sprintf('Expected 1 shipping method, but got %d', $itemsCount));
484
        Assert::true($this->responseChecker->hasItemWithTranslation($response, 'en_US', 'name', $name));
485
    }
486
487
    /**
488
     * @Then I should see :amount shipping methods on the list
489
     */
490
    public function iShouldSeeShippingMethodOnTheList(int $amount): void
491
    {
492
        $response = $this->client->getLastResponse();
493
        $itemsCount = $this->responseChecker->countCollectionItems($response);
494
495
        Assert::same($itemsCount, $amount, sprintf('Expected 1 shipping method, but got %d', $itemsCount));
496
    }
497
498
    /**
499
     * @Then I should be notified that it is in use
500
     */
501
    public function iShouldBeNotifiedThatItIsInUse(): void
502
    {
503
        Assert::contains(
504
            $this->responseChecker->getError($this->client->getLastResponse()),
505
            'Cannot delete, the shipping method is in use.'
506
        );
507
    }
508
509
    /**
510
     * @Then I should be notified that :element is required
511
     */
512
    public function iShouldBeNotifiedThatElementIsRequired(string $element): void
513
    {
514
        Assert::contains(
515
            $this->responseChecker->getError($this->client->getLastResponse()),
516
            sprintf('%s: Please enter shipping method %s.', $element, $element)
517
        );
518
    }
519
520
    /**
521
     * @Then I should be notified that zone has to be selected
522
     */
523
    public function iShouldBeNotifiedThatZoneHasToBeSelected(): void
524
    {
525
        Assert::contains(
526
            $this->responseChecker->getError($this->client->getLastResponse()),
527
            'zone: Please select shipping method zone.'
528
        );
529
    }
530
531
    /**
532
     * @Then shipping method with :element :value should not be added
533
     */
534
    public function theShippingMethodWithElementValueShouldNotBeAdded(string $element, string $value): void
535
    {
536
        Assert::false(
537
            $this->responseChecker->hasItemWithValue($this->client->index(), $element, $value),
538
            sprintf('Shipping method should not have %s "%s", but it does,', $element, $value)
539
        );
540
    }
541
542
    /**
543
     * @Then the first shipping method on the list should have code :value
544
     */
545
    public function theFirstProductOnTheListShouldHave(string $value): void
546
    {
547
        $shippingMethods = $this->responseChecker->getCollection($this->client->getLastResponse());
548
549
        Assert::same(reset($shippingMethods)['code'], $value);
550
    }
551
552
    /**
553
     * @Then the first shipping method on the list should have name :value
554
     */
555
    public function theFirstShippingMethodOnTheListShouldHave(string $value): void
556
    {
557
        $shippingMethods = $this->responseChecker->getCollection($this->client->getLastResponse());
558
559
        Assert::same(reset($shippingMethods)['translations'][$this->getAdminLocaleCode()]['name'], $value);
560
    }
561
562
    /**
563
     * @Then the last shipping method on the list should have name :value
564
     */
565
    public function theLastShippingMethodOnTheListShouldHave(string $value): void
566
    {
567
        $shippingMethods = $this->responseChecker->getCollection($this->client->getLastResponse());
568
569
        Assert::same(end($shippingMethods)['translations']['en_US']['name'], $value);
570
    }
571
572
    /**
573
     * @Then I should be viewing non archival shipping methods
574
     */
575
    public function iShouldBeViewingNonArchivalShippingMethods(): void
576
    {
577
        // Intentionally left blank
578
    }
579
580
    private function getAdminLocaleCode(): string
581
    {
582
        /** @var AdminUserInterface $adminUser */
583
        $adminUser = $this->sharedStorage->get('administrator');
584
585
        $response = $this->adminUsersClient->show((string) $adminUser->getId());
586
587
        return $this->responseChecker->getValue($response, 'localeCode');
588
    }
589
}
590