Completed
Push — master ( 0541e3...1b0cb6 )
by Ilya
55s queued 18s
created

configureStateMachine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
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
declare(strict_types = 1);
9
10
namespace PyzTest\Glue\OrderAmendments\RestApi\Fixtures;
11
12
use ArrayObject;
13
use Generated\Shared\DataBuilder\QuoteBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\QuoteBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Generated\Shared\Transfer\CustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CustomerTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Generated\Shared\Transfer\SaveOrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\SaveOrderTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester;
18
use SprykerTest\Shared\Testify\Fixtures\FixturesBuilderInterface;
19
use SprykerTest\Shared\Testify\Fixtures\FixturesContainerInterface;
20
21
/**
22
 * Auto-generated group annotations
23
 *
24
 * @group PyzTest
25
 * @group Glue
26
 * @group Carts
27
 * @group RestApi
28
 * @group OrderAmendmentRestApiFixtures
29
 * Add your own group annotations below this line
30
 * @group EndToEnd
31
 */
32
class OrderAmendmentRestApiFixtures implements FixturesBuilderInterface, FixturesContainerInterface
33
{
34
    /**
35
     * @var string
36
     */
37
    protected const TEST_USERNAME = 'OrderAmendmentRestApiFixtures';
38
39
    /**
40
     * @var string
41
     */
42
    protected const TEST_PASSWORD = 'change123';
43
44
    /**
45
     * @var string
46
     */
47
    protected const STATE_MACHINE_NAME = 'DummyPayment01';
48
49
    /**
50
     * @var string
51
     */
52
    protected const ORDER_ITEM_STATE_GRACE_PERIOD_STARTED = 'grace period started';
53
54
    /**
55
     * @var string
56
     */
57
    protected const ORDER_ITEM_STATE_PAID = 'paid';
58
59
    /**
60
     * @var string
61
     */
62
    protected const PRICE_MODE_GROSS = 'GROSS_MODE';
63
64
    /**
65
     * @var \Generated\Shared\Transfer\CustomerTransfer
66
     */
67
    protected CustomerTransfer $customerTransfer;
68
69
    /**
70
     * @var \Generated\Shared\Transfer\SaveOrderTransfer
71
     */
72
    protected SaveOrderTransfer $readyForAmendmentOrderTransfer;
73
74
    /**
75
     * @var \Generated\Shared\Transfer\SaveOrderTransfer
76
     */
77
    protected SaveOrderTransfer $notReadyForAmendmentOrderTransfer;
78
79
    /**
80
     * @return \Generated\Shared\Transfer\CustomerTransfer
81
     */
82
    public function getCustomerTransfer(): CustomerTransfer
83
    {
84
        return $this->customerTransfer;
85
    }
86
87
    /**
88
     * @return \Generated\Shared\Transfer\SaveOrderTransfer
89
     */
90
    public function getReadyForAmendmentOrderTransfer(): SaveOrderTransfer
91
    {
92
        return $this->readyForAmendmentOrderTransfer;
93
    }
94
95
    /**
96
     * @return \Generated\Shared\Transfer\SaveOrderTransfer
97
     */
98
    public function getNotReadyForAmendmentOrderTransfer(): SaveOrderTransfer
99
    {
100
        return $this->notReadyForAmendmentOrderTransfer;
101
    }
102
103
    /**
104
     * @param \PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester $I
105
     *
106
     * @return \SprykerTest\Shared\Testify\Fixtures\FixturesContainerInterface
107
     */
108
    public function buildFixtures(OrderAmendmentsApiTester $I): FixturesContainerInterface
109
    {
110
        $this->configureStateMachine($I);
111
        $this->customerTransfer = $this->createCustomerTransfer($I);
112
113
        $this->readyForAmendmentOrderTransfer = $this->createOrderWithProductConcretes($I);
114
        $this->setOrderItemsState(
115
            $I,
116
            $this->readyForAmendmentOrderTransfer->getOrderItems(),
117
            static::ORDER_ITEM_STATE_GRACE_PERIOD_STARTED,
118
        );
119
120
        $this->notReadyForAmendmentOrderTransfer = $this->createOrderWithProductConcretes($I);
121
        $this->setOrderItemsState(
122
            $I,
123
            $this->notReadyForAmendmentOrderTransfer->getOrderItems(),
124
            static::ORDER_ITEM_STATE_PAID,
125
        );
126
127
        return $this;
128
    }
129
130
    /**
131
     * @param \PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester $I
132
     *
133
     * @return \Generated\Shared\Transfer\CustomerTransfer
134
     */
135
    protected function createCustomerTransfer(OrderAmendmentsApiTester $I): CustomerTransfer
136
    {
137
        $customerTransfer = $I->haveCustomer([
138
            CustomerTransfer::USERNAME => static::TEST_USERNAME,
139
            CustomerTransfer::PASSWORD => static::TEST_PASSWORD,
140
            CustomerTransfer::NEW_PASSWORD => static::TEST_PASSWORD,
141
        ]);
142
143
        return $I->confirmCustomer($customerTransfer);
144
    }
145
146
    /**
147
     * @param \PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester $I
148
     *
149
     * @return \Generated\Shared\Transfer\SaveOrderTransfer
150
     */
151
    protected function createOrderWithProductConcretes(OrderAmendmentsApiTester $I): SaveOrderTransfer
152
    {
153
        $product1Transfer = $I->haveProductWithPriceAndStock();
154
        $product2Transfer = $I->haveProductWithPriceAndStock();
155
        $quoteTransfer = (new QuoteBuilder())
156
            ->withCustomer([CustomerTransfer::CUSTOMER_REFERENCE => $this->customerTransfer->getCustomerReference()])
157
            ->withItem([
158
                ItemTransfer::SKU => $product1Transfer->getSkuOrFail(),
159
                ItemTransfer::QUANTITY => 1,
160
            ])
161
            ->withItem([
162
                ItemTransfer::SKU => $product2Transfer->getSkuOrFail(),
163
                ItemTransfer::QUANTITY => 2,
164
            ])
165
            ->withTotals()
166
            ->withShippingAddress()
167
            ->withBillingAddress()
168
            ->withCurrency()
169
            ->withPayment()
170
            ->build();
171
172
        $quoteTransfer->setPriceMode(static::PRICE_MODE_GROSS);
173
174
        return $I->haveOrderFromQuote($quoteTransfer, static::STATE_MACHINE_NAME);
175
    }
176
177
    /**
178
     * @param \PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester $I
179
     * @param \ArrayObject<array-key, \Generated\Shared\Transfer\ItemTransfer> $itemTransfers
180
     * @param string $stateName
181
     *
182
     * @return void
183
     */
184
    protected function setOrderItemsState(OrderAmendmentsApiTester $I, ArrayObject $itemTransfers, string $stateName): void
185
    {
186
        foreach ($itemTransfers as $itemTransfer) {
187
            $I->setItemState($itemTransfer->getIdSalesOrderItemOrFail(), $stateName);
188
        }
189
    }
190
191
    /**
192
     * @param \PyzTest\Glue\OrderAmendments\OrderAmendmentsApiTester $I
193
     *
194
     * @return void
195
     */
196
    protected function configureStateMachine(OrderAmendmentsApiTester $I): void
197
    {
198
        $I->configureTestStateMachine([static::STATE_MACHINE_NAME]);
199
    }
200
}
201