1414namespace Tests \Sylius \InvoicingPlugin \Unit \Converter ;
1515
1616use Doctrine \Common \Collections \ArrayCollection ;
17+ use PHPUnit \Framework \Attributes \Test ;
1718use PHPUnit \Framework \MockObject \MockObject ;
1819use PHPUnit \Framework \TestCase ;
1920use Sylius \Component \Core \Model \OrderInterface ;
@@ -51,13 +52,13 @@ protected function setUp(): void
5152 );
5253 }
5354
54- /** @test */
55+ #[Test]
5556 public function it_implements_line_items_converter_interface (): void
5657 {
5758 self ::assertInstanceOf (LineItemsConverterInterface::class, $ this ->converter );
5859 }
5960
60- /** @test */
61+ #[Test]
6162 public function it_extracts_line_items_from_order_item_units (): void
6263 {
6364 $ lineItem = $ this ->createMock (LineItemInterface::class);
@@ -104,7 +105,7 @@ public function it_extracts_line_items_from_order_item_units(): void
104105 self ::assertEquals ([$ lineItem ], $ result );
105106 }
106107
107- /** @test */
108+ #[Test]
108109 public function it_groups_the_same_line_items_during_extracting_order_item_units (): void
109110 {
110111 $ mjolnirLineItem = $ this ->createMock (LineItemInterface::class);
@@ -121,12 +122,24 @@ public function it_groups_the_same_line_items_during_extracting_order_item_units
121122 $ this ->lineItemFactory
122123 ->expects ($ this ->exactly (3 ))
123124 ->method ('createWithData ' )
124- ->withConsecutive (
125- ['Mjolnir ' , 1 , 5000 , 5000 , 5000 , 500 , 5500 , null , 'MJOLNIR ' , '10% ' ],
126- ['Mjolnir ' , 1 , 5000 , 5000 , 5000 , 500 , 5500 , null , 'MJOLNIR ' , '10% ' ],
127- ['Stormbreaker ' , 1 , 8000 , 8000 , 8000 , 1600 , 9600 , null , 'STORMBREAKER ' , '20% ' ],
128- )
129- ->willReturnOnConsecutiveCalls ($ mjolnirLineItem , $ mjolnirLineItem , $ stormbreakerLineItem );
125+ ->willReturnCallback (function (...$ args ) use ($ mjolnirLineItem , $ stormbreakerLineItem ) {
126+ static $ callCount = 0 ;
127+ ++$ callCount ;
128+
129+ if ($ callCount === 1 ) {
130+ $ this ->assertEquals (['Mjolnir ' , 1 , 5000 , 5000 , 5000 , 500 , 5500 , null , 'MJOLNIR ' , '10% ' ], $ args );
131+
132+ return $ mjolnirLineItem ;
133+ }
134+ if ($ callCount === 2 ) {
135+ $ this ->assertEquals (['Mjolnir ' , 1 , 5000 , 5000 , 5000 , 500 , 5500 , null , 'MJOLNIR ' , '10% ' ], $ args );
136+
137+ return $ mjolnirLineItem ;
138+ }
139+ $ this ->assertEquals (['Stormbreaker ' , 1 , 8000 , 8000 , 8000 , 1600 , 9600 , null , 'STORMBREAKER ' , '20% ' ], $ args );
140+
141+ return $ stormbreakerLineItem ;
142+ });
130143
131144 $ mjolnirLineItem
132145 ->expects ($ this ->exactly (2 ))
@@ -161,8 +174,24 @@ public function it_groups_the_same_line_items_during_extracting_order_item_units
161174 $ this ->unitNetPriceProvider
162175 ->expects ($ this ->exactly (3 ))
163176 ->method ('getUnitNetPrice ' )
164- ->withConsecutive ([$ firstOrderItemUnit ], [$ secondOrderItemUnit ], [$ thirdOrderItemUnit ])
165- ->willReturnOnConsecutiveCalls (5000 , 5000 , 8000 );
177+ ->willReturnCallback (function ($ unit ) use ($ firstOrderItemUnit , $ secondOrderItemUnit , $ thirdOrderItemUnit ) {
178+ static $ callCount = 0 ;
179+ ++$ callCount ;
180+
181+ if ($ callCount === 1 ) {
182+ $ this ->assertSame ($ firstOrderItemUnit , $ unit );
183+
184+ return 5000 ;
185+ }
186+ if ($ callCount === 2 ) {
187+ $ this ->assertSame ($ secondOrderItemUnit , $ unit );
188+
189+ return 5000 ;
190+ }
191+ $ this ->assertSame ($ thirdOrderItemUnit , $ unit );
192+
193+ return 8000 ;
194+ });
166195
167196 // Second order item unit setup
168197 $ secondOrderItemUnit ->expects (self ::once ())->method ('getTaxTotal ' )->willReturn (500 );
@@ -188,8 +217,24 @@ public function it_groups_the_same_line_items_during_extracting_order_item_units
188217 $ this ->taxRatePercentageProvider
189218 ->expects ($ this ->exactly (3 ))
190219 ->method ('provideFromAdjustable ' )
191- ->withConsecutive ([$ firstOrderItemUnit ], [$ secondOrderItemUnit ], [$ thirdOrderItemUnit ])
192- ->willReturnOnConsecutiveCalls ('10% ' , '10% ' , '20% ' );
220+ ->willReturnCallback (function ($ unit ) use ($ firstOrderItemUnit , $ secondOrderItemUnit , $ thirdOrderItemUnit ) {
221+ static $ callCount = 0 ;
222+ ++$ callCount ;
223+
224+ if ($ callCount === 1 ) {
225+ $ this ->assertSame ($ firstOrderItemUnit , $ unit );
226+
227+ return '10% ' ;
228+ }
229+ if ($ callCount === 2 ) {
230+ $ this ->assertSame ($ secondOrderItemUnit , $ unit );
231+
232+ return '10% ' ;
233+ }
234+ $ this ->assertSame ($ thirdOrderItemUnit , $ unit );
235+
236+ return '20% ' ;
237+ });
193238
194239 $ result = $ this ->converter ->convert ($ order );
195240
0 commit comments