Skip to content

Commit

Permalink
Updating unit test for asserting return from private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
khushboo-singhvi committed Oct 18, 2024
1 parent ec5f014 commit ad67f20
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions Test/Unit/Helper/PaymentResponseHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ private static function handlePaymentsDetailsActionCancelledOrRefusedProvider():
{
return [
['resultCode' => PaymentResponseHandler::REFUSED],
['resultCode' => PaymentResponseHandler::CANCELLED]
['resultCode' => PaymentResponseHandler::CANCELLED],
['resultCode' => PaymentResponseHandler::CANCELLED, 'hasGiftCard' => true]
];
}

Expand All @@ -398,7 +399,7 @@ private static function handlePaymentsDetailsActionCancelledOrRefusedProvider():
* @throws NoSuchEntityException
* @dataProvider handlePaymentsDetailsActionCancelledOrRefusedProvider
*/
public function testHandlePaymentsDetailsResponseCancelOrRefused($resultCode)
public function testHandlePaymentsDetailsResponseCancelOrRefused($resultCode, $hasGiftCard = false)
{
$paymentsDetailsResponse = [
'resultCode' => $resultCode,
Expand All @@ -412,6 +413,16 @@ public function testHandlePaymentsDetailsResponseCancelOrRefused($resultCode)
]
];

if ($hasGiftCard) {
$giftcardData = $this->testHasActiveGiftCardPayments();
// Mock the dataHelper and service to simulate cancellation call
$this->dataHelperMock->expects($this->once())->method('initializeAdyenClient');
$this->dataHelperMock->expects($this->once())->method('initializeOrdersApi');
$this->adyenLoggerMock->expects($this->once())->method('error')->with(
'Error canceling partial payments',
$this->anything()
);
}
$this->adyenLoggerMock->expects($this->atLeastOnce())->method('addAdyenResult');

$result = $this->paymentResponseHandler->handlePaymentsDetailsResponse(
Expand Down Expand Up @@ -543,11 +554,6 @@ public function testOrderStatusUpdateWhenResponseIsValid()

public function testHasActiveGiftCardPayments()
{

// Mock the addFieldToFilter method to return the collection itself for chaining


// Mock getSize to simulate an authorized gift card payment
$this->paymentResponseMockForFactory->expects($this->any())
->method('getSize')
->willReturn(1); // Simulate there is at least one record
Expand Down Expand Up @@ -583,5 +589,6 @@ public function testHasActiveGiftCardPayments()
$this->assertEquals([
['merchant_reference' => '12345', 'result_code' => 'Authorised']
], $result);
return $result;
}
}

0 comments on commit ad67f20

Please sign in to comment.