Skip to content

Commit 5f25fdd

Browse files
committed
fix static test failures
1 parent a784526 commit 5f25fdd

File tree

12 files changed

+110
-75
lines changed

12 files changed

+110
-75
lines changed

app/code/Magento/BraintreeGraphQl/Model/BraintreeDataProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
1111
use Magento\Framework\Stdlib\ArrayManager;
1212

13+
/**
14+
* Format Braintree input into value expected when setting payment method
15+
*/
1316
class BraintreeDataProvider implements AdditionalDataProviderInterface
1417
{
1518
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/braintree';
@@ -19,12 +22,21 @@ class BraintreeDataProvider implements AdditionalDataProviderInterface
1922
*/
2023
private $arrayManager;
2124

25+
/**
26+
* @param ArrayManager $arrayManager
27+
*/
2228
public function __construct(
2329
ArrayManager $arrayManager
2430
) {
2531
$this->arrayManager = $arrayManager;
2632
}
2733

34+
/**
35+
* Format Braintree input into value expected when setting payment method
36+
*
37+
* @param array $args
38+
* @return array
39+
*/
2840
public function getData(array $args): array
2941
{
3042
return $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $args) ?? [];

app/code/Magento/BraintreeGraphQl/Model/BraintreeVaultDataProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
1111
use Magento\Framework\Stdlib\ArrayManager;
1212

13+
/**
14+
* Format Braintree input into value expected when setting payment method
15+
*/
1316
class BraintreeVaultDataProvider implements AdditionalDataProviderInterface
1417
{
1518
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/braintree_cc_vault';
@@ -19,12 +22,21 @@ class BraintreeVaultDataProvider implements AdditionalDataProviderInterface
1922
*/
2023
private $arrayManager;
2124

25+
/**
26+
* @param ArrayManager $arrayManager
27+
*/
2228
public function __construct(
2329
ArrayManager $arrayManager
2430
) {
2531
$this->arrayManager = $arrayManager;
2632
}
2733

34+
/**
35+
* Format Braintree input into value expected when setting payment method
36+
*
37+
* @param array $args
38+
* @return array
39+
*/
2840
public function getData(array $args): array
2941
{
3042
return $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $args) ?? [];

app/code/Magento/BraintreeGraphQl/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"type": "magento2-module",
55
"require": {
66
"php": "~7.1.3||~7.2.0",
7-
"magento/framework": "*"
7+
"magento/framework": "*",
8+
"magento/module-quote-graph-ql": "*"
89
},
910
"suggest": {
1011
"magento/module-graph-ql": "*"

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"magento/module-backend": "*",
113113
"magento/module-backup": "*",
114114
"magento/module-braintree": "*",
115+
"magento/module-braintree-graph-ql": "*",
115116
"magento/module-bundle": "*",
116117
"magento/module-bundle-graph-ql": "*",
117118
"magento/module-bundle-import-export": "*",

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/api-functional/_files/Magento/TestModuleBraintree/Model/Adapter/BraintreeAdapter.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
*/
2323
class BraintreeAdapter extends \Magento\Braintree\Model\Adapter\BraintreeAdapter
2424
{
25-
/**
26-
* @var Config
27-
*/
28-
private $config;
29-
3025
/**
3126
* @var MockResponseDataProvider
3227
*/
@@ -56,7 +51,7 @@ public function __construct(
5651
*/
5752
public function createNonce($token)
5853
{
59-
return $this->mockResponseDataProvider->generateMockNonceResponse();
54+
return $this->mockResponseDataProvider->generateMockNonceResponse($token);
6055
}
6156

6257
/**

dev/tests/api-functional/_files/Magento/TestModuleBraintree/Model/MockResponseDataProvider.php

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ public function generateMockSaleResponse(array $attributes): \Braintree\Instance
4444
/**
4545
* Create mock nonce response for testing
4646
*
47+
* @param string $token
4748
* @return \Braintree\Instance
4849
*/
49-
public function generateMockNonceResponse(): \Braintree\Instance
50+
public function generateMockNonceResponse(string $token): \Braintree\Instance
5051
{
51-
$nonce = $this->createNonce();
52+
$nonce = $this->createNonce($token);
5253

5354
return new \Braintree\Result\Successful($nonce, 'paymentMethodNonce');
5455
}
@@ -63,21 +64,23 @@ public function generateMockNonceResponse(): \Braintree\Instance
6364
private function createTransaction(array $attributes): \Braintree\Transaction
6465
{
6566
$creditCardInfo = $this->generateCardDetails();
66-
return \Braintree\Transaction::factory([
67-
'amount' => $attributes['amount'],
68-
'billing' => $attributes['billing'] ?? null,
69-
'creditCard' => $creditCardInfo,
70-
'cardDetails' => new \Braintree\Transaction\CreditCardDetails($creditCardInfo),
71-
'currencyIsoCode' => 'USD',
72-
'customer' => $attributes['customer'],
73-
'cvvResponseCode' => 'M',
74-
'id' => $this->random->getRandomString(8),
75-
'options' => $attributes['options'] ?? null,
76-
'shipping' => $attributes['shipping'] ?? null,
77-
'paymentMethodNonce' => $attributes['paymentMethodNonce'],
78-
'status' => 'authorized',
79-
'type' => 'sale',
80-
]);
67+
return \Braintree\Transaction::factory(
68+
[
69+
'amount' => $attributes['amount'],
70+
'billing' => $attributes['billing'] ?? null,
71+
'creditCard' => $creditCardInfo,
72+
'cardDetails' => new \Braintree\Transaction\CreditCardDetails($creditCardInfo),
73+
'currencyIsoCode' => 'USD',
74+
'customer' => $attributes['customer'],
75+
'cvvResponseCode' => 'M',
76+
'id' => $this->random->getRandomString(8),
77+
'options' => $attributes['options'] ?? null,
78+
'shipping' => $attributes['shipping'] ?? null,
79+
'paymentMethodNonce' => $attributes['paymentMethodNonce'],
80+
'status' => 'authorized',
81+
'type' => 'sale',
82+
]
83+
);
8184
}
8285

8386
/**
@@ -102,27 +105,31 @@ private function generateCardDetails(): array
102105
/**
103106
* Create fake Braintree nonce
104107
*
108+
* @param string $token
105109
* @return \Braintree\PaymentMethodNonce
106110
* @throws \Magento\Framework\Exception\LocalizedException
107111
*/
108-
private function createNonce(): \Braintree\PaymentMethodNonce
112+
private function createNonce(string $token): \Braintree\PaymentMethodNonce
109113
{
110114
$lastFour = (string) random_int(1000, 9999);
111115
$lastTwo = substr($lastFour, -2);
112-
return \Braintree\PaymentMethodNonce::factory([
113-
'consumed' => false,
114-
'default' => true,
115-
'description' => 'ending in ' . $lastTwo,
116-
'details' => [
117-
'bin' => $this->random->getRandomString(6),
118-
'cardType' => 'Visa',
119-
'lastFour' => $lastFour,
120-
'lastTwo' => $lastTwo,
121-
],
122-
'hasSubscription' => false,
123-
'isLocked' => false,
124-
'nonce' => $this->random->getRandomString(36),
125-
'type' => 'CreditCard'
126-
]);
116+
return \Braintree\PaymentMethodNonce::factory(
117+
[
118+
'bin' => $token,
119+
'consumed' => false,
120+
'default' => true,
121+
'description' => 'ending in ' . $lastTwo,
122+
'details' => [
123+
'bin' => $this->random->getRandomString(6),
124+
'cardType' => 'Visa',
125+
'lastFour' => $lastFour,
126+
'lastTwo' => $lastTwo,
127+
],
128+
'hasSubscription' => false,
129+
'isLocked' => false,
130+
'nonce' => $this->random->getRandomString(36),
131+
'type' => 'CreditCard'
132+
]
133+
);
127134
}
128135
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Braintree/Customer/SetPaymentMethodTest.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
use Magento\Vault\Model\ResourceModel\PaymentToken;
1919
use Magento\Vault\Model\ResourceModel\PaymentToken\CollectionFactory as TokenCollectionFactory;
2020

21+
/**
22+
* Test setting payment method and placing order with Braintree
23+
*/
2124
class SetPaymentMethodTest extends GraphQlAbstract
2225
{
23-
private const REQUIRED_CONSTS = [
24-
'TESTS_BRAINTREE_MERCHANT_ID',
25-
'TESTS_BRAINTREE_PUBLIC_KEY',
26-
'TESTS_BRAINTREE_PRIVATE_KEY',
27-
];
28-
2926
/**
3027
* @var CustomerTokenServiceInterface
3128
*/
@@ -71,12 +68,6 @@ class SetPaymentMethodTest extends GraphQlAbstract
7168
*/
7269
protected function setUp()
7370
{
74-
foreach (static::REQUIRED_CONSTS as $const) {
75-
if (!defined($const)) {
76-
$this->markTestSkipped('Braintree sandbox credentials must be defined in phpunit_graphql.xml.dist');
77-
}
78-
}
79-
8071
$objectManager = Bootstrap::getObjectManager();
8172
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
8273
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
@@ -178,13 +169,20 @@ public function testPlaceOrderWithVault()
178169
$reservedOrderId = 'test_quote';
179170
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
180171

181-
$nonceResult = $this->getNonceCommand->execute([
182-
'customer_id' => 1,
183-
'public_hash' => 'braintree_public_hash',
184-
]);
172+
$nonceResult = $this->getNonceCommand->execute(
173+
[
174+
'customer_id' => 1,
175+
'public_hash' => 'braintree_public_hash',
176+
]
177+
);
185178
$nonce = $nonceResult->get()['paymentMethodNonce'];
186179

187-
$setPaymentQuery = $this->getSetPaymentBraintreeVaultQuery($maskedQuoteId, 'braintree_public_hash', $nonce, true);
180+
$setPaymentQuery = $this->getSetPaymentBraintreeVaultQuery(
181+
$maskedQuoteId,
182+
'braintree_public_hash',
183+
$nonce,
184+
true
185+
);
188186
$setPaymentResponse = $this->graphQlMutation($setPaymentQuery, [], '', $this->getHeaderMap());
189187

190188
$this->assertSetPaymentMethodResponse($setPaymentResponse, 'braintree_cc_vault');
@@ -251,8 +249,12 @@ private function getSetPaymentBraintreeQuery(string $maskedQuoteId, bool $saveIn
251249
* @param bool $saveInVault
252250
* @return string
253251
*/
254-
private function getSetPaymentBraintreeVaultQuery(string $maskedQuoteId, string $publicHash, string $nonce, bool $saveInVault = false): string
255-
{
252+
private function getSetPaymentBraintreeVaultQuery(
253+
string $maskedQuoteId,
254+
string $publicHash,
255+
string $nonce,
256+
bool $saveInVault = false
257+
): string {
256258
$saveInVault = json_encode($saveInVault);
257259
return <<<QUERY
258260
mutation {

dev/tests/api-functional/testsuite/Magento/GraphQl/Braintree/Guest/SetPaymentMethodTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use Magento\TestFramework\Helper\Bootstrap;
1616
use Magento\TestFramework\TestCase\GraphQlAbstract;
1717

18+
/**
19+
* Test setting payment method and placing order with Braintree
20+
*/
1821
class SetPaymentMethodTest extends GraphQlAbstract
1922
{
2023
private const REQUIRED_CONSTS = [

dev/tests/integration/testsuite/Magento/GraphQl/Braintree/_files/payments.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
// save payment configuration for the default scope
2525
$configData = [
26-
'payment/braintree/merchant_id' => defined('TESTS_BRAINTREE_MERCHANT_ID') ? TESTS_BRAINTREE_MERCHANT_ID : 'def_merchant_id',
27-
'payment/braintree/public_key' => $encryptor->encrypt(defined('TESTS_BRAINTREE_PUBLIC_KEY') ? TESTS_BRAINTREE_PUBLIC_KEY : 'def_public_key'),
28-
'payment/braintree/private_key' => $encryptor->encrypt(defined('TESTS_BRAINTREE_PRIVATE_KEY') ? TESTS_BRAINTREE_PRIVATE_KEY : 'def_private_key'),
26+
'payment/braintree/merchant_id' => 'def_merchant_id',
27+
'payment/braintree/public_key' => $encryptor->encrypt('def_public_key'),
28+
'payment/braintree/private_key' => $encryptor->encrypt('def_private_key'),
2929
'payment/' . ConfigProvider::CODE . '/active' => '1',
3030
'payment/' . ConfigProvider::CC_VAULT_CODE . '/active' => '1',
3131
'payment/' . ConfigProvider::CODE . '/environment' => 'sandbox',

0 commit comments

Comments
 (0)