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

CartsRestApiFixturesTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 44
dl 0
loc 116
c 1
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createPersistentQuote() 0 23 1
A mapProductConcreteTransfersToQuoteTransferItems() 0 17 2
A getStoreFacade() 0 3 1
A createGuestCustomerReference() 0 3 1
A createProduct() 0 22 1
A createEmptyQuote() 0 4 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\Carts\RestApi\Fixtures;
9
10
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...
11
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...
12
use Generated\Shared\Transfer\MoneyValueTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\MoneyValueTransfer 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\PriceProductTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PriceProductTransfer 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\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...
15
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer 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\StockProductTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StockProductTransfer 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 Generated\Shared\Transfer\StoreTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreTransfer 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...
18
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...
19
use PyzTest\Glue\Carts\CartsApiTester;
20
use Spryker\Shared\Price\PriceConfig;
21
use Spryker\Zed\Store\Business\StoreFacadeInterface;
22
23
trait CartsRestApiFixturesTrait
24
{
25
    /**
26
     * @return string
27
     */
28
    protected function createGuestCustomerReference(): string
29
    {
30
        return uniqid('testReference', true);
31
    }
32
33
    /**
34
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
35
     * @param string $customerReference
36
     *
37
     * @return \Generated\Shared\Transfer\QuoteTransfer
38
     */
39
    protected function createEmptyQuote(CartsApiTester $I, string $customerReference): QuoteTransfer
40
    {
41
        return $I->havePersistentQuote([
42
            QuoteTransfer::CUSTOMER => (new CustomerTransfer())->setCustomerReference($customerReference),
43
        ]);
44
    }
45
46
    /**
47
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
48
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
49
     * @param array<\Generated\Shared\Transfer\ProductConcreteTransfer> $productConcreteTransfers
50
     *
51
     * @return \Generated\Shared\Transfer\QuoteTransfer
52
     */
53
    protected function createPersistentQuote(
54
        CartsApiTester $I,
55
        CustomerTransfer $customerTransfer,
56
        array $productConcreteTransfers,
57
    ): QuoteTransfer {
58
        $quoteTransfer = $I->havePersistentQuote([
59
            QuoteTransfer::CUSTOMER => $customerTransfer,
60
            QuoteTransfer::TOTALS => (new TotalsTransfer())
61
                ->setSubtotal(random_int(1000, 10000))
62
                ->setPriceToPay(random_int(1000, 10000)),
63
            QuoteTransfer::ITEMS => $this->mapProductConcreteTransfersToQuoteTransferItems($productConcreteTransfers),
64
            QuoteTransfer::STORE => [
65
                StoreTransfer::NAME => 'DE',
66
                StoreTransfer::DEFAULT_CURRENCY_ISO_CODE => 'EUR',
67
                StoreTransfer::AVAILABLE_CURRENCY_ISO_CODES => ['EUR'],
68
            ],
69
            QuoteTransfer::PRICE_MODE => PriceConfig::PRICE_MODE_GROSS,
70
        ]);
71
72
        $quoteTransfer = $I->getLocator()->cart()->facade()->reloadItems($quoteTransfer);
73
        $I->getLocator()->quote()->facade()->updateQuote($quoteTransfer);
74
75
        return $quoteTransfer;
76
    }
77
78
    /**
79
     * @param array<\Generated\Shared\Transfer\ProductConcreteTransfer> $productConcreteTransfers
80
     *
81
     * @return array
82
     */
83
    protected function mapProductConcreteTransfersToQuoteTransferItems(array $productConcreteTransfers): array
84
    {
85
        $quoteTransferItems = [];
86
87
        foreach ($productConcreteTransfers as $productConcreteTransfer) {
88
            $quoteTransferItems[] = [
89
                ItemTransfer::SKU => $productConcreteTransfer->getSku(),
90
                ItemTransfer::GROUP_KEY => $productConcreteTransfer->getSku(),
91
                ItemTransfer::ABSTRACT_SKU => $productConcreteTransfer->getAbstractSku(),
92
                ItemTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(),
93
                ItemTransfer::UNIT_PRICE => random_int(100, 1000),
94
                ItemTransfer::UNIT_GROSS_PRICE => random_int(100, 1000),
95
                ItemTransfer::QUANTITY => 1,
96
            ];
97
        }
98
99
        return $quoteTransferItems;
100
    }
101
102
    /**
103
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
104
     *
105
     * @return \Generated\Shared\Transfer\ProductConcreteTransfer
106
     */
107
    protected function createProduct(CartsApiTester $I): ProductConcreteTransfer
108
    {
109
        $productConcreteTransfer = $I->haveFullProduct();
110
111
        $I->haveProductInStockForStore($this->getStoreFacade($I)->getCurrentStore(), [
112
            StockProductTransfer::SKU => $productConcreteTransfer->getSku(),
113
            StockProductTransfer::IS_NEVER_OUT_OF_STOCK => 1,
114
        ]);
115
116
        $priceProductOverride = [
117
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
118
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
119
            PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
120
            PriceProductTransfer::PRICE_TYPE_NAME => 'DEFAULT',
121
            PriceProductTransfer::MONEY_VALUE => [
122
                MoneyValueTransfer::NET_AMOUNT => 777,
123
                MoneyValueTransfer::GROSS_AMOUNT => 888,
124
            ],
125
        ];
126
        $I->havePriceProduct($priceProductOverride);
127
128
        return $productConcreteTransfer;
129
    }
130
131
    /**
132
     * @param \PyzTest\Glue\Carts\CartsApiTester $I
133
     *
134
     * @return \Spryker\Zed\Store\Business\StoreFacadeInterface
135
     */
136
    protected function getStoreFacade(CartsApiTester $I): StoreFacadeInterface
137
    {
138
        return $I->getLocator()->store()->facade();
139
    }
140
}
141