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

OrdersRestApiFixtures::createStateMachine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
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\Orders\RestApi;
9
10
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...
11
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...
12
use Generated\Shared\Transfer\ProductConcreteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ProductConcreteTransfer 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...
13
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...
14
use Generated\Shared\Transfer\TotalsTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\TotalsTransfer 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 PyzTest\Glue\Orders\OrdersApiTester;
16
use Spryker\Shared\Kernel\Transfer\AbstractTransfer;
17
use SprykerTest\Shared\Testify\Fixtures\FixturesBuilderInterface;
18
use SprykerTest\Shared\Testify\Fixtures\FixturesContainerInterface;
19
20
/**
21
 * Auto-generated group annotations
22
 *
23
 * @group PyzTest
24
 * @group Glue
25
 * @group Orders
26
 * @group RestApi
27
 * Add your own group annotations below this line
28
 * @group EndToEnd
29
 */
30
class OrdersRestApiFixtures implements FixturesBuilderInterface, FixturesContainerInterface
31
{
32
    /**
33
     * @var string
34
     */
35
    protected const TEST_USERNAME = 'test username';
36
37
    /**
38
     * @var string
39
     */
40
    protected const TEST_PASSWORD = 'change123';
41
42
    /**
43
     * @var int
44
     */
45
    protected const TEST_GRAND_TOTAL = 1;
46
47
    /**
48
     * @var \Generated\Shared\Transfer\SaveOrderTransfer
49
     */
50
    protected SaveOrderTransfer $saveOrderTransfer;
51
52
    /**
53
     * @var \Generated\Shared\Transfer\CustomerTransfer
54
     */
55
    protected CustomerTransfer $customerWithoutOrders;
56
57
    /**
58
     * @var \Generated\Shared\Transfer\CustomerTransfer
59
     */
60
    protected CustomerTransfer $customerWithOrders;
61
62
    /**
63
     * @return \Generated\Shared\Transfer\CustomerTransfer
64
     */
65
    public function getCustomerWithoutOrders(): CustomerTransfer
66
    {
67
        return $this->customerWithoutOrders;
68
    }
69
70
    /**
71
     * @return \Generated\Shared\Transfer\CustomerTransfer
72
     */
73
    public function getCustomerWithOrders(): CustomerTransfer
74
    {
75
        return $this->customerWithOrders;
76
    }
77
78
    /**
79
     * @return \Generated\Shared\Transfer\SaveOrderTransfer
80
     */
81
    public function geSaveOrderTransfer(): SaveOrderTransfer
82
    {
83
        return $this->saveOrderTransfer;
84
    }
85
86
    /**
87
     * @param \PyzTest\Glue\Orders\OrdersApiTester $I
88
     *
89
     * @return \SprykerTest\Shared\Testify\Fixtures\FixturesContainerInterface
90
     */
91
    public function buildFixtures(OrdersApiTester $I): FixturesContainerInterface
92
    {
93
        $this->customerWithoutOrders = $this->createCustomerTransfer($I, static::TEST_USERNAME, static::TEST_PASSWORD);
94
95
        $this->saveOrderTransfer = $this->createOrderTransfer($I);
96
97
        return $this;
98
    }
99
100
    /**
101
     * @param \PyzTest\Glue\Orders\OrdersApiTester $I
102
     *
103
     * @return \Generated\Shared\Transfer\ProductConcreteTransfer
104
     */
105
    public function createProductTransfer(OrdersApiTester $I): ProductConcreteTransfer
106
    {
107
        return $I->haveProduct();
108
    }
109
110
    /**
111
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
112
     * @param array $productTransfers
113
     *
114
     * @return \Spryker\Shared\Kernel\Transfer\AbstractTransfer
115
     */
116
    public function createQuoteTransfer(CustomerTransfer $customerTransfer, array $productTransfers): AbstractTransfer
117
    {
118
        return (new QuoteBuilder())
119
            ->withItem($productTransfers)
120
            ->withCustomer([CustomerTransfer::CUSTOMER_REFERENCE => $customerTransfer->getCustomerReference()])
121
            ->withTotals([TotalsTransfer::GRAND_TOTAL => static::TEST_GRAND_TOTAL])
122
            ->withShippingAddress()
123
            ->withBillingAddress()
124
            ->withCurrency()
125
            ->withPayment()
126
            ->build();
127
    }
128
129
    /**
130
     * @param \PyzTest\Glue\Orders\OrdersApiTester $I
131
     *
132
     * @return \Generated\Shared\Transfer\SaveOrderTransfer
133
     */
134
    protected function createOrderTransfer(OrdersApiTester $I): SaveOrderTransfer
135
    {
136
        $this->customerWithOrders = $this->createCustomerTransfer($I, static::TEST_USERNAME, static::TEST_PASSWORD);
137
        $quote = $this->createQuoteTransfer($this->customerWithOrders, [$this->createProductTransfer($I)]);
138
139
        return $I->haveOrderFromQuote($quote, $this->createStateMachine($I));
140
    }
141
142
    /**
143
     * @param \PyzTest\Glue\Orders\OrdersApiTester $I
144
     *
145
     * @return string
146
     */
147
    protected function createStateMachine(OrdersApiTester $I): string
148
    {
149
        $testStateMachineProcessName = 'DummyPayment01';
150
        $I->configureTestStateMachine([$testStateMachineProcessName]);
151
152
        return $testStateMachineProcessName;
153
    }
154
155
    /**
156
     * @param \PyzTest\Glue\Orders\OrdersApiTester $I
157
     * @param string $name
158
     * @param string $password
159
     *
160
     * @return \Generated\Shared\Transfer\CustomerTransfer
161
     */
162
    protected function createCustomerTransfer(OrdersApiTester $I, string $name, string $password): CustomerTransfer
163
    {
164
        $customerTransfer = $I->haveCustomer([
165
            CustomerTransfer::USERNAME => $name,
166
            CustomerTransfer::PASSWORD => $password,
167
            CustomerTransfer::NEW_PASSWORD => $password,
168
        ]);
169
170
        return $I->confirmCustomer($customerTransfer);
171
    }
172
}
173