From ee95478a269cc6d7e481720990fb07cccddd6f4a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 29 May 2021 19:12:23 +1200 Subject: [PATCH] [NFC] Superficial code cleanup --- api/v3/Order.php | 23 +++++++++++-------- .../CRM/Contribute/Form/ContributionTest.php | 23 ++++++++++++++----- .../phpunit/CRM/Core/Payment/BaseIPNTest.php | 23 ++++++++++++++----- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/api/v3/Order.php b/api/v3/Order.php index 92ee017d6e..2a9a5e4936 100644 --- a/api/v3/Order.php +++ b/api/v3/Order.php @@ -24,8 +24,9 @@ * * @return array * Array of Order, if error an array with an error id and error message + * @throws \CiviCRM_API3_Exception */ -function civicrm_api3_order_get($params) { +function civicrm_api3_order_get(array $params): array { $contributions = []; $params['api.line_item.get'] = ['qty' => ['<>' => 0]]; $isSequential = FALSE; @@ -53,7 +54,7 @@ function civicrm_api3_order_get($params) { * @param array $params * Array of parameters determined by getfields. */ -function _civicrm_api3_order_get_spec(&$params) { +function _civicrm_api3_order_get_spec(array &$params) { $params['id']['api.aliases'] = ['order_id']; $params['id']['title'] = ts('Contribution / Order ID'); } @@ -70,7 +71,7 @@ function _civicrm_api3_order_get_spec(&$params) { * @throws \CiviCRM_API3_Exception * @throws API_Exception */ -function civicrm_api3_order_create($params) { +function civicrm_api3_order_create(array $params): array { civicrm_api3_verify_one_mandatory($params, NULL, ['line_items', 'total_amount']); $entity = NULL; $entityIds = []; @@ -156,10 +157,10 @@ function civicrm_api3_order_create($params) { $entity . '_id' => $entityId, ]; // if entity is pledge then build pledge param - if ($entity == 'pledge') { + if ($entity === 'pledge') { $paymentParams += $entityParams; } - elseif ($entity == 'membership') { + elseif ($entity === 'membership') { $contribution['values'][$contribution['id']]['membership_id'][] = $entityId; $paymentParams['isSkipLineItem'] = TRUE; } @@ -174,11 +175,12 @@ function civicrm_api3_order_create($params) { * * @param array $params * Input parameters. + * * @return array * @throws API_Exception * @throws CiviCRM_API3_Exception */ -function civicrm_api3_order_delete($params) { +function civicrm_api3_order_delete(array $params): array { $contribution = civicrm_api3('Contribution', 'get', [ 'return' => ['is_test'], 'id' => $params['id'], @@ -199,8 +201,9 @@ function civicrm_api3_order_delete($params) { * Input parameters. * * @return array + * @throws \CiviCRM_API3_Exception */ -function civicrm_api3_order_cancel($params) { +function civicrm_api3_order_cancel(array $params) { $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $params['contribution_status_id'] = array_search('Cancelled', $contributionStatuses); $result = civicrm_api3('Contribution', 'create', $params); @@ -215,7 +218,7 @@ function civicrm_api3_order_cancel($params) { * @param array $params * Array of parameters determined by getfields. */ -function _civicrm_api3_order_cancel_spec(&$params) { +function _civicrm_api3_order_cancel_spec(array &$params) { $params['contribution_id'] = [ 'api.required' => 1, 'title' => 'Contribution ID', @@ -231,7 +234,7 @@ function _civicrm_api3_order_cancel_spec(&$params) { * @param array $params * Array of parameters determined by getfields. */ -function _civicrm_api3_order_create_spec(&$params) { +function _civicrm_api3_order_create_spec(array &$params) { $params['contact_id'] = [ 'name' => 'contact_id', 'title' => 'Contact ID', @@ -271,7 +274,7 @@ function _civicrm_api3_order_create_spec(&$params) { * @param array $params * Array of parameters determined by getfields. */ -function _civicrm_api3_order_delete_spec(&$params) { +function _civicrm_api3_order_delete_spec(array &$params) { $params['contribution_id'] = [ 'api.required' => TRUE, 'title' => 'Contribution ID', diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index db1d80e842..5e6f051642 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -142,9 +142,12 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { * * @param string $thousandSeparator * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + * @throws \Civi\Payment\Exception\PaymentProcessorException * @dataProvider getThousandSeparators */ - public function testSubmit($thousandSeparator) { + public function testSubmit(string $thousandSeparator): void { $this->setCurrencySeparators($thousandSeparator); $form = new CRM_Contribute_Form_Contribution(); $form->testSubmit([ @@ -162,8 +165,11 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { /** * Test the submit function on the contribution page. + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ - public function testSubmitCreditCard() { + public function testSubmitCreditCard(): void { $form = new CRM_Contribute_Form_Contribution(); $form->testSubmit([ 'total_amount' => 50, @@ -180,8 +186,11 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { /** * Test the submit function on the contribution page. + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ - public function testSubmitCreditCardPayPal() { + public function testSubmitCreditCardPayPal(): void { $mut = new CiviMailUtils($this, TRUE); $mut->clearMessages(); $form = new CRM_Contribute_Form_Contribution(); @@ -236,8 +245,8 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { ]), ]); - $this->assertEquals(1, $contribution["count"], "Contribution count should be one."); - $this->assertTrue(!empty($contribution["values"][$contribution["id"]]["receipt_date"]), "Receipt date should not be blank."); + $this->assertEquals(1, $contribution['count'], 'Contribution count should be one.'); + $this->assertNotTrue(empty($contribution['values'][$contribution['id']]['receipt_date']), 'Receipt date should not be blank.'); $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $this->_individualId]); $this->assertTrue(empty($contact['source'])); @@ -251,6 +260,8 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { /** * Test the submit function on the contribution page + * + * @throws \CRM_Core_Exception */ public function testSubmitCreditCardWithEmailReceipt() { $mut = new CiviMailUtils($this, TRUE); @@ -909,7 +920,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 * * @dataProvider getThousandSeparators */ - public function testSubmitUpdate($thousandSeparator) { + public function testSubmitUpdate(string $thousandSeparator): void { $this->setCurrencySeparators($thousandSeparator); $form = new CRM_Contribute_Form_Contribution(); diff --git a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php index 072929ea7c..662b1e5ec5 100644 --- a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php @@ -60,6 +60,8 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { /** * Setup function. + * + * @throws \CRM_Core_Exception */ public function setUp(): void { parent::setUp(); @@ -199,7 +201,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { /** * Test the LoadObjects function with recurring membership data. */ - public function testSendMailParticipantObjectsCheckLog() { + public function testSendMailParticipantObjectsCheckLog(): void { $this->_setUpParticipantObjects(); $mut = new CiviMailUtils($this, TRUE); $this->callAPISuccess('Contribution', 'sendconfirmation', [ @@ -215,8 +217,11 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { /** * Test the LoadObjects function with recurring membership data. + * + * @throws \CRM_Core_Exception + * @throws \Exception */ - public function testsendMailParticipantObjectsNoMail() { + public function testsendMailParticipantObjectsNoMail(): void { $this->_setUpParticipantObjects(); $event = new CRM_Event_BAO_Event(); $event->id = $this->_eventId; @@ -238,7 +243,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { /** * Test the LoadObjects function with a pledge. */ - public function testSendMailPledge() { + public function testSendMailPledge(): void { $this->_setUpPledgeObjects(); $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $this->_contributionId; @@ -246,7 +251,13 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->assertStringContainsString('Contribution Information', $msg['html']); } - public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() { + /** + * @throws \API_Exception + * @throws \CRM_Core_Exception + * @throws \Civi\API\Exception\UnauthorizedException + * @throws \CiviCRM_API3_Exception + */ + public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities(): void { $this->_setUpParticipantObjects('Pending from incomplete transaction'); $additionalParticipantId = $this->participantCreate([ 'event_id' => $this->_eventId, @@ -259,7 +270,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { 'contribution_status_id:name' => 'Cancelled', ])->addWhere('id', '=', $this->_contributionId)->execute(); - $cancelledParticipantsCount = civicrm_api3('Participant', 'get', [ + $cancelledParticipantsCount = $this->callAPISuccess('Participant', 'get', [ 'sequential' => 1, 'id' => ['IN' => [$this->_participantId, $additionalParticipantId]], 'status_id' => 'Cancelled', @@ -355,7 +366,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { /** * Prepare for membership test. */ - public function _setUpMembershipObjects() { + public function _setUpMembershipObjects(): void { try { if (!$this->_membershipTypeID) { $this->_membershipTypeID = $this->membershipTypeCreate(); -- 2.25.1