Skip to content

Commit

Permalink
Updating unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
khushboo-singhvi committed Oct 18, 2024
1 parent 37772dc commit 569ccf8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Helper/PaymentResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ public function handlePaymentsDetailsResponse(
case self::REFUSED:
case self::CANCELLED:
$getGiftcardDetails = $this->hasActiveGiftCardPayments(
$order,
$paymentsDetailsResponse['merchantReference']
);
if (!empty($getGiftcardDetails)) {
Expand Down Expand Up @@ -410,7 +409,7 @@ private function isValidMerchantReference(array $paymentsDetailsResponse, OrderI
}

// Method to check for existing Gift Card payments
private function hasActiveGiftCardPayments(OrderInterface $order, $merchantReference)
private function hasActiveGiftCardPayments($merchantReference)
{
$paymentResponseCollection = $this->paymentResponseCollectionFactory->create()
->addFieldToFilter('merchant_reference', $merchantReference)
Expand Down
35 changes: 35 additions & 0 deletions Test/Unit/Helper/PaymentResponseHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Adyen\Payment\Model\ResourceModel\PaymentResponse\Collection;
use Adyen\Payment\Model\ResourceModel\PaymentResponse\CollectionFactory;
use Adyen\Payment\Helper\Config as Config;
use ReflectionClass;

class PaymentResponseHandlerTest extends AbstractAdyenTestCase
{
Expand Down Expand Up @@ -475,4 +476,38 @@ public function testHandlePaymentsDetailsResponseInvalidMerchantReference(){

$this->assertFalse($result);
}

public function testHandlePaymentsDetailsResponseValidMerchantReference()
{
$paymentsDetailsResponse = [
'resultCode' => PaymentResponseHandler::AUTHORISED,
'pspReference' => 'ABC123456789',
'paymentMethod' => [
'brand' => 'ideal'
],
'merchantReference' => '00123456' // assuming this is a valid reference
];
// Mock the isValidMerchantReference to return true
$reflectionClass = new ReflectionClass(PaymentResponseHandler::class);
$method = $reflectionClass->getMethod('isValidMerchantReference');
$method->setAccessible(true);
$isValidMerchantReference = $method->invokeArgs($this->paymentResponseHandler, [$paymentsDetailsResponse,$this->orderMock]);
$this->assertTrue($isValidMerchantReference);
}

public function testPaymentDetailsCallFailureLogsError()
{
$resultCode = 'some_result_code';
$paymentsDetailsResponse = ['error' => 'some error message'];

// Expect the logger to be called with the specific message
$this->adyenLoggerMock->expects($this->once())
->method('error');

// Call the method that triggers the logging, e.g., handlePaymentDetailsFailure()
$this->paymentResponseHandler->handlePaymentsDetailsResponse(
$paymentsDetailsResponse,
$this->orderMock
);
}
}

0 comments on commit 569ccf8

Please sign in to comment.