Completed
Push — api ( cecea0...116a36 )
by Kamil
29:57 queued 30s
created

ManagingCurrenciesContext::iAddIt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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 Behat\Behat\Context\Context;
17
use Sylius\Behat\Client\ApiClientInterface;
18
use Webmozart\Assert\Assert;
19
20
final class ManagingCurrenciesContext implements Context
21
{
22
    /** @var ApiClientInterface */
23
    private $client;
24
25
    public function __construct(ApiClientInterface $client)
26
    {
27
        $this->client = $client;
28
    }
29
30
    /**
31
     * @When I want to browse currencies of the store
32
     */
33
    public function iWantToSeeAllCurrenciesInStore(): void
34
    {
35
        $this->client->index('currencies');
36
    }
37
38
    /**
39
     * @When I want to add a new currency
40
     */
41
    public function iWantToAddNewCurrency(): void
42
    {
43
        $this->client->buildCreateRequest('currencies');
44
    }
45
46
    /**
47
     * @When I choose :currencyCode
48
     */
49
    public function iChoose(string $currencyCode): void
50
    {
51
        $this->client->addRequestData('code', $currencyCode);
52
    }
53
54
    /**
55
     * @When I add it
56
     * @When I try to add it
57
     */
58
    public function iAddIt(): void
59
    {
60
        $this->client->create();
61
    }
62
63
    /**
64
     * @Then I should see :count currencies in the list
65
     */
66
    public function iShouldSeeCurrenciesInTheList(int $count): void
67
    {
68
        $itemsCount = $this->client->countCollectionItems();
69
70
        Assert::eq($count, $itemsCount, sprintf('Expected %d currencies, but got %d', $count, $itemsCount));
71
    }
72
73
    /**
74
     * @Then I should see the currency :currencyName in the list
75
     * @Then the currency :currencyName should appear in the store
76
     */
77
    public function currencyShouldAppearInTheStore(string $currencyName): void
78
    {
79
        $this->client->index('currencies');
80
        Assert::true(
81
            $this->client->hasItemWithValue('name', $currencyName),
82
            sprintf('There is no currency with name "%s"', $currencyName)
83
        );
84
    }
85
86
    /**
87
     * @Then there should still be only one currency with code :code
88
     */
89
    public function thereShouldStillBeOnlyOneCurrencyWithCode(string $code): void
90
    {
91
        $this->client->index('currencies');
92
        Assert::eq(1, $this->client->countCollectionItems());
93
        Assert::true($this->client->hasItemWithValue('code', $code), sprintf('There is no currency with code "%s"', $code));
94
    }
95
96
    /**
97
     * @Then I should be notified that currency code must be unique
98
     */
99
    public function iShouldBeNotifiedThatCurrencyCodeMustBeUnique(): void
100
    {
101
        Assert::false($this->client->isCreationSuccessful(), 'Currency has been created successfully, but it should not');
102
        Assert::same($this->client->getError(), 'code: Currency code must be unique.');
103
    }
104
}
105