PaymentStepTest::shipmentDataProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
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\Yves\Checkout\Process\Steps;
11
12
use Codeception\Test\Unit;
13
use Generated\Shared\DataBuilder\PaymentMethodsBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\PaymentMethodsBuilder 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\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...
15
use Generated\Shared\Transfer\PaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentTransfer 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\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...
17
use PyzTest\Yves\Checkout\CheckoutBusinessTester;
18
use Spryker\Yves\Messenger\FlashMessenger\FlashMessengerInterface;
19
use Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginCollection;
20
use Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginInterface;
21
use SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToCalculationClientBridge;
22
use SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToCalculationClientInterface;
23
use SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToPaymentClientInterface;
24
use SprykerShop\Yves\CheckoutPage\Extractor\PaymentMethodKeyExtractor;
25
use SprykerShop\Yves\CheckoutPage\Process\Steps\PaymentStep;
26
use Symfony\Component\HttpFoundation\Request;
27
28
/**
29
 * Auto-generated group annotations
30
 *
31
 * @group PyzTest
32
 * @group Yves
33
 * @group Checkout
34
 * @group Process
35
 * @group Steps
36
 * @group PaymentStepTest
37
 * Add your own group annotations below this line
38
 */
39
class PaymentStepTest extends Unit
40
{
41
    /**
42
     * @var \PyzTest\Yves\Checkout\CheckoutBusinessTester:
43
     */
44
    protected CheckoutBusinessTester $tester;
45
46
    /**
47
     * @dataProvider executeDataProvider
48
     *
49
     * @param \SprykerShop\Yves\CheckoutPage\Process\Steps\PaymentStep $paymentStep
50
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
51
     *
52
     * @return void
53
     */
54
    public function testExecuteShouldSelectPlugin(PaymentStep $paymentStep, QuoteTransfer $quoteTransfer): void
55
    {
56
        $paymentStep->execute($this->createRequest(), $quoteTransfer);
57
    }
58
59
    /**
60
     * @dataProvider postConditionsDataProvider
61
     *
62
     * @param \SprykerShop\Yves\CheckoutPage\Process\Steps\PaymentStep $paymentStep
63
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
64
     *
65
     * @return void
66
     */
67
    public function testPostConditionsShouldReturnTrueWhenPaymentSet(
68
        PaymentStep $paymentStep,
69
        QuoteTransfer $quoteTransfer,
70
    ): void {
71
        // Act
72
        $postConditionFulfilled = $paymentStep->postCondition($quoteTransfer);
73
74
        // Assert
75
        $this->assertTrue($postConditionFulfilled);
76
    }
77
78
    /**
79
     * @dataProvider shipmentDataProvider
80
     *
81
     * @param \SprykerShop\Yves\CheckoutPage\Process\Steps\PaymentStep $paymentStep
82
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
83
     *
84
     * @return void
85
     */
86
    public function testShipmentRequireInputShouldReturnTrue(
87
        PaymentStep $paymentStep,
88
        QuoteTransfer $quoteTransfer,
89
    ): void {
90
        // Act
91
        $isInputRequired = $paymentStep->requireInput($quoteTransfer);
92
93
        // Assert
94
        $this->assertTrue($isInputRequired);
95
    }
96
97
    /**
98
     * @return array
99
     */
100
    public function executeDataProvider(): array
101
    {
102
        return [
103
            'payment step executes without an error' => $this->addDataForExecuteDataProvider(),
104
        ];
105
    }
106
107
    /**
108
     * @return array
109
     */
110
    protected function addDataForExecuteDataProvider(): array
111
    {
112
        $paymentPluginMock = $this->createPaymentPluginMock();
113
        $paymentPluginMock->expects($this->once())->method('addToDataClass');
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Spryker\Yves\StepEngine\...pHandlerPluginInterface. ( Ignorable by Annotation )

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

113
        $paymentPluginMock->/** @scrutinizer ignore-call */ 
114
                            expects($this->once())->method('addToDataClass');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
114
115
        $stepHandlerPluginCollection = new StepHandlerPluginCollection();
116
        $stepHandlerPluginCollection->add($paymentPluginMock, 'test');
117
118
        $paymentStep = $this->createPaymentStep($stepHandlerPluginCollection);
119
120
        $paymentTransfer = (new PaymentTransfer())
121
            ->setPaymentSelection('test');
122
        $quoteTransfer = (new QuoteTransfer())->setPayment($paymentTransfer);
123
124
        return [$paymentStep, $quoteTransfer];
125
    }
126
127
    /**
128
     * @return array
129
     */
130
    public function postConditionsDataProvider(): array
131
    {
132
        return [
133
            'post condition is fulfilled' => $this->addDataForPostConditionsDataProvider(),
134
        ];
135
    }
136
137
    /**
138
     * @return array
139
     */
140
    protected function addDataForPostConditionsDataProvider(): array
141
    {
142
        $paymentStep = $this->createPaymentStep(new StepHandlerPluginCollection());
143
        $quoteTransfer = (new QuoteBuilder())
144
            ->withPayment([
145
                'paymentProvider' => 'test',
146
                'paymentSelection' => 'test',
147
            ])
148
            ->build();
149
        $quoteTransfer->setPayment($quoteTransfer->getPayments()[0]);
150
151
        return [$paymentStep, $quoteTransfer];
152
    }
153
154
    /**
155
     * @return array
156
     */
157
    public function shipmentDataProvider(): array
158
    {
159
        return [
160
            'shipment required input is not provided' => $this->addDataForShipmentDataProvider(),
161
        ];
162
    }
163
164
    /**
165
     * @return array
166
     */
167
    protected function addDataForShipmentDataProvider(): array
168
    {
169
        $paymentStep = $this->createPaymentStep(new StepHandlerPluginCollection());
170
        $quoteTransfer = (new QuoteBuilder())
171
            ->build();
172
173
        return [$paymentStep, $quoteTransfer];
174
    }
175
176
    /**
177
     * @param \Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginCollection $paymentPlugins
178
     *
179
     * @return \SprykerShop\Yves\CheckoutPage\Process\Steps\PaymentStep
180
     */
181
    protected function createPaymentStep(StepHandlerPluginCollection $paymentPlugins): PaymentStep
182
    {
183
        return new PaymentStep(
184
            $this->getPaymentClientMock(),
185
            $paymentPlugins,
186
            'payment',
187
            'escape_route',
188
            $this->getFlashMessengerMock(),
189
            $this->getCalculationClientMock(),
190
            $this->getCheckoutPaymentStepEnterPreCheckPlugins(),
191
            new PaymentMethodKeyExtractor(),
192
        );
193
    }
194
195
    /**
196
     * @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToPaymentClientInterface
197
     */
198
    public function getPaymentClientMock(): CheckoutPageToPaymentClientInterface
199
    {
200
        $paymentClientMock = $this->getMockBuilder(CheckoutPageToPaymentClientInterface::class)
201
            ->disableOriginalConstructor()
202
            ->onlyMethods(['getAvailableMethods'])
203
            ->getMock();
204
205
        $paymentMethodsTransfer = (new PaymentMethodsBuilder())
206
            ->withMethod([
207
                'methodName' => 'test',
208
            ])
209
            ->build();
210
211
        $paymentClientMock
212
            ->method('getAvailableMethods')
213
            ->willReturn($paymentMethodsTransfer);
214
215
        return $paymentClientMock;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $paymentClientMock returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return SprykerShop\Yves\Checkou...oPaymentClientInterface.
Loading history...
216
    }
217
218
    /**
219
     * @return \Symfony\Component\HttpFoundation\Request
220
     */
221
    protected function createRequest(): Request
222
    {
223
        return Request::createFromGlobals();
224
    }
225
226
    /**
227
     * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginInterface
228
     */
229
    protected function createPaymentPluginMock(): StepHandlerPluginInterface
230
    {
231
        return $this->getMockBuilder(StepHandlerPluginInterface::class)->getMock();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockBui...face::class)->getMock() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Spryker\Yves\StepEngine\...pHandlerPluginInterface.
Loading history...
232
    }
233
234
    /**
235
     * @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToCalculationClientInterface
236
     */
237
    protected function getCalculationClientMock(): CheckoutPageToCalculationClientInterface
238
    {
239
        return $this->getMockBuilder(CheckoutPageToCalculationClientBridge::class)
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockBui...onstructor()->getMock() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return SprykerShop\Yves\Checkou...culationClientInterface.
Loading history...
240
            ->disableOriginalConstructor()
241
            ->getMock();
242
    }
243
244
    /**
245
     * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Yves\Messenger\FlashMessenger\FlashMessengerInterface
246
     */
247
    protected function getFlashMessengerMock(): FlashMessengerInterface
248
    {
249
        return $this->getMockBuilder(FlashMessengerInterface::class)->getMock();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockBui...face::class)->getMock() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Spryker\Yves\Messenger\F...FlashMessengerInterface.
Loading history...
250
    }
251
252
    /**
253
     * @return array<\SprykerShop\Yves\CheckoutPageExtension\Dependency\Plugin\CheckoutPaymentStepEnterPreCheckPluginInterface>
254
     */
255
    public function getCheckoutPaymentStepEnterPreCheckPlugins(): array
256
    {
257
        return [];
258
    }
259
}
260