createShipmentStepPostConditionCheckerMock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 6
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\Yves\Checkout\Process\Steps;
11
12
use Codeception\Test\Unit;
13
use Generated\Shared\Transfer\ExpenseTransfer;
14
use Generated\Shared\Transfer\QuoteTransfer;
15
use Generated\Shared\Transfer\ShipmentTransfer;
16
use Spryker\Shared\Shipment\ShipmentConfig;
17
use Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginCollection;
18
use Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginInterface;
19
use SprykerShop\Yves\CheckoutPage\CheckoutPageDependencyProvider;
20
use SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToCalculationClientInterface;
21
use SprykerShop\Yves\CheckoutPage\Dependency\Service\CheckoutPageToShipmentServiceBridge;
22
use SprykerShop\Yves\CheckoutPage\Dependency\Service\CheckoutPageToShipmentServiceInterface;
23
use SprykerShop\Yves\CheckoutPage\GiftCard\GiftCardItemsChecker;
24
use SprykerShop\Yves\CheckoutPage\GiftCard\GiftCardItemsCheckerInterface;
25
use SprykerShop\Yves\CheckoutPage\Process\Steps\PostConditionCheckerInterface;
26
use SprykerShop\Yves\CheckoutPage\Process\Steps\ShipmentStep;
27
use SprykerShop\Yves\CheckoutPage\Process\Steps\ShipmentStep\PostConditionChecker;
28
use SprykerShop\Yves\CheckoutPageExtension\Dependency\Plugin\CheckoutShipmentStepEnterPreCheckPluginInterface;
29
use SprykerShop\Yves\QuoteApprovalWidget\Plugin\CheckoutPage\QuoteApprovalCheckerCheckoutShipmentStepEnterPreCheckPlugin;
30
use Symfony\Component\HttpFoundation\Request;
31
32
/**
33
 * Auto-generated group annotations
34
 *
35
 * @group PyzTest
36
 * @group Yves
37
 * @group Checkout
38
 * @group Process
39
 * @group Steps
40
 * @group ShipmentStepTest
41
 * Add your own group annotations below this line
42
 */
43
class ShipmentStepTest extends Unit
44
{
45
    /**
46
     * @var \PyzTest\Yves\Checkout\CheckoutBusinessTester
47
     */
48
    public $tester;
49
50
    /**
51
     * @return void
52
     */
53
    public function testShipmentStepExecuteShouldTriggerPlugins(): void
54
    {
55
        $shipmentPluginMock = $this->createShipmentMock();
56
        $shipmentPluginMock->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

56
        $shipmentPluginMock->/** @scrutinizer ignore-call */ 
57
                             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...
57
58
        $shipmentStepHandler = new StepHandlerPluginCollection();
59
        $shipmentStepHandler->add($shipmentPluginMock, CheckoutPageDependencyProvider::PLUGIN_SHIPMENT_STEP_HANDLER);
60
        $shipmentStep = $this->createShipmentStep($shipmentStepHandler);
61
62
        $quoteTransfer = new QuoteTransfer();
63
64
        $shipmentTransfer = new ShipmentTransfer();
65
        $shipmentTransfer->setShipmentSelection(CheckoutPageDependencyProvider::PLUGIN_SHIPMENT_STEP_HANDLER);
66
        $quoteTransfer->setShipment($shipmentTransfer);
67
68
        $shipmentStep->execute($this->createRequest(), $quoteTransfer);
69
    }
70
71
    /**
72
     * @return void
73
     */
74
    public function testShipmentPostConditionsShouldReturnTrueWhenShipmentSet(): void
75
    {
76
        $this->markTestSkipped('This test is skipped because it is no longer relevant after https://spryker.atlassian.net/browse/SUPESC-435.');
77
78
        $quoteTransfer = new QuoteTransfer();
79
        $expenseTransfer = new ExpenseTransfer();
80
        $expenseTransfer->setType(ShipmentConfig::SHIPMENT_EXPENSE_TYPE);
81
        $quoteTransfer->addExpense($expenseTransfer);
82
83
        $shipmentStep = $this->createShipmentStep(new StepHandlerPluginCollection());
84
85
        $this->assertTrue($shipmentStep->postCondition($quoteTransfer));
86
    }
87
88
    /**
89
     * @param \Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginCollection $shipmentPlugins
90
     *
91
     * @return \SprykerShop\Yves\CheckoutPage\Process\Steps\ShipmentStep
92
     */
93
    protected function createShipmentStep(StepHandlerPluginCollection $shipmentPlugins): ShipmentStep
94
    {
95
        $giftCardItemsCheckerMock = $this->createGiftCardItemsCheckerMock();
96
97
        return new ShipmentStep(
98
            $this->createCalculationClientMock(),
99
            $shipmentPlugins,
100
            $this->createShipmentStepPostConditionCheckerMock($giftCardItemsCheckerMock),
0 ignored issues
show
Bug introduced by
$giftCardItemsCheckerMock of type SprykerShop\Yves\Checkou...rdItemsCheckerInterface is incompatible with the type PHPUnit\Framework\MockOb...hipmentServiceInterface expected by parameter $giftCardItemsCheckerMock of PyzTest\Yves\Checkout\Pr...tConditionCheckerMock(). ( Ignorable by Annotation )

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

100
            $this->createShipmentStepPostConditionCheckerMock(/** @scrutinizer ignore-type */ $giftCardItemsCheckerMock),
Loading history...
101
            $giftCardItemsCheckerMock,
102
            CheckoutPageDependencyProvider::PLUGIN_SHIPMENT_STEP_HANDLER,
103
            'escape_route',
104
            $this->getCheckoutShipmentStepEnterPreCheckPlugins(),
105
        );
106
    }
107
108
    /**
109
     * @return \Symfony\Component\HttpFoundation\Request
110
     */
111
    protected function createRequest(): Request
112
    {
113
        return Request::createFromGlobals();
114
    }
115
116
    /**
117
     * @return \SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToCalculationClientInterface
118
     */
119
    protected function createCalculationClientMock(): CheckoutPageToCalculationClientInterface
120
    {
121
        $calculationClientMock = $this->createMock(CheckoutPageToCalculationClientInterface::class);
122
        $calculationClientMock->method('recalculate')
123
            ->willReturnArgument(0);
124
125
        return $calculationClientMock;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $calculationClientMock returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return SprykerShop\Yves\Checkou...culationClientInterface.
Loading history...
126
    }
127
128
    /**
129
     * @return \Spryker\Yves\StepEngine\Dependency\Plugin\Handler\StepHandlerPluginInterface
130
     */
131
    protected function createShipmentMock(): StepHandlerPluginInterface
132
    {
133
        return $this->createMock(StepHandlerPluginInterface::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...PluginInterface::class) returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Spryker\Yves\StepEngine\...pHandlerPluginInterface.
Loading history...
134
    }
135
136
    /**
137
     * @param \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\Dependency\Service\CheckoutPageToShipmentServiceInterface $giftCardItemsCheckerMock
138
     *
139
     * @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\Process\Steps\PostConditionCheckerInterface
140
     */
141
    protected function createShipmentStepPostConditionCheckerMock($giftCardItemsCheckerMock): PostConditionCheckerInterface
142
    {
143
        return $this->getMockBuilder(PostConditionChecker::class)
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockBui...nalMethods()->getMock() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return SprykerShop\Yves\Checkou...nditionCheckerInterface.
Loading history...
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...yingToOriginalMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/5307 ( Ignorable by Annotation )

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

143
        return /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(PostConditionChecker::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
144
            ->setConstructorArgs([$this->createShipmentServiceMock(), $giftCardItemsCheckerMock])
145
            ->enableProxyingToOriginalMethods()
146
            ->getMock();
147
    }
148
149
    /**
150
     * @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\GiftCard\GiftCardItemsCheckerInterface
151
     */
152
    protected function createGiftCardItemsCheckerMock(): GiftCardItemsCheckerInterface
153
    {
154
        return $this->getMockBuilder(GiftCardItemsChecker::class)
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockBui...nalMethods()->getMock() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return SprykerShop\Yves\Checkou...rdItemsCheckerInterface.
Loading history...
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...yingToOriginalMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/5307 ( Ignorable by Annotation )

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

154
        return /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(GiftCardItemsChecker::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
155
            ->enableProxyingToOriginalMethods()
156
            ->getMock();
157
    }
158
159
    /**
160
     * @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\Dependency\Service\CheckoutPageToShipmentServiceInterface
161
     */
162
    protected function createShipmentServiceMock(): CheckoutPageToShipmentServiceInterface
163
    {
164
        return $this->getMockBuilder(CheckoutPageToShipmentServiceBridge::class)
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockBui...nalMethods()->getMock() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return SprykerShop\Yves\Checkou...hipmentServiceInterface.
Loading history...
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...yingToOriginalMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/5307 ( Ignorable by Annotation )

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

164
        return /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(CheckoutPageToShipmentServiceBridge::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
165
            ->setConstructorArgs([$this->tester->getShipmentService()])
166
            ->enableProxyingToOriginalMethods()
167
            ->getMock();
168
    }
169
170
    /**
171
     * @return array<\SprykerShop\Yves\CheckoutPageExtension\Dependency\Plugin\CheckoutShipmentStepEnterPreCheckPluginInterface>
172
     */
173
    public function getCheckoutShipmentStepEnterPreCheckPlugins(): array
174
    {
175
        return [
176
            $this->getQuoteApprovalCheckerCheckoutShipmentStepEnterPreCheckPluginMock(),
177
        ];
178
    }
179
180
    /**
181
     * @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPageExtension\Dependency\Plugin\CheckoutShipmentStepEnterPreCheckPluginInterface
182
     */
183
    protected function getQuoteApprovalCheckerCheckoutShipmentStepEnterPreCheckPluginMock(): CheckoutShipmentStepEnterPreCheckPluginInterface
184
    {
185
        return $this->getMockBuilder(QuoteApprovalCheckerCheckoutShipmentStepEnterPreCheckPlugin::class)
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...yingToOriginalMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/5307 ( Ignorable by Annotation )

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

185
        return /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(QuoteApprovalCheckerCheckoutShipmentStepEnterPreCheckPlugin::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug Best Practice introduced by
The expression return $this->getMockBui...nalMethods()->getMock() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return SprykerShop\Yves\Checkou...PreCheckPluginInterface.
Loading history...
186
            ->enableProxyingToOriginalMethods()
187
            ->getMock();
188
    }
189
}
190