22
22
use Sylius \RefundPlugin \Model \OrderItemUnitRefund ;
23
23
use Sylius \RefundPlugin \Model \ShipmentRefund ;
24
24
use Sylius \RefundPlugin \Validator \RefundAmountValidatorInterface ;
25
- use Sylius \RefundPlugin \Validator \RefundUnitsBelongToOrderValidatorInterface ;
25
+ use Sylius \RefundPlugin \Validator \UnitRefundsBelongingToOrderValidatorInterface ;
26
26
27
27
final class RefundUnitsCommandValidatorSpec extends ObjectBehavior
28
28
{
29
29
function let (
30
30
OrderRefundingAvailabilityCheckerInterface $ orderRefundingAvailabilityChecker ,
31
31
RefundAmountValidatorInterface $ refundAmountValidator ,
32
- RefundUnitsBelongToOrderValidatorInterface $ refundUnitsBelongToOrderValidator ,
32
+ UnitRefundsBelongingToOrderValidatorInterface $ firstUnitRefundsBelongingToOrderValidator ,
33
+ UnitRefundsBelongingToOrderValidatorInterface $ secondUnitRefundsBelongingToOrderValidator ,
33
34
): void {
34
35
$ this ->beConstructedWith (
35
36
$ orderRefundingAvailabilityChecker ,
36
37
$ refundAmountValidator ,
37
- $ refundUnitsBelongToOrderValidator ,
38
+ [
39
+ $ firstUnitRefundsBelongingToOrderValidator ,
40
+ $ secondUnitRefundsBelongingToOrderValidator ,
41
+ ],
38
42
);
39
43
}
40
44
@@ -54,7 +58,8 @@ function it_throws_exception_when_order_is_not_available_for_refund(
54
58
function it_throws_exception_when_order_item_units_amount_is_not_valid (
55
59
OrderRefundingAvailabilityCheckerInterface $ orderRefundingAvailabilityChecker ,
56
60
RefundAmountValidatorInterface $ refundAmountValidator ,
57
- RefundUnitsBelongToOrderValidatorInterface $ refundUnitsBelongToOrderValidator ,
61
+ UnitRefundsBelongingToOrderValidatorInterface $ firstUnitRefundsBelongingToOrderValidator ,
62
+ UnitRefundsBelongingToOrderValidatorInterface $ secondUnitRefundsBelongingToOrderValidator ,
58
63
): void {
59
64
$ orderRefundingAvailabilityChecker ->__invoke ('000001 ' )->willReturn (true );
60
65
@@ -67,7 +72,12 @@ function it_throws_exception_when_order_item_units_amount_is_not_valid(
67
72
->willThrow (InvalidRefundAmount::class)
68
73
;
69
74
70
- $ refundUnitsBelongToOrderValidator
75
+ $ firstUnitRefundsBelongingToOrderValidator
76
+ ->validateUnits ([$ orderItemUnitRefund ], '000001 ' )
77
+ ->shouldBeCalled ()
78
+ ;
79
+
80
+ $ secondUnitRefundsBelongingToOrderValidator
71
81
->validateUnits ([$ orderItemUnitRefund ], '000001 ' )
72
82
->shouldBeCalled ()
73
83
;
@@ -78,7 +88,8 @@ function it_throws_exception_when_order_item_units_amount_is_not_valid(
78
88
function it_throws_exception_when_order_item_units_do_not_belong_to_an_order (
79
89
OrderRefundingAvailabilityCheckerInterface $ orderRefundingAvailabilityChecker ,
80
90
RefundAmountValidatorInterface $ refundAmountValidator ,
81
- RefundUnitsBelongToOrderValidatorInterface $ refundUnitsBelongToOrderValidator ,
91
+ UnitRefundsBelongingToOrderValidatorInterface $ firstUnitRefundsBelongingToOrderValidator ,
92
+ UnitRefundsBelongingToOrderValidatorInterface $ secondUnitRefundsBelongingToOrderValidator ,
82
93
): void {
83
94
$ orderRefundingAvailabilityChecker ->__invoke ('000001 ' )->willReturn (true );
84
95
@@ -91,18 +102,24 @@ function it_throws_exception_when_order_item_units_do_not_belong_to_an_order(
91
102
->shouldNotBeCalled ()
92
103
;
93
104
94
- $ refundUnitsBelongToOrderValidator
105
+ $ firstUnitRefundsBelongingToOrderValidator
95
106
->validateUnits ([$ orderItemUnitRefund ], '000001 ' )
96
107
->willThrow (RefundUnitsNotBelongToOrder::class)
97
108
;
98
109
110
+ $ secondUnitRefundsBelongingToOrderValidator
111
+ ->validateUnits ([$ refundUnits ], '000001 ' )
112
+ ->shouldNotBeCalled ()
113
+ ;
114
+
99
115
$ this ->shouldThrow (RefundUnitsNotBelongToOrder::class)->during ('validate ' , [$ refundUnits ]);
100
116
}
101
117
102
118
function it_throws_exception_when_shipment_amount_is_not_valid (
103
119
OrderRefundingAvailabilityCheckerInterface $ orderRefundingAvailabilityChecker ,
104
120
RefundAmountValidatorInterface $ refundAmountValidator ,
105
- RefundUnitsBelongToOrderValidatorInterface $ refundUnitsBelongToOrderValidator ,
121
+ UnitRefundsBelongingToOrderValidatorInterface $ firstUnitRefundsBelongingToOrderValidator ,
122
+ UnitRefundsBelongingToOrderValidatorInterface $ secondUnitRefundsBelongingToOrderValidator ,
106
123
): void {
107
124
$ orderRefundingAvailabilityChecker ->__invoke ('000001 ' )->willReturn (true );
108
125
@@ -115,7 +132,12 @@ function it_throws_exception_when_shipment_amount_is_not_valid(
115
132
->willThrow (InvalidRefundAmount::class)
116
133
;
117
134
118
- $ refundUnitsBelongToOrderValidator
135
+ $ firstUnitRefundsBelongingToOrderValidator
136
+ ->validateUnits ([$ shipmentRefund ], '000001 ' )
137
+ ->shouldBeCalled ()
138
+ ;
139
+
140
+ $ secondUnitRefundsBelongingToOrderValidator
119
141
->validateUnits ([$ shipmentRefund ], '000001 ' )
120
142
->shouldBeCalled ()
121
143
;
@@ -126,7 +148,8 @@ function it_throws_exception_when_shipment_amount_is_not_valid(
126
148
function it_throws_exception_when_shipment_does_not_belong_to_an_order (
127
149
OrderRefundingAvailabilityCheckerInterface $ orderRefundingAvailabilityChecker ,
128
150
RefundAmountValidatorInterface $ refundAmountValidator ,
129
- RefundUnitsBelongToOrderValidatorInterface $ refundUnitsBelongToOrderValidator ,
151
+ UnitRefundsBelongingToOrderValidatorInterface $ firstUnitRefundsBelongingToOrderValidator ,
152
+ UnitRefundsBelongingToOrderValidatorInterface $ secondUnitRefundsBelongingToOrderValidator ,
130
153
): void {
131
154
$ orderRefundingAvailabilityChecker ->__invoke ('000001 ' )->willReturn (true );
132
155
@@ -139,7 +162,12 @@ function it_throws_exception_when_shipment_does_not_belong_to_an_order(
139
162
->shouldNotBeCalled ()
140
163
;
141
164
142
- $ refundUnitsBelongToOrderValidator
165
+ $ firstUnitRefundsBelongingToOrderValidator
166
+ ->validateUnits ([$ shipmentRefund ], '000001 ' )
167
+ ->shouldBeCalled ()
168
+ ;
169
+
170
+ $ secondUnitRefundsBelongingToOrderValidator
143
171
->validateUnits ([$ shipmentRefund ], '000001 ' )
144
172
->willThrow (RefundUnitsNotBelongToOrder::class)
145
173
;
0 commit comments