From af004c0456ce44d000e1e5f3c9e7628cb1a8a8eb Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 27 Jan 2016 03:45:47 +0530 Subject: [PATCH] CRM-16188, modified code to add exception and also changed test to check exception errors ---------------------------------------- * CRM-16188: Create an order API https://issues.civicrm.org/jira/browse/CRM-16188 --- CRM/Contribute/BAO/Contribution.php | 4 +--- .../phpunit/CRM/Contribute/BAO/ContributionTest.php | 12 ++++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 763f9b629d..ae31ac8a90 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4824,7 +4824,6 @@ LIMIT 1;"; * @param array $params * array of order params. * - * @return string */ public static function checkLineItems(&$params) { $totalAmount = CRM_Utils_Array::value('total_amount', $params); @@ -4841,9 +4840,8 @@ LIMIT 1;"; $params['total_amount'] = $lineItemAmount; } elseif ($totalAmount != $lineItemAmount) { - return "Line item total doesn't match with total amount."; + throw new API_Exception("Line item total doesn't match with total amount."); } - return NULL; } } diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index c481d63ee9..4061b0f7bc 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -819,12 +819,16 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; ), ), ); - $error = CRM_Contribute_BAO_Contribution::checkLineItems($params); - $this->assertEquals("Line item total doesn't match with total amount.", $error); + try { + $error = CRM_Contribute_BAO_Contribution::checkLineItems($params); + $this->fail("Missed expected exception"); + } + catch (Exception $e) { + $this->assertEquals("Line item total doesn't match with total amount.", $e->getMessage()); + } $this->assertEquals(3, $params['line_items'][0]['line_item'][0]['financial_type_id']); $params['total_amount'] = 300; - $error = CRM_Contribute_BAO_Contribution::checkLineItems($params); - $this->assertEquals(NULL, $error); + CRM_Contribute_BAO_Contribution::checkLineItems($params); } } -- 2.25.1