Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
fix static test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
pmclain committed Jun 18, 2019
1 parent a784526 commit ca74ab5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 41 deletions.
12 changes: 12 additions & 0 deletions app/code/Magento/BraintreeGraphQl/Model/BraintreeDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
use Magento\Framework\Stdlib\ArrayManager;

/**
* Format Braintree input into value expected when setting payment method
*/
class BraintreeDataProvider implements AdditionalDataProviderInterface
{
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/braintree';
Expand All @@ -19,12 +22,21 @@ class BraintreeDataProvider implements AdditionalDataProviderInterface
*/
private $arrayManager;

/**
* @param ArrayManager $arrayManager
*/
public function __construct(
ArrayManager $arrayManager
) {
$this->arrayManager = $arrayManager;
}

/**
* Format Braintree input into value expected when setting payment method
*
* @param array $args
* @return array
*/
public function getData(array $args): array
{
return $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $args) ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
use Magento\Framework\Stdlib\ArrayManager;

/**
* Format Braintree input into value expected when setting payment method
*/
class BraintreeVaultDataProvider implements AdditionalDataProviderInterface
{
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/braintree_cc_vault';
Expand All @@ -19,12 +22,21 @@ class BraintreeVaultDataProvider implements AdditionalDataProviderInterface
*/
private $arrayManager;

/**
* @param ArrayManager $arrayManager
*/
public function __construct(
ArrayManager $arrayManager
) {
$this->arrayManager = $arrayManager;
}

/**
* Format Braintree input into value expected when setting payment method
*
* @param array $args
* @return array
*/
public function getData(array $args): array
{
return $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $args) ?? [];
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/BraintreeGraphQl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "magento2-module",
"require": {
"php": "~7.1.3||~7.2.0",
"magento/framework": "*"
"magento/framework": "*",
"magento/module-quote-graph-ql": "*"
},
"suggest": {
"magento/module-graph-ql": "*"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
*/
class BraintreeAdapter extends \Magento\Braintree\Model\Adapter\BraintreeAdapter
{
/**
* @var Config
*/
private $config;

/**
* @var MockResponseDataProvider
*/
Expand Down Expand Up @@ -56,7 +51,7 @@ public function __construct(
*/
public function createNonce($token)
{
return $this->mockResponseDataProvider->generateMockNonceResponse();
return $this->mockResponseDataProvider->generateMockNonceResponse($token);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public function generateMockSaleResponse(array $attributes): \Braintree\Instance
/**
* Create mock nonce response for testing
*
* @param string $token
* @return \Braintree\Instance
*/
public function generateMockNonceResponse(): \Braintree\Instance
public function generateMockNonceResponse(string $token): \Braintree\Instance
{
$nonce = $this->createNonce();
$nonce = $this->createNonce($token);

return new \Braintree\Result\Successful($nonce, 'paymentMethodNonce');
}
Expand All @@ -63,21 +64,23 @@ public function generateMockNonceResponse(): \Braintree\Instance
private function createTransaction(array $attributes): \Braintree\Transaction
{
$creditCardInfo = $this->generateCardDetails();
return \Braintree\Transaction::factory([
'amount' => $attributes['amount'],
'billing' => $attributes['billing'] ?? null,
'creditCard' => $creditCardInfo,
'cardDetails' => new \Braintree\Transaction\CreditCardDetails($creditCardInfo),
'currencyIsoCode' => 'USD',
'customer' => $attributes['customer'],
'cvvResponseCode' => 'M',
'id' => $this->random->getRandomString(8),
'options' => $attributes['options'] ?? null,
'shipping' => $attributes['shipping'] ?? null,
'paymentMethodNonce' => $attributes['paymentMethodNonce'],
'status' => 'authorized',
'type' => 'sale',
]);
return \Braintree\Transaction::factory(
[
'amount' => $attributes['amount'],
'billing' => $attributes['billing'] ?? null,
'creditCard' => $creditCardInfo,
'cardDetails' => new \Braintree\Transaction\CreditCardDetails($creditCardInfo),
'currencyIsoCode' => 'USD',
'customer' => $attributes['customer'],
'cvvResponseCode' => 'M',
'id' => $this->random->getRandomString(8),
'options' => $attributes['options'] ?? null,
'shipping' => $attributes['shipping'] ?? null,
'paymentMethodNonce' => $attributes['paymentMethodNonce'],
'status' => 'authorized',
'type' => 'sale',
]
);
}

/**
Expand All @@ -102,27 +105,31 @@ private function generateCardDetails(): array
/**
* Create fake Braintree nonce
*
* @param string $token
* @return \Braintree\PaymentMethodNonce
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function createNonce(): \Braintree\PaymentMethodNonce
private function createNonce(string $token): \Braintree\PaymentMethodNonce
{
$lastFour = (string) random_int(1000, 9999);
$lastTwo = substr($lastFour, -2);
return \Braintree\PaymentMethodNonce::factory([
'consumed' => false,
'default' => true,
'description' => 'ending in ' . $lastTwo,
'details' => [
'bin' => $this->random->getRandomString(6),
'cardType' => 'Visa',
'lastFour' => $lastFour,
'lastTwo' => $lastTwo,
],
'hasSubscription' => false,
'isLocked' => false,
'nonce' => $this->random->getRandomString(36),
'type' => 'CreditCard'
]);
return \Braintree\PaymentMethodNonce::factory(
[
'bin' => $token,
'consumed' => false,
'default' => true,
'description' => 'ending in ' . $lastTwo,
'details' => [
'bin' => $this->random->getRandomString(6),
'cardType' => 'Visa',
'lastFour' => $lastFour,
'lastTwo' => $lastTwo,
],
'hasSubscription' => false,
'isLocked' => false,
'nonce' => $this->random->getRandomString(36),
'type' => 'CreditCard'
]
);
}
}

0 comments on commit ca74ab5

Please sign in to comment.