7
7
8
8
namespace Magento \AuthorizenetGraphQl \Model \Resolver \Customer ;
9
9
10
- use Magento \Framework \App \Request \Http ;
11
10
use Magento \Framework \Serialize \SerializerInterface ;
12
- use Magento \GraphQl \Controller \GraphQl ;
13
11
use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
12
+ use Magento \GraphQl \Service \GraphQlRequest ;
14
13
use Magento \Integration \Api \CustomerTokenServiceInterface ;
15
- use Magento \Framework \Webapi \Request ;
16
14
use Magento \TestFramework \Helper \Bootstrap ;
17
15
use Magento \Framework \HTTP \ZendClient ;
18
16
use Magento \Framework \HTTP \ZendClientFactory ;
19
17
use Magento \TestFramework \ObjectManager ;
20
18
use PHPUnit \Framework \MockObject \Builder \InvocationMocker ;
21
- use Magento \Payment \Gateway \Data \PaymentDataObjectFactory ;
22
19
use PHPUnit \Framework \MockObject \MockObject ;
23
- use Magento \Quote \Model \Quote \PaymentFactory ;
24
20
use PHPUnit \Framework \TestCase ;
25
21
use Zend_Http_Response ;
26
22
29
25
*
30
26
* @magentoAppArea graphql
31
27
* @magentoDbIsolation disabled
32
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
33
28
*/
34
29
class PlaceOrderWithAuthorizeNetTest extends TestCase
35
30
{
36
- const CONTENT_TYPE = 'application/json ' ;
37
-
38
- /** @var ObjectManager */
31
+ /** @var ObjectManager */
39
32
private $ objectManager ;
40
33
41
- /** @var GetMaskedQuoteIdByReservedOrderId */
34
+ /** @var GetMaskedQuoteIdByReservedOrderId */
42
35
private $ getMaskedQuoteIdByReservedOrderId ;
43
36
44
37
/** @var SerializerInterface */
45
38
private $ jsonSerializer ;
46
39
47
- /** @var Http */
48
- private $ request ;
40
+ /** @var GraphQlRequest */
41
+ private $ graphQlRequest ;
49
42
50
43
/** @var ZendClient|MockObject|InvocationMocker */
51
44
private $ clientMock ;
52
45
53
- /** @var CustomerTokenServiceInterface */
46
+ /** @var CustomerTokenServiceInterface */
54
47
private $ customerTokenService ;
55
48
56
49
/** @var Zend_Http_Response */
57
50
protected $ responseMock ;
58
51
59
- /** @var PaymentFactory */
60
- private $ paymentFactory ;
61
-
62
52
protected function setUp () : void
63
53
{
64
54
$ this ->objectManager = Bootstrap::getObjectManager ();
65
55
$ this ->jsonSerializer = $ this ->objectManager ->get (SerializerInterface::class);
66
- $ this ->request = $ this ->objectManager ->get (Http ::class);
56
+ $ this ->graphQlRequest = $ this ->objectManager ->create (GraphQlRequest ::class);
67
57
$ this ->getMaskedQuoteIdByReservedOrderId = $ this ->objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
68
58
$ this ->customerTokenService = $ this ->objectManager ->get (CustomerTokenServiceInterface::class);
69
59
$ this ->clientMock = $ this ->createMock (ZendClient::class);
@@ -75,8 +65,6 @@ protected function setUp() : void
75
65
$ clientFactoryMock = $ this ->createMock (ZendClientFactory::class);
76
66
$ clientFactoryMock ->method ('create ' )
77
67
->willReturn ($ this ->clientMock );
78
- /** @var PaymentDataObjectFactory $paymentFactory */
79
- $ this ->paymentFactory = $ this ->objectManager ->get (PaymentDataObjectFactory::class);
80
68
$ this ->objectManager ->addSharedInstance ($ clientFactoryMock , ZendClientFactory::class);
81
69
}
82
70
@@ -126,23 +114,12 @@ public function testDispatchToPlaceOrderWithRegisteredCustomer(): void
126
114
}
127
115
}
128
116
QUERY ;
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 (
'[email protected] ' ,
'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);
145
117
118
+ $ customerToken =
$ this ->
customerTokenService ->
createCustomerAccessToken (
'[email protected] ' ,
'password ' );
119
+ $ requestHeaders = [
120
+ 'Accept ' => 'application/json ' ,
121
+ 'Authorization ' => 'Bearer ' . $ customerToken
122
+ ];
146
123
// phpcs:ignore Magento2.Security.IncludeFile
147
124
$ expectedRequest = include __DIR__ . '/../../../_files/request_authorize_customer.php ' ;
148
125
// phpcs:ignore Magento2.Security.IncludeFile
@@ -153,7 +130,7 @@ public function testDispatchToPlaceOrderWithRegisteredCustomer(): void
153
130
154
131
$ this ->responseMock ->method ('getBody ' )->willReturn (json_encode ($ authorizeResponse ));
155
132
156
- $ response = $ graphql -> dispatch ( $ this -> request );
133
+ $ response = $ this -> graphQlRequest -> send ( $ query , [], '' , $ requestHeaders );
157
134
$ responseData = $ this ->jsonSerializer ->unserialize ($ response ->getContent ());
158
135
159
136
$ this ->assertArrayNotHasKey ('errors ' , $ responseData , 'Response has errors ' );
@@ -178,6 +155,5 @@ public function testDispatchToPlaceOrderWithRegisteredCustomer(): void
178
155
protected function tearDown ()
179
156
{
180
157
$ this ->objectManager ->removeSharedInstance (ZendClientFactory::class);
181
- parent ::tearDown ();
182
158
}
183
159
}
0 commit comments