9
9
10
10
use Magento \Framework \GraphQl \Query \Resolver \ContextInterface ;
11
11
use Magento \Framework \Api \ExtensionAttributesInterface ;
12
+ use Magento \Tax \Api \Data \OrderTaxDetailsAppliedTaxInterface ;
13
+ use Magento \Tax \Api \OrderTaxManagementInterface ;
12
14
use PHPUnit \Framework \MockObject \MockObject ;
13
15
use PHPUnit \Framework \TestCase ;
14
16
use Magento \SalesGraphQl \Model \Resolver \OrderTotal ;
15
17
use Magento \Sales \Api \Data \OrderInterface ;
16
18
use Magento \Framework \GraphQl \Config \Element \Field ;
17
19
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
18
20
use Magento \Framework \Exception \LocalizedException ;
21
+ use Magento \Tax \Api \Data \OrderTaxDetailsInterface ;
19
22
20
23
class OrderTotalTest extends TestCase
21
24
{
@@ -49,6 +52,21 @@ class OrderTotalTest extends TestCase
49
52
*/
50
53
private $ extensionAttributesMock ;
51
54
55
+ /**
56
+ * @var OrderTaxManagementInterface|MockObject
57
+ */
58
+ private $ orderTaxManagementMock ;
59
+
60
+ /**
61
+ * @var OrderTaxDetailsInterface
62
+ */
63
+ private $ orderTaxDetailsMock ;
64
+
65
+ /**
66
+ * @var OrderTaxDetailsAppliedTaxInterface
67
+ */
68
+ private $ orderTaxDetailsAppliedTaxMock ;
69
+
52
70
protected function setUp (): void
53
71
{
54
72
$ this ->contextMock = $ this ->createMock (ContextInterface::class);
@@ -65,7 +83,11 @@ protected function setUp(): void
65
83
$ this ->orderMock ->method ('getShippingInclTax ' )->willReturn (7.00 );
66
84
$ this ->orderMock ->method ('getDiscountAmount ' )->willReturn (7.00 );
67
85
$ this ->orderMock ->method ('getDiscountDescription ' )->willReturn ('TEST123 ' );
68
- $ this ->orderTotal = new OrderTotal ();
86
+ $ this ->orderMock ->method ('getEntityId ' )->willReturn (123 );
87
+ $ this ->orderTaxManagementMock = $ this ->createMock (OrderTaxManagementInterface::class);
88
+ $ this ->orderTaxDetailsMock = $ this ->createMock (OrderTaxDetailsInterface::class);
89
+ $ this ->orderTaxDetailsAppliedTaxMock = $ this ->createMock (OrderTaxDetailsAppliedTaxInterface::class);
90
+ $ this ->orderTotal = new OrderTotal ($ this ->orderTaxManagementMock );
69
91
}
70
92
71
93
public function testResolve (): void
@@ -74,12 +96,21 @@ public function testResolve(): void
74
96
$ resolveInfoMock = $ this ->createMock (ResolveInfo::class);
75
97
$ value = ['model ' => $ this ->orderMock ];
76
98
$ args = [];
99
+ $ this ->orderTaxDetailsAppliedTaxMock ->expects ($ this ->atMost (1 ))->method ('setTitle ' )->willReturn ('TestTitle ' );
100
+ $ this ->orderTaxDetailsAppliedTaxMock ->expects ($ this ->atMost (1 ))->method ('setAmount ' )->willReturn (100.00 );
101
+ $ this ->orderTaxDetailsAppliedTaxMock ->expects ($ this ->atMost (1 ))->method ('setPercent ' )->willReturn (10 );
102
+ $ this ->orderTaxDetailsMock ->expects ($ this ->any ())->method ('getAppliedTaxes ' )->willReturn ([
103
+ $ this ->orderTaxDetailsAppliedTaxMock
104
+ ]);
105
+ $ this ->orderTaxManagementMock ->expects ($ this ->any ())->method ('getOrderTaxDetails ' )->willReturn (
106
+ $ this ->orderTaxDetailsMock
107
+ );
77
108
$ this ->extensionAttributesMock = $ this ->getMockBuilder (ExtensionAttributesInterface::class)
78
109
->addMethods (['getAppliedTaxes ' , 'getItemAppliedTaxes ' ])
79
110
->disableOriginalConstructor ()
80
111
->getMock ();
81
- $ this ->extensionAttributesMock ->expects ($ this ->once ( ))->method ('getAppliedTaxes ' )->willReturn ([]);
82
- $ this ->extensionAttributesMock ->expects ($ this ->once ( ))->method ('getItemAppliedTaxes ' )->willReturn ([]);
112
+ $ this ->extensionAttributesMock ->expects ($ this ->atMost ( 1 ))->method ('getAppliedTaxes ' )->willReturn ([]);
113
+ $ this ->extensionAttributesMock ->expects ($ this ->atMost ( 1 ))->method ('getItemAppliedTaxes ' )->willReturn ([]);
83
114
$ this ->orderMock ->method ('getExtensionAttributes ' )->willReturn ($ this ->extensionAttributesMock );
84
115
$ result = $ this ->orderTotal ->resolve ($ fieldMock , $ this ->contextMock , $ resolveInfoMock , $ value , $ args );
85
116
$ this ->assertArrayHasKey ('base_grand_total ' , $ result );
0 commit comments