Issues (3641)

Persistence/Propel/Mapper/QuoteMapperTest.php (1 issue)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerTest\Zed\Quote\Persistence\Propel\Mapper;
9
10
use Codeception\Test\Unit;
11
use Generated\Shared\Transfer\ItemTransfer;
12
use Generated\Shared\Transfer\QuoteTransfer;
13
use Spryker\Service\UtilEncoding\UtilEncodingServiceInterface;
14
use Spryker\Zed\Quote\Business\Quote\QuoteFieldsConfigurator;
15
use Spryker\Zed\Quote\Dependency\Service\QuoteToUtilEncodingServiceBridge;
16
use Spryker\Zed\Quote\Persistence\Propel\Mapper\QuoteMapper;
17
use Spryker\Zed\Quote\QuoteConfig;
18
19
/**
20
 * Auto-generated group annotations
21
 *
22
 * @group SprykerTest
23
 * @group Zed
24
 * @group Quote
25
 * @group Persistence
26
 * @group Propel
27
 * @group Mapper
28
 * @group QuoteMapperTest
29
 * Add your own group annotations below this line
30
 */
31
class QuoteMapperTest extends Unit
32
{
33
    /**
34
     * @var \SprykerTest\Zed\Quote\QuotePersistenceTester
35
     */
36
    protected $tester;
37
38
    /**
39
     * @dataProvider mapTransferToEntityDataProvider
40
     *
41
     * @param array $quoteAllowedFields
42
     * @param array $quoteItemAllowedFields
43
     *
44
     * @return void
45
     */
46
    public function testMapTransferToEntity(array $quoteAllowedFields, array $quoteItemAllowedFields): void
47
    {
48
        // Arrange
49
        $utilEncodingService = $this->getUtilEncodingService();
50
        $quoteFieldsConfigurator = new QuoteFieldsConfigurator($this->createQuoteConfigMock($quoteAllowedFields, $quoteItemAllowedFields));
51
        $quoteMapper = new QuoteMapper(new QuoteToUtilEncodingServiceBridge($utilEncodingService));
52
        $quoteTransfer = $this->tester->createQuoteTransfer();
53
54
        $quoteFieldsAllowedForSaving = $quoteFieldsConfigurator->getQuoteFieldsAllowedForSaving($quoteTransfer);
55
56
        // Act
57
        $updatedQuoteEntity = $quoteMapper->mapTransferToEntity(
58
            $quoteTransfer,
59
            $this->tester->createQuotePropelEntity(),
60
            $quoteFieldsAllowedForSaving,
61
        );
62
        $decodedQuoteData = $utilEncodingService->decodeJson($updatedQuoteEntity->getQuoteData(), true);
63
64
        // Assert
65
        $this->tester->assertContainOnlyAllowedFields($quoteFieldsAllowedForSaving, $decodedQuoteData);
0 ignored issues
show
It seems like $decodedQuoteData can also be of type null and object; however, parameter $decodedQuoteData of SprykerTest\Zed\Quote\Qu...tainOnlyAllowedFields() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        $this->tester->assertContainOnlyAllowedFields($quoteFieldsAllowedForSaving, /** @scrutinizer ignore-type */ $decodedQuoteData);
Loading history...
66
    }
67
68
    /**
69
     * @return \Spryker\Service\UtilEncoding\UtilEncodingServiceInterface
70
     */
71
    protected function getUtilEncodingService(): UtilEncodingServiceInterface
72
    {
73
        return $this->tester->getLocator()->utilEncoding()->service();
74
    }
75
76
    /**
77
     * @param array $quoteAllowedFields
78
     * @param array $quoteItemAllowedFields
79
     *
80
     * @return \Spryker\Zed\Quote\QuoteConfig|\PHPUnit\Framework\MockObject\MockObject
81
     */
82
    protected function createQuoteConfigMock(array $quoteAllowedFields, array $quoteItemAllowedFields): QuoteConfig
83
    {
84
        $quoteConfigMock = $this->getMockBuilder(QuoteConfig::class)
85
            ->onlyMethods(['getQuoteFieldsAllowedForSaving', 'getQuoteItemFieldsAllowedForSaving'])
86
            ->getMock();
87
88
        $quoteConfigMock->method('getQuoteFieldsAllowedForSaving')->willReturn($quoteAllowedFields);
89
        $quoteConfigMock->method('getQuoteItemFieldsAllowedForSaving')->willReturn($quoteItemAllowedFields);
90
91
        return $quoteConfigMock;
92
    }
93
94
    /**
95
     * @return array
96
     */
97
    public function mapTransferToEntityDataProvider(): array
98
    {
99
        return [
100
            [
101
                'quoteAllowedFields' => [
102
                    QuoteTransfer::ITEMS,
103
                    QuoteTransfer::TOTALS,
104
                ],
105
                'quoteItemAllowedFields' => [
106
                    ItemTransfer::SKU,
107
                    ItemTransfer::IMAGES,
108
                ],
109
            ],
110
            [
111
                'quoteAllowedFields' => [
112
                    QuoteTransfer::ITEMS,
113
                    QuoteTransfer::TOTALS,
114
                    QuoteTransfer::CURRENCY,
115
                    QuoteTransfer::PRICE_MODE,
116
                ],
117
                'quoteItemAllowedFields' => [],
118
            ],
119
        ];
120
    }
121
}
122