Skip to content

Commit 7471197

Browse files
committed
MAGETWO-63910: Create infrastructure for mapper in Payment module
- Refactored code - Added unit tests
1 parent f7b8fd1 commit 7471197

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

app/code/Magento/Braintree/Model/AvsEmsCodeMapper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ class AvsEmsCodeMapper implements PaymentVerificationInterface
4848
*
4949
* @param OrderPaymentInterface $orderPayment
5050
* @return string
51-
* @throws \Exception
51+
* @throws \InvalidArgumentException
5252
*/
5353
public function getCode(OrderPaymentInterface $orderPayment)
5454
{
5555
if ($orderPayment->getMethod() !== ConfigProvider::CODE) {
56-
throw new \Exception('"' . $orderPayment->getMethod() . '" does not supported by Braintree AVS mapper.');
56+
throw new \InvalidArgumentException(
57+
'The "' . $orderPayment->getMethod() . '" does not supported by Braintree AVS mapper.'
58+
);
5759
}
5860

5961
$additionalInfo = $orderPayment->getAdditionalInformation();

app/code/Magento/Braintree/Model/CvvEmsCodeMapper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class CvvEmsCodeMapper implements PaymentVerificationInterface
5252
public function getCode(OrderPaymentInterface $orderPayment)
5353
{
5454
if ($orderPayment->getMethod() !== ConfigProvider::CODE) {
55-
throw new \Exception('"' . $orderPayment->getMethod() . '" does not supported by Braintree CVV mapper.');
55+
throw new \InvalidArgumentException(
56+
'The "' . $orderPayment->getMethod() . '" does not supported by Braintree CVV mapper.'
57+
);
5658
}
5759

5860
$additionalInfo = $orderPayment->getAdditionalInformation();

app/code/Magento/Braintree/Test/Unit/Model/AvsEmsCodeMapperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function testGetCode($avsZip, $avsStreet, $expected)
5959
* Checks a test case, when payment order is not Braintree payment method.
6060
*
6161
* @covers \Magento\Braintree\Model\AvsEmsCodeMapper::getCode
62-
* @expectedException \Exception
63-
* @expectedExceptionMessage "some_payment" does not supported by Braintree AVS mapper.
62+
* @expectedException \InvalidArgumentException
63+
* @expectedExceptionMessage The "some_payment" does not supported by Braintree AVS mapper.
6464
*/
6565
public function testGetCodeWithException()
6666
{

app/code/Magento/Braintree/Test/Unit/Model/CvvEmsCodeMapperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public function testGetCode($cvvCode, $expected)
5555
* Checks a test case, when payment order is not Braintree payment method.
5656
*
5757
* @covers \Magento\Braintree\Model\CvvEmsCodeMapper::getCode
58-
* @expectedException \Exception
59-
* @expectedExceptionMessage "some_payment" does not supported by Braintree CVV mapper.
58+
* @expectedException \InvalidArgumentException
59+
* @expectedExceptionMessage The "some_payment" does not supported by Braintree CVV mapper.
6060
*/
6161
public function testGetCodeWithException()
6262
{

app/code/Magento/Payment/Api/PaymentVerificationInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ interface PaymentVerificationInterface
2424
{
2525
/**
2626
* Gets payment provider verification code.
27+
* Throws an exception if provided payment method is different to verification implementation.
2728
*
2829
* @param OrderPaymentInterface $orderPayment
2930
* @return string
31+
* @throws \InvalidArgumentException
3032
*/
3133
public function getCode(OrderPaymentInterface $orderPayment);
3234
}

0 commit comments

Comments
 (0)