77
88namespace Magento \AuthorizenetGraphQl \Model \Resolver \Customer ;
99
10- use Magento \Framework \App \Request \Http ;
1110use Magento \Framework \Serialize \SerializerInterface ;
12- use Magento \GraphQl \Controller \GraphQl ;
1311use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
12+ use Magento \GraphQl \Service \GraphQlRequest ;
1413use Magento \Integration \Api \CustomerTokenServiceInterface ;
15- use Magento \Framework \Webapi \Request ;
1614use Magento \TestFramework \Helper \Bootstrap ;
1715use Magento \Framework \HTTP \ZendClient ;
1816use Magento \Framework \HTTP \ZendClientFactory ;
1917use Magento \TestFramework \ObjectManager ;
2018use PHPUnit \Framework \MockObject \Builder \InvocationMocker ;
21- use Magento \Payment \Gateway \Data \PaymentDataObjectFactory ;
2219use PHPUnit \Framework \MockObject \MockObject ;
23- use Magento \Quote \Model \Quote \PaymentFactory ;
2420use PHPUnit \Framework \TestCase ;
2521use Zend_Http_Response ;
2622
2925 *
3026 * @magentoAppArea graphql
3127 * @magentoDbIsolation disabled
32- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3328 */
3429class PlaceOrderWithAuthorizeNetTest extends TestCase
3530{
36- const CONTENT_TYPE = 'application/json ' ;
37-
38- /** @var ObjectManager */
31+ /** @var ObjectManager */
3932 private $ objectManager ;
4033
41- /** @var GetMaskedQuoteIdByReservedOrderId */
34+ /** @var GetMaskedQuoteIdByReservedOrderId */
4235 private $ getMaskedQuoteIdByReservedOrderId ;
4336
4437 /** @var SerializerInterface */
4538 private $ jsonSerializer ;
4639
47- /** @var Http */
48- private $ request ;
40+ /** @var GraphQlRequest */
41+ private $ graphQlRequest ;
4942
5043 /** @var ZendClient|MockObject|InvocationMocker */
5144 private $ clientMock ;
5245
53- /** @var CustomerTokenServiceInterface */
46+ /** @var CustomerTokenServiceInterface */
5447 private $ customerTokenService ;
5548
5649 /** @var Zend_Http_Response */
5750 protected $ responseMock ;
5851
59- /** @var PaymentFactory */
60- private $ paymentFactory ;
61-
6252 protected function setUp () : void
6353 {
6454 $ this ->objectManager = Bootstrap::getObjectManager ();
6555 $ this ->jsonSerializer = $ this ->objectManager ->get (SerializerInterface::class);
66- $ this ->request = $ this ->objectManager ->get (Http ::class);
56+ $ this ->graphQlRequest = $ this ->objectManager ->create (GraphQlRequest ::class);
6757 $ this ->getMaskedQuoteIdByReservedOrderId = $ this ->objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
6858 $ this ->customerTokenService = $ this ->objectManager ->get (CustomerTokenServiceInterface::class);
6959 $ this ->clientMock = $ this ->createMock (ZendClient::class);
@@ -75,8 +65,6 @@ protected function setUp() : void
7565 $ clientFactoryMock = $ this ->createMock (ZendClientFactory::class);
7666 $ clientFactoryMock ->method ('create ' )
7767 ->willReturn ($ this ->clientMock );
78- /** @var PaymentDataObjectFactory $paymentFactory */
79- $ this ->paymentFactory = $ this ->objectManager ->get (PaymentDataObjectFactory::class);
8068 $ this ->objectManager ->addSharedInstance ($ clientFactoryMock , ZendClientFactory::class);
8169 }
8270
@@ -126,23 +114,12 @@ public function testDispatchToPlaceOrderWithRegisteredCustomer(): void
126114 }
127115}
128116QUERY ;
129- $ postData = [
130- 'query ' => $ query ,
131- 'variables ' => null ,
132- 'operationName ' => null
133- ];
134- $ this ->request ->setPathInfo ('/graphql ' );
135- $ this ->request ->setMethod ('POST ' );
136- $ this ->request ->setContent ($ this ->jsonSerializer ->serialize ($ postData ));
137- $ customerToken = $ this ->customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
138- $ bearerCustomerToken = 'Bearer ' . $ customerToken ;
139- $ webApiRequest = $ this ->objectManager ->get (Request::class);
140- $ webApiRequest ->getHeaders ()->addHeaderLine ('Content-Type ' , 'application/json ' )
141- ->addHeaderLine ('Accept ' , 'application/json ' )
142- ->addHeaderLine ('Authorization ' , $ bearerCustomerToken );
143- $ this ->request ->setHeaders ($ webApiRequest ->getHeaders ());
144- $ graphql = $ this ->objectManager ->get (\Magento \GraphQl \Controller \GraphQl::class);
145117
118+ $ customerToken = $ this ->customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
119+ $ requestHeaders = [
120+ 'Accept ' => 'application/json ' ,
121+ 'Authorization ' => 'Bearer ' . $ customerToken
122+ ];
146123 // phpcs:ignore Magento2.Security.IncludeFile
147124 $ expectedRequest = include __DIR__ . '/../../../_files/request_authorize_customer.php ' ;
148125 // phpcs:ignore Magento2.Security.IncludeFile
@@ -153,7 +130,7 @@ public function testDispatchToPlaceOrderWithRegisteredCustomer(): void
153130
154131 $ this ->responseMock ->method ('getBody ' )->willReturn (json_encode ($ authorizeResponse ));
155132
156- $ response = $ graphql -> dispatch ( $ this -> request );
133+ $ response = $ this -> graphQlRequest -> send ( $ query , [], '' , $ requestHeaders );
157134 $ responseData = $ this ->jsonSerializer ->unserialize ($ response ->getContent ());
158135
159136 $ this ->assertArrayNotHasKey ('errors ' , $ responseData , 'Response has errors ' );
@@ -178,6 +155,5 @@ public function testDispatchToPlaceOrderWithRegisteredCustomer(): void
178155 protected function tearDown ()
179156 {
180157 $ this ->objectManager ->removeSharedInstance (ZendClientFactory::class);
181- parent ::tearDown ();
182158 }
183159}
0 commit comments