10
10
use Magento \Framework \GraphQl \Config \Element \Field ;
11
11
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
12
12
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
13
- use Magento \GraphQl \Helper \Error \AggregateExceptionMessageFormatter ;
14
13
use Magento \GraphQl \Model \Query \Context ;
15
14
use Magento \GraphQl \Model \Query \ContextExtensionInterface ;
16
15
use Magento \Quote \Model \Quote ;
17
16
use Magento \QuoteGraphQl \Model \Cart \GetCartForCheckout ;
18
17
use Magento \QuoteGraphQl \Model \Cart \PlaceOrder as PlaceOrderModel ;
19
- use Magento \QuoteGraphQl \Model \ErrorMapper ;
18
+ use Magento \QuoteGraphQl \Model \OrderErrorProcessor ;
20
19
use Magento \QuoteGraphQl \Model \QuoteException ;
21
20
use Magento \QuoteGraphQl \Model \Resolver \PlaceOrder ;
22
21
use Magento \Sales \Api \OrderRepositoryInterface ;
@@ -41,14 +40,9 @@ class PlaceOrderTranslationTest extends TestCase
41
40
private $ placeOrderModelMock ;
42
41
43
42
/**
44
- * @var AggregateExceptionMessageFormatter |MockObject
43
+ * @var OrderErrorProcessor |MockObject
45
44
*/
46
- private $ errorMessageFormatterMock ;
47
-
48
- /**
49
- * @var ErrorMapper|MockObject
50
- */
51
- private $ errorMapperMock ;
45
+ private $ orderErrorProcessor ;
52
46
53
47
/**
54
48
* @var PlaceOrder
@@ -59,42 +53,27 @@ protected function setUp(): void
59
53
{
60
54
$ this ->getCartForCheckoutMock = $ this ->createMock (GetCartForCheckout::class);
61
55
$ 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);
64
57
65
58
$ this ->placeOrderResolver = new PlaceOrder (
66
59
$ this ->getCartForCheckoutMock ,
67
60
$ this ->placeOrderModelMock ,
68
61
$ this ->createMock (OrderRepositoryInterface::class),
69
62
$ this ->createMock (OrderFormatter::class),
70
- $ this ->errorMessageFormatterMock ,
71
- $ this ->errorMapperMock
63
+ $ this ->orderErrorProcessor
72
64
);
73
65
}
74
66
75
67
/**
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
77
69
*/
78
- public function testGetRawMessageIsCalledForErrorMapping (): void
70
+ public function testExceptionProcessing (): void
79
71
{
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);
92
73
$ this ->getCartForCheckoutMock ->method ('execute ' )->willReturn ($ this ->createMock (Quote::class));
93
74
$ this ->placeOrderModelMock ->method ('execute ' )->willThrowException ($ exception );
94
- $ this ->errorMessageFormatterMock ->method ('getFormatted ' )->willReturn ($ exception );
95
75
96
76
$ contextMock = $ this ->createMock (Context::class);
97
-
98
77
$ extensionAttributesMock = $ this ->getMockBuilder (ContextExtensionInterface::class)
99
78
->disableOriginalConstructor ()
100
79
->addMethods (
@@ -106,11 +85,18 @@ public function testGetRawMessageIsCalledForErrorMapping(): void
106
85
$ extensionAttributesMock ->method ('getStore ' )->willReturn ($ this ->createMock (StoreInterface::class));
107
86
$ contextMock ->method ('getExtensionAttributes ' )->willReturn ($ extensionAttributesMock );
108
87
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
+
109
95
$ this ->expectException (QuoteException::class);
110
96
$ this ->placeOrderResolver ->resolve (
111
97
$ this ->createMock (Field::class),
112
98
$ contextMock ,
113
- $ this -> createMock (ResolveInfo::class) ,
99
+ $ info ,
114
100
null ,
115
101
['input ' => ['cart_id ' => 'masked_cart_id ' ]]
116
102
);
0 commit comments