2020use Magento \Framework \App \RequestInterface ;
2121use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
2222use Magento \Quote \Api \CartRepositoryInterface ;
23- use Magento \Quote \Api \CartManagementInterface ;
2423use Magento \Quote \Model \Quote ;
25- use Magento \Quote \Model \Quote \Payment ;
26- use Magento \Payment \Model \MethodInterface ;
2724use Magento \Quote \Model \Quote \Address ;
2825use Magento \Quote \Model \Quote \Item ;
29- use Magento \Catalog \Model \Product ;
30- use Magento \Catalog \Model \Product \Type \AbstractType ;
3126use Magento \Quote \Model \Quote \Item \Updater ;
3227use Magento \Quote \Model \QuoteFactory ;
3328use Magento \Sales \Model \AdminOrder \Create ;
4439 */
4540class CreateTest extends TestCase
4641{
47- private const CUSTOMER_ID = 1 ;
42+ const CUSTOMER_ID = 1 ;
4843
4944 /**
5045 * @var Create
@@ -56,11 +51,6 @@ class CreateTest extends TestCase
5651 */
5752 private $ quoteRepository ;
5853
59- /**
60- * @var CartManagementInterface|MockObject
61- */
62- private $ quoteManagement ;
63-
6454 /**
6555 * @var QuoteFactory|MockObject
6656 */
@@ -114,10 +104,6 @@ protected function setUp(): void
114104 $ this ->formFactory = $ this ->createPartialMock (FormFactory::class, ['create ' ]);
115105 $ this ->quoteFactory = $ this ->createPartialMock (QuoteFactory::class, ['create ' ]);
116106 $ this ->customerFactory = $ this ->createPartialMock (CustomerInterfaceFactory::class, ['create ' ]);
117- $ this ->quoteManagement = $ this ->getMockBuilder (CartManagementInterface::class)
118- ->disableOriginalConstructor ()
119- ->setMethods (['submit ' ])
120- ->getMockForAbstractClass ();
121107
122108 $ this ->itemUpdater = $ this ->createMock (Updater::class);
123109
@@ -131,7 +117,6 @@ protected function setUp(): void
131117 ->setMethods (
132118 [
133119 'getQuote ' ,
134- 'getOrder ' ,
135120 'getStoreId ' ,
136121 'getCustomerId ' ,
137122 'setData ' ,
@@ -149,8 +134,6 @@ protected function setUp(): void
149134 $ storeMock = $ this ->getMockBuilder (StoreInterface::class)
150135 ->setMethods (['getId ' ])
151136 ->getMockForAbstractClass ();
152- $ storeMock ->method ('getId ' )
153- ->willReturn (1 );
154137 $ this ->sessionQuote ->method ('getStore ' )
155138 ->willReturn ($ storeMock );
156139
@@ -178,15 +161,6 @@ protected function setUp(): void
178161 'getShippingAddress ' ,
179162 'getBillingAddress ' ,
180163 'getCouponCode ' ,
181- 'getCustomerFirstname ' ,
182- 'getCustomerLastname ' ,
183- 'getCustomerMiddlename ' ,
184- 'getIncrementId ' ,
185- 'getOriginalIncrementId ' ,
186- 'getEditIncrement ' ,
187- 'setRelationChildId ' ,
188- 'setRelationChildRealId ' ,
189- 'save ' ,
190164 ]
191165 )
192166 ->getMock ();
@@ -204,7 +178,6 @@ protected function setUp(): void
204178 'dataObjectHelper ' => $ this ->dataObjectHelper ,
205179 'quoteRepository ' => $ this ->quoteRepository ,
206180 'quoteFactory ' => $ this ->quoteFactory ,
207- 'quoteManagement ' => $ this ->quoteManagement ,
208181 ]
209182 );
210183 }
@@ -488,144 +461,4 @@ public function testInitFromOrder()
488461
489462 $ this ->adminOrderCreate ->initFromOrder ($ this ->orderMock );
490463 }
491-
492- /**
493- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
494- */
495- public function testCreateOrder ()
496- {
497- $ method = $ this ->getMockBuilder (MethodInterface::class)
498- ->disableOriginalConstructor ()
499- ->setMethods (
500- [
501- 'isAvailable ' ,
502- 'validate ' ,
503- ]
504- )
505- ->getMockForAbstractClass ();
506- $ method ->method ('isAvailable ' )
507- ->willReturn (true );
508- $ method ->method ('validate ' )
509- ->willReturn (true );
510- $ payment = $ this ->getMockBuilder (Payment::class)
511- ->disableOriginalConstructor ()
512- ->setMethods (
513- [
514- 'getMethod ' ,
515- 'getMethodInstance ' ,
516- ]
517- )
518- ->getMock ();
519- $ payment ->method ('getMethod ' )
520- ->willReturn ('checkmo ' );
521- $ payment ->method ('getMethodInstance ' )
522- ->willReturn ($ method );
523-
524- $ type = $ this ->getMockBuilder (AbstractType::class)
525- ->disableOriginalConstructor ()
526- ->setMethods (
527- [
528- 'getOrderOptions ' ,
529- ]
530- )
531- ->getMockForAbstractClass ();
532- $ type ->method ('getOrderOptions ' )
533- ->willReturn (false );
534-
535- $ product = $ this ->getMockBuilder (Product::class)
536- ->disableOriginalConstructor ()
537- ->setMethods (
538- [
539- 'getTypeInstance ' ,
540- ]
541- )
542- ->getMockForAbstractClass ();
543- $ product ->method ('getTypeInstance ' )
544- ->willReturn ($ type );
545-
546- $ item = $ this ->getMockBuilder (Item::class)
547- ->disableOriginalConstructor ()
548- ->setMethods (
549- [
550- 'getHasError ' ,
551- 'getProduct ' ,
552- 'getOptionByCode ' ,
553- ]
554- )
555- ->getMockForAbstractClass ();
556- $ item ->method ('getHasError ' )
557- ->willReturn (false );
558- $ item ->method ('getProduct ' )
559- ->willReturn ($ product );
560- $ item ->method ('getOptionByCode ' )
561- ->willReturn (false );
562- $ items = [
563- $ item
564- ];
565-
566- $ quote = $ this ->getMockBuilder (Quote::class)
567- ->disableOriginalConstructor ()
568- ->setMethods (
569- [
570- 'getCustomerIsGuest ' ,
571- 'getAllItems ' ,
572- 'isVirtual ' ,
573- 'getPayment ' ,
574- 'getItemById ' ,
575- ]
576- )
577- ->getMock ();
578- $ quote ->method ('getCustomerIsGuest ' )
579- ->willReturn (true );
580- $ quote ->method ('getAllItems ' )
581- ->willReturn ($ items );
582- $ quote ->method ('isVirtual ' )
583- ->willReturn (true );
584- $ quote ->method ('getPayment ' )
585- ->willReturn ($ payment );
586- $ quote ->method ('getItemById ' )
587- ->willReturn ($ item );
588-
589- $ this ->sessionQuote
590- ->method ('getQuote ' )
591- ->willReturn ($ quote );
592- $ this ->orderMock ->method ('getId ' )
593- ->willReturn (1 );
594- $ this ->orderMock ->method ('getCustomerFirstname ' )
595- ->willReturn ('firstname ' );
596- $ this ->orderMock ->method ('getCustomerLastname ' )
597- ->willReturn ('lastname ' );
598- $ this ->orderMock ->method ('getCustomerMiddlename ' )
599- ->willReturn ('middlename ' );
600- $ this ->orderMock ->method ('getIncrementId ' )
601- ->willReturn ('100000001 ' );
602- $ this ->orderMock ->method ('getEditIncrement ' )
603- ->willReturn (0 );
604- $ this ->sessionQuote
605- ->method ('getOrder ' )
606- ->willReturn ($ this ->orderMock );
607-
608- $ guestOrder = $ this ->getMockBuilder (Order::class)
609- ->disableOriginalConstructor ()
610- ->setMethods (
611- [
612- 'getId ' ,
613- 'getIncrementId ' ,
614- 'getCustomerIsGuest ' ,
615- 'save ' ,
616- ]
617- )
618- ->getMock ();
619- $ guestOrder ->method ('getId ' )
620- ->willReturn (2 );
621- $ guestOrder ->method ('getIncrementId ' )
622- ->willReturn ('100000001-1 ' );
623- $ guestOrder ->method ('getCustomerIsGuest ' )
624- ->willReturn (true );
625- $ this ->quoteManagement ->method ('submit ' )
626- ->willReturn ($ guestOrder );
627-
628- $ object = $ this ->adminOrderCreate ->createOrder ();
629- self ::assertEquals ($ this ->orderMock ->getCustomerFirstname (), $ object ->getCustomerFirstname ());
630- }
631464}
0 commit comments