99
1010use Magento \Framework \GraphQl \Query \Resolver \ContextInterface ;
1111use Magento \Framework \Api \ExtensionAttributesInterface ;
12+ use Magento \Tax \Api \Data \OrderTaxDetailsAppliedTaxInterface ;
13+ use Magento \Tax \Api \OrderTaxManagementInterface ;
1214use PHPUnit \Framework \MockObject \MockObject ;
1315use PHPUnit \Framework \TestCase ;
1416use Magento \SalesGraphQl \Model \Resolver \OrderTotal ;
1517use Magento \Sales \Api \Data \OrderInterface ;
1618use Magento \Framework \GraphQl \Config \Element \Field ;
1719use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
1820use Magento \Framework \Exception \LocalizedException ;
21+ use Magento \Tax \Api \Data \OrderTaxDetailsInterface ;
1922
2023class OrderTotalTest extends TestCase
2124{
@@ -49,6 +52,21 @@ class OrderTotalTest extends TestCase
4952 */
5053 private $ extensionAttributesMock ;
5154
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+
5270 protected function setUp (): void
5371 {
5472 $ this ->contextMock = $ this ->createMock (ContextInterface::class);
@@ -65,7 +83,11 @@ protected function setUp(): void
6583 $ this ->orderMock ->method ('getShippingInclTax ' )->willReturn (7.00 );
6684 $ this ->orderMock ->method ('getDiscountAmount ' )->willReturn (7.00 );
6785 $ 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 );
6991 }
7092
7193 public function testResolve (): void
@@ -74,12 +96,21 @@ public function testResolve(): void
7496 $ resolveInfoMock = $ this ->createMock (ResolveInfo::class);
7597 $ value = ['model ' => $ this ->orderMock ];
7698 $ 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+ );
77108 $ this ->extensionAttributesMock = $ this ->getMockBuilder (ExtensionAttributesInterface::class)
78109 ->addMethods (['getAppliedTaxes ' , 'getItemAppliedTaxes ' ])
79110 ->disableOriginalConstructor ()
80111 ->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 ([]);
83114 $ this ->orderMock ->method ('getExtensionAttributes ' )->willReturn ($ this ->extensionAttributesMock );
84115 $ result = $ this ->orderTotal ->resolve ($ fieldMock , $ this ->contextMock , $ resolveInfoMock , $ value , $ args );
85116 $ this ->assertArrayHasKey ('base_grand_total ' , $ result );
0 commit comments