Skip to content

Commit

Permalink
MAGETWO-54054: Compiler performance optimization
Browse files Browse the repository at this point in the history
 - MAGETWO-50778: [Github][PR] Add cache of configuration files list #1628
 - merge mainline
  • Loading branch information
Volodymyr Kublytskyi committed Aug 18, 2016
2 parents 6be7878 + 37692c8 commit be2f0cc
Show file tree
Hide file tree
Showing 275 changed files with 9,573 additions and 2,552 deletions.
18 changes: 8 additions & 10 deletions app/code/Magento/Backend/App/Action/Plugin/MassactionKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,27 @@
*/
namespace Magento\Backend\App\Action\Plugin;

use Magento\Framework\App\RequestInterface;
use Magento\Backend\App\AbstractAction;

class MassactionKey
{
/**
* Process massaction key
*
* @param \Magento\Backend\App\AbstractAction $subject
* @param callable $proceed
* @param \Magento\Framework\App\RequestInterface $request
* @param AbstractAction $subject
* @param RequestInterface $request
*
* @return mixed
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDispatch(
\Magento\Backend\App\AbstractAction $subject,
\Closure $proceed,
\Magento\Framework\App\RequestInterface $request
) {
public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
{
$key = $request->getPost('massaction_prepare_key');
if ($key) {
$postData = $request->getPost($key);
$value = is_array($postData) ? $postData : explode(',', $postData);
$request->setPostValue($key, $value ? $value : null);
}
return $proceed($request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Magento\Backend\Test\Unit\App\Action\Plugin;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Backend\App\AbstractAction;
use Magento\Framework\App\RequestInterface;

class MassactionKeyTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -15,17 +17,12 @@ class MassactionKeyTest extends \PHPUnit_Framework_TestCase
protected $plugin;

/**
* @var \Closure
*/
protected $closureMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var \PHPUnit_Framework_MockObject_MockObject|RequestInterface
*/
protected $requestMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var \PHPUnit_Framework_MockObject_MockObject|AbstractAction
*/
protected $subjectMock;

Expand All @@ -35,27 +32,32 @@ protected function setUp()
return 'Expected';
};
$this->subjectMock = $this->getMock(\Magento\Backend\App\AbstractAction::class, [], [], '', false);
$this->requestMock = $this->getMock(\Magento\Framework\App\Request\Http::class, [], [], '', false);
$this->requestMock = $this->getMockForAbstractClass(
RequestInterface::class,
[],
'',
false,
false,
true,
['getPost', 'setPostValue']
);

$objectManager = new ObjectManager($this);
$this->plugin = $objectManager->getObject(
\Magento\Backend\App\Action\Plugin\MassactionKey::class,
[
'subject' => $this->subjectMock,
'closure' => $this->closureMock,
'request' => $this->requestMock,
]
);
}

/**
* @covers \Magento\Backend\App\Action\Plugin\MassactionKey::aroundDispatch
*
* @param $postData array|string
* @param array $convertedData
* @dataProvider aroundDispatchDataProvider
* @dataProvider beforeDispatchDataProvider
*/
public function testAroundDispatchWhenMassactionPrepareKeyRequestExists($postData, $convertedData)
public function testBeforeDispatchWhenMassactionPrepareKeyRequestExists($postData, $convertedData)
{
$this->requestMock->expects($this->at(0))
->method('getPost')
Expand All @@ -69,24 +71,18 @@ public function testAroundDispatchWhenMassactionPrepareKeyRequestExists($postDat
->method('setPostValue')
->with('key', $convertedData);

$this->assertEquals(
'Expected',
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
);
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
}

public function aroundDispatchDataProvider()
public function beforeDispatchDataProvider()
{
return [
'post_data_is_array' => [['key'], ['key']],
'post_data_is_string' => ['key, key_two', ['key', ' key_two']]
];
}

/**
* @covers \Magento\Backend\App\Action\Plugin\MassactionKey::aroundDispatch
*/
public function testAroundDispatchWhenMassactionPrepareKeyRequestNotExists()
public function testBeforeDispatchWhenMassactionPrepareKeyRequestNotExists()
{
$this->requestMock->expects($this->once())
->method('getPost')
Expand All @@ -95,9 +91,6 @@ public function testAroundDispatchWhenMassactionPrepareKeyRequestNotExists()
$this->requestMock->expects($this->never())
->method('setPostValue');

$this->assertEquals(
'Expected',
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
);
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
}
}
10 changes: 10 additions & 0 deletions app/code/Magento/Braintree/Gateway/Response/RiskDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class RiskDataHandler implements HandlerInterface
*/
const RISK_DATA_DECISION = 'riskDataDecision';

/**
* Risk data Review status
*/
private static $statusReview = 'Review';

/**
* @var SubjectReader
*/
Expand Down Expand Up @@ -62,5 +67,10 @@ public function handle(array $handlingSubject, array $response)

$payment->setAdditionalInformation(self::RISK_DATA_ID, $transaction->riskData->id);
$payment->setAdditionalInformation(self::RISK_DATA_DECISION, $transaction->riskData->decision);

// mark payment as fraud
if ($transaction->riskData->decision === self::$statusReview) {
$payment->setIsFraudDetected(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/
namespace Magento\Braintree\Test\Unit\Gateway\Response;

use Braintree\RiskData;
use Braintree\Transaction;
use Magento\Sales\Model\Order\Payment;
use Magento\Braintree\Gateway\Helper\SubjectReader;
use Magento\Braintree\Gateway\Response\RiskDataHandler;
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
use Magento\Sales\Model\Order\Payment;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class RiskDataHandlerTest
Expand All @@ -25,99 +25,95 @@ class RiskDataHandlerTest extends \PHPUnit_Framework_TestCase
private $riskDataHandler;

/**
* @var SubjectReader|\PHPUnit_Framework_MockObject_MockObject
* @var SubjectReader|MockObject
*/
private $subjectReaderMock;
private $subjectReader;

/**
* Set up
*/
protected function setUp()
{
$this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
$this->subjectReader = $this->getMockBuilder(SubjectReader::class)
->disableOriginalConstructor()
->setMethods(['readPayment', 'readTransaction'])
->getMock();

$this->riskDataHandler = new RiskDataHandler($this->subjectReaderMock);
$this->riskDataHandler = new RiskDataHandler($this->subjectReader);
}

/**
* Run test for handle method
* Test for handle method
* @covers \Magento\Braintree\Gateway\Response\RiskDataHandler::handle
* @param string $riskDecision
* @param boolean $isFraud
* @dataProvider riskDataProvider
*/
public function testHandle()
public function testHandle($riskDecision, $isFraud)
{
$paymentData = $this->getPaymentDataObjectMock();
$transaction = $this->getBraintreeTransactionMock();
/** @var Payment|MockObject $payment */
$payment = $this->getMockBuilder(Payment::class)
->disableOriginalConstructor()
->setMethods(['setAdditionalInformation', 'setIsFraudDetected'])
->getMock();
/** @var PaymentDataObjectInterface|MockObject $paymentDO */
$paymentDO = $this->getMock(PaymentDataObjectInterface::class);
$paymentDO->expects(self::once())
->method('getPayment')
->willReturn($payment);

$transaction = Transaction::factory([
'riskData' => [
'id' => 'test-id',
'decision' => $riskDecision
]
]);

$response = [
'object' => $transaction
];
$handlingSubject = [
'payment' =>$paymentData,
'payment' => $paymentDO,
];

$this->subjectReaderMock->expects(self::once())
$this->subjectReader->expects(static::once())
->method('readPayment')
->with($handlingSubject)
->willReturn($paymentData);
$this->subjectReaderMock->expects(self::once())
->willReturn($paymentDO);
$this->subjectReader->expects(static::once())
->method('readTransaction')
->with($response)
->willReturn($transaction);

$this->riskDataHandler->handle($handlingSubject, $response);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function getBraintreeTransactionMock()
{
$transaction = \Braintree\Transaction::factory([]);
$transaction->_set(
'riskData',
RiskData::factory(
[
'id' => 'test-id',
'decision' => 'test-decision',
]
)
);

return $transaction;
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function getPaymentDataObjectMock()
{
$mock = $this->getMockBuilder(PaymentDataObjectInterface::class)
->getMockForAbstractClass();
$payment->expects(static::at(0))
->method('setAdditionalInformation')
->with(RiskDataHandler::RISK_DATA_ID, 'test-id');
$payment->expects(static::at(1))
->method('setAdditionalInformation')
->with(RiskDataHandler::RISK_DATA_DECISION, $riskDecision);

$mock->expects(static::once())
->method('getPayment')
->willReturn($this->getPaymentMock());
if (!$isFraud) {
$payment->expects(static::never())
->method('setIsFraudDetected');
} else {
$payment->expects(static::once())
->method('setIsFraudDetected')
->with(true);
}

return $mock;
$this->riskDataHandler->handle($handlingSubject, $response);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
* Get list of variations to test fraud
* @return array
*/
private function getPaymentMock()
public function riskDataProvider()
{
$paymentMock = $this->getMockBuilder(Payment::class)
->disableOriginalConstructor()
->getMock();

$paymentMock->expects(self::at(0))
->method('setAdditionalInformation')
->with(RiskDataHandler::RISK_DATA_ID, 'test-id');
$paymentMock->expects(self::at(1))
->method('setAdditionalInformation')
->with(RiskDataHandler::RISK_DATA_DECISION, 'test-decision');

return $paymentMock;
return [
['decision' => 'Not Evaluated', 'isFraud' => false],
['decision' => 'Approve', 'isFraud' => false],
['decision' => 'Review', 'isFraud' => true],
];
}
}
20 changes: 10 additions & 10 deletions app/code/Magento/Braintree/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="payment">
<group id="braintree_section" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Braintree</label>
<comment><![CDATA[Accept credit/debit cards and PayPal in your Magento store. No setup or monthly fees and your customers never leave your store to complete the purchase.]]></comment>
<attribute type="expanded">1</attribute>
<fieldset_css>complex braintree-section</fieldset_css>
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group</frontend_model>
<group id="braintree" translate="label" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">
<label><![CDATA[&nbsp;]]></label>
<group id="braintree_section" sortOrder="6" showInDefault="0" showInWebsite="0" showInStore="0">
<group id="braintree" translate="label comment" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Braintree</label>
<comment><![CDATA[Accept credit/debit cards and PayPal in your Magento store.<br/>No setup or monthly fees and your customers never leave your store to complete the purchase.]]></comment>
<fieldset_css>complex braintree-section</fieldset_css>
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
<attribute type="activity_path">payment/braintree/active</attribute>
<more_url>https://articles.braintreepayments.com/guides/magento/configuration</more_url>
<attribute type="displayIn">recommended_solutions</attribute>
<field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enable this Solution</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand All @@ -43,8 +40,11 @@
<group id="braintree_required"/>
</requires>
</field>
<group id="configuration_details" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="4">
<comment>http://docs.magento.com/m2/ce/user_guide/payment/braintree.html</comment>
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Hint</frontend_model>
</group>
<group id="braintree_required" translate="label" showInDefault="1" showInWebsite="1" sortOrder="5">
<comment><![CDATA[<a href="https://www.braintreegateway.com/login" target="_blank">Click here to login to your existing Braintree account</a>. Or to setup a new account and accept payments on your website, <a href="https://apply.braintreegateway.com/signup/us" target="_blank">click here to signup for a Braintree account</a>.<br><br>Powered by <a href="https://www.braintreepayments.com/features/hosted-fields" target="_blank">Braintree v.zero with Hosted Fields</a> latest technology. Hosted Fields are small, transparent iframes that replace the sensitive credit card inputs in your checkout flow - helping you meet the latest data security requirements while ensuring your customization doesn't suffer. <a href="https://www.braintreepayments.com/features/hosted-fields" target="_blank">Find out more</a>.]]></comment>
<label>Basic Braintree Settings</label>
<attribute type="expanded">1</attribute>
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Braintree/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<can_void>1</can_void>
<can_cancel>1</can_cancel>
<can_edit>1</can_edit>
<can_review_payment>1</can_review_payment>
<can_deny_payment>1</can_deny_payment>
<cctypes>AE,VI,MC,DI,JCB,CUP,DN,MI</cctypes>
<useccv>1</useccv>
<cctypes_braintree_mapper><![CDATA[{"american-express":"AE","discover":"DI","jcb":"JCB","mastercard":"MC","master-card":"MC","visa":"VI","maestro":"MI","diners-club":"DN","unionpay":"CUP"}]]></cctypes_braintree_mapper>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Braintree/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<item name="void" xsi:type="string">BraintreeVoidCommand</item>
<item name="refund" xsi:type="string">BraintreeRefundCommand</item>
<item name="cancel" xsi:type="string">BraintreeVoidCommand</item>
<item name="deny_payment" xsi:type="string">BraintreeVoidCommand</item>
</argument>
</arguments>
</virtualType>
Expand Down
Loading

0 comments on commit be2f0cc

Please sign in to comment.