1010use Magento \Framework \GraphQl \Config \Element \Field ;
1111use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
1212use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
13- use Magento \GraphQl \Helper \Error \AggregateExceptionMessageFormatter ;
1413use Magento \GraphQl \Model \Query \Context ;
1514use Magento \GraphQl \Model \Query \ContextExtensionInterface ;
1615use Magento \Quote \Model \Quote ;
1716use Magento \QuoteGraphQl \Model \Cart \GetCartForCheckout ;
1817use Magento \QuoteGraphQl \Model \Cart \PlaceOrder as PlaceOrderModel ;
19- use Magento \QuoteGraphQl \Model \ErrorMapper ;
18+ use Magento \QuoteGraphQl \Model \OrderErrorProcessor ;
2019use Magento \QuoteGraphQl \Model \QuoteException ;
2120use Magento \QuoteGraphQl \Model \Resolver \PlaceOrder ;
2221use Magento \Sales \Api \OrderRepositoryInterface ;
2827/**
2928 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3029 */
31- class PlaceOrderTranslationTest extends TestCase
30+ class PlaceOrderExceptionProcessingTest extends TestCase
3231{
3332 /**
3433 * @var GetCartForCheckout|MockObject
@@ -41,14 +40,9 @@ class PlaceOrderTranslationTest extends TestCase
4140 private $ placeOrderModelMock ;
4241
4342 /**
44- * @var AggregateExceptionMessageFormatter |MockObject
43+ * @var OrderErrorProcessor |MockObject
4544 */
46- private $ errorMessageFormatterMock ;
47-
48- /**
49- * @var ErrorMapper|MockObject
50- */
51- private $ errorMapperMock ;
45+ private $ orderErrorProcessor ;
5246
5347 /**
5448 * @var PlaceOrder
@@ -59,42 +53,27 @@ protected function setUp(): void
5953 {
6054 $ this ->getCartForCheckoutMock = $ this ->createMock (GetCartForCheckout::class);
6155 $ this ->placeOrderModelMock = $ this ->createMock (PlaceOrderModel::class);
62- $ this ->errorMessageFormatterMock = $ this ->createMock (AggregateExceptionMessageFormatter::class);
63- $ this ->errorMapperMock = $ this ->createMock (ErrorMapper::class);
56+ $ this ->orderErrorProcessor = $ this ->createMock (OrderErrorProcessor::class);
6457
6558 $ this ->placeOrderResolver = new PlaceOrder (
6659 $ this ->getCartForCheckoutMock ,
6760 $ this ->placeOrderModelMock ,
6861 $ this ->createMock (OrderRepositoryInterface::class),
6962 $ this ->createMock (OrderFormatter::class),
70- $ this ->errorMessageFormatterMock ,
71- $ this ->errorMapperMock
63+ $ this ->orderErrorProcessor
7264 );
7365 }
7466
7567 /**
76- * Test that getRawMessage() is called on GraphQlInputException to map the error message properly.
68+ * Test that OrderErrorProcessor::execute method is being triggered on thrown LocalizedException
7769 */
78- public function testGetRawMessageIsCalledForErrorMapping (): void
70+ public function testExceptionProcessing (): void
7971 {
80- $ exception = $ this ->getMockBuilder (GraphQlInputException::class)
81- ->disableOriginalConstructor ()
82- ->onlyMethods (['getRawMessage ' ])
83- ->getMock ();
84- $ exception ->method ('getRawMessage ' )->willReturn ('Raw error message ' );
85- $ exception ->expects ($ this ->once ())->method ('getRawMessage ' );
86-
87- $ this ->errorMapperMock ->expects ($ this ->once ())
88- ->method ('getErrorMessageId ' )
89- ->with ('Raw error message ' )
90- ->willReturn (1 );
91-
72+ $ exception = $ this ->createMock (GraphQlInputException::class);
9273 $ this ->getCartForCheckoutMock ->method ('execute ' )->willReturn ($ this ->createMock (Quote::class));
9374 $ this ->placeOrderModelMock ->method ('execute ' )->willThrowException ($ exception );
94- $ this ->errorMessageFormatterMock ->method ('getFormatted ' )->willReturn ($ exception );
9575
9676 $ contextMock = $ this ->createMock (Context::class);
97-
9877 $ extensionAttributesMock = $ this ->getMockBuilder (ContextExtensionInterface::class)
9978 ->disableOriginalConstructor ()
10079 ->addMethods (
@@ -106,11 +85,18 @@ public function testGetRawMessageIsCalledForErrorMapping(): void
10685 $ extensionAttributesMock ->method ('getStore ' )->willReturn ($ this ->createMock (StoreInterface::class));
10786 $ contextMock ->method ('getExtensionAttributes ' )->willReturn ($ extensionAttributesMock );
10887
88+ $ field = $ this ->createMock (Field::class);
89+ $ info = $ this ->createMock (ResolveInfo::class);
90+ $ this ->orderErrorProcessor ->expects ($ this ->once ())
91+ ->method ('execute ' )
92+ ->with ($ exception , $ field , $ contextMock )
93+ ->willThrowException ($ this ->createMock (QuoteException::class));
94+
10995 $ this ->expectException (QuoteException::class);
11096 $ this ->placeOrderResolver ->resolve (
11197 $ this ->createMock (Field::class),
11298 $ contextMock ,
113- $ this -> createMock (ResolveInfo::class) ,
99+ $ info ,
114100 null ,
115101 ['input ' => ['cart_id ' => 'masked_cart_id ' ]]
116102 );
0 commit comments