From 849ac823ccb6306373062c9592925a0f5bcc34b3 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 17 Mar 2020 16:24:50 +1300 Subject: [PATCH] [REF] Replace CRM_Utils_Array::value with ?? in variable assignments Partial of #16768 - only contains test lines which I don't think need individual review --- tests/phpunit/CRM/Contact/BAO/ContactTest.php | 2 +- tests/phpunit/CRM/Core/BAO/AddressTest.php | 4 ++-- tests/phpunit/CRM/Core/Page/AJAXTest.php | 2 +- tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php | 4 ++-- tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php | 8 ++++---- tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php | 4 ++-- tests/phpunit/CiviTest/CiviTestSMSProvider.php | 2 +- tests/phpunit/CiviTest/CiviUnitTestCase.php | 6 +++--- tests/phpunit/api/v3/ContributionPageTest.php | 4 ++-- tests/phpunit/api/v3/MembershipTypeTest.php | 8 ++++---- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/phpunit/CRM/Contact/BAO/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactTest.php index 77e6020f6a..f5b75760fa 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactTest.php @@ -611,7 +611,7 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase { $this->assertEquals(1, $values['noteTotalCount'], 'Check for total note count'); foreach ($values['note'] as $key => $val) { - $retrieveNote = CRM_Utils_Array::value('note', $val); + $retrieveNote = $val['note'] ?? NULL; //check the note value $this->assertEquals($params['note'], $retrieveNote, 'Check for note'); } diff --git a/tests/phpunit/CRM/Core/BAO/AddressTest.php b/tests/phpunit/CRM/Core/BAO/AddressTest.php index 6509776640..b8264bbb7d 100644 --- a/tests/phpunit/CRM/Core/BAO/AddressTest.php +++ b/tests/phpunit/CRM/Core/BAO/AddressTest.php @@ -312,14 +312,14 @@ class CRM_Core_BAO_AddressTest extends CiviUnitTestCase { $result = civicrm_api3('Address', 'create', $params); $value = array_pop($result['values']); - $street_number = CRM_Utils_Array::value('street_number', $value); + $street_number = $value['street_number'] ?? NULL; $this->assertEquals($street_number, '54'); // Ensure street parsing does not happen if disabled. $this->setStreetAddressParsing(FALSE); $result = civicrm_api3('Address', 'create', $params); $value = array_pop($result['values']); - $street_number = CRM_Utils_Array::value('street_number', $value); + $street_number = $value['street_number'] ?? NULL; $this->assertEmpty($street_number); } diff --git a/tests/phpunit/CRM/Core/Page/AJAXTest.php b/tests/phpunit/CRM/Core/Page/AJAXTest.php index 330f0daa9e..6855a6dbf9 100644 --- a/tests/phpunit/CRM/Core/Page/AJAXTest.php +++ b/tests/phpunit/CRM/Core/Page/AJAXTest.php @@ -49,7 +49,7 @@ class CRM_Core_Page_AJAXTest extends CiviUnitTestCase { foreach ($cases as $case) { list ($type, $className, $expectedResult) = $case; - $methodName = CRM_Utils_Array::value(3, $case); + $methodName = $case[3] ?? NULL; $actualResult = CRM_Core_Page_AJAX::checkAuthz($type, $className, $methodName); if ($methodName) { $this->assertEquals($expectedResult, $actualResult, diff --git a/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php b/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php index 6d8aa14921..b5dcf0133a 100644 --- a/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php @@ -75,8 +75,8 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { // -- processing priceSet using the BAO $lineItems = []; $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, FALSE); - $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); - $feeBlock = CRM_Utils_Array::value('fields', $priceSet); + $priceSet = $priceSet[$priceSetId] ?? NULL; + $feeBlock = $priceSet['fields'] ?? NULL; $params['price_2'] = $feeTotal; $tempParams = $params; diff --git a/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php b/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php index 50311c0166..894ea803dd 100644 --- a/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php +++ b/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php @@ -71,8 +71,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { $this->_priceSetID = $this->priceSetCreate(); CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $this->_priceSetID); $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($this->_priceSetID, TRUE, FALSE); - $priceSet = CRM_Utils_Array::value($this->_priceSetID, $priceSet); - $this->_feeBlock = CRM_Utils_Array::value('fields', $priceSet); + $priceSet = $priceSet[$this->_priceSetID] ?? NULL; + $this->_feeBlock = $priceSet['fields'] ?? NULL; } /** @@ -376,8 +376,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { $this->_priceSetID = $this->priceSetCreate('Text'); CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $this->_priceSetID); $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($this->_priceSetID, TRUE, FALSE); - $priceSet = CRM_Utils_Array::value($this->_priceSetID, $priceSet); - $this->_feeBlock = CRM_Utils_Array::value('fields', $priceSet); + $priceSet = $priceSet[$this->_priceSetID] ?? NULL; + $this->_feeBlock = $priceSet['fields'] ?? NULL; $params = [ 'send_receipt' => 1, diff --git a/tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php index cbe95e1db8..ab848b8651 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php @@ -348,7 +348,7 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'limit' => 0, ], ]); - $result = CRM_Utils_Array::value('values', $membershipTypesResult, NULL); + $result = $membershipTypesResult['values'] ?? NULL; $this->assertEquals(empty($result), FALSE, 'Verify membership types for organization.'); $membershipTypesResult = civicrm_api3('MembershipType', 'get', [ @@ -357,7 +357,7 @@ class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { 'limit' => 0, ], ]); - $result = CRM_Utils_Array::value('values', $membershipTypesResult, NULL); + $result = $membershipTypesResult['values'] ?? NULL; $this->assertEquals(empty($result), TRUE, 'Verify membership types for organization.'); $this->membershipTypeDelete(['id' => $membershipType->id]); diff --git a/tests/phpunit/CiviTest/CiviTestSMSProvider.php b/tests/phpunit/CiviTest/CiviTestSMSProvider.php index e687ac411b..db73e2a5ad 100644 --- a/tests/phpunit/CiviTest/CiviTestSMSProvider.php +++ b/tests/phpunit/CiviTest/CiviTestSMSProvider.php @@ -28,7 +28,7 @@ class CiviTestSMSProvider extends CRM_SMS_Provider { $providerID = $provider['id']; } else { - $providerID = CRM_Utils_Array::value('provider_id', $providerParams); + $providerID = $providerParams['provider_id'] ?? NULL; } $skipAuth = $providerID ? FALSE : TRUE; $cacheKey = (int) $providerID; diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 173c06e6e1..74e1675b7f 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -1064,8 +1064,8 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { $this->priceSetID = $this->ids['PriceSet'][] = $this->eventPriceSetCreate(55, 0, 'Radio', $options); CRM_Price_BAO_PriceSet::addTo('civicrm_event', $event['id'], $this->priceSetID); $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($this->priceSetID, TRUE, FALSE); - $priceSet = CRM_Utils_Array::value($this->priceSetID, $priceSet); - $this->eventFeeBlock = CRM_Utils_Array::value('fields', $priceSet); + $priceSet = $priceSet[$this->priceSetID] ?? NULL; + $this->eventFeeBlock = $priceSet['fields'] ?? NULL; return $event; } @@ -1927,7 +1927,7 @@ VALUES else { $keys[CRM_Utils_Array::value('name', $settings, $field)] = CRM_Utils_Array::value('name', $settings, $field); } - $type = CRM_Utils_Array::value('type', $settings); + $type = $settings['type'] ?? NULL; if ($type == CRM_Utils_Type::T_DATE) { $dateFields[] = $settings['name']; // we should identify both real names & unique names as dates diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index b35c227b0c..5d4b4a8a10 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -2049,8 +2049,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ public function hook_civicrm_alterPaymentProcessorParams($paymentObj, &$rawParams, &$cookedParams) { // Ensure total_amount are the same if they're both given. - $total_amount = CRM_Utils_Array::value('total_amount', $rawParams); - $amount = CRM_Utils_Array::value('amount', $rawParams); + $total_amount = $rawParams['total_amount'] ?? NULL; + $amount = $rawParams['amount'] ?? NULL; if (!empty($total_amount) && !empty($amount) && $total_amount != $amount) { throw new Exception("total_amount '$total_amount' and amount '$amount' differ."); } diff --git a/tests/phpunit/api/v3/MembershipTypeTest.php b/tests/phpunit/api/v3/MembershipTypeTest.php index bf78045c55..328e8cf2a7 100644 --- a/tests/phpunit/api/v3/MembershipTypeTest.php +++ b/tests/phpunit/api/v3/MembershipTypeTest.php @@ -286,11 +286,11 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { foreach ($memType as $rowCount => $type) { $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($type); $fieldParams['option_id'] = [1 => $priceFieldValue['id']]; - $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype); + $fieldParams['option_label'][$rowCount] = $membetype['name'] ?? NULL; $fieldParams['option_amount'][$rowCount] = $membetype['minimum_fee'] ?? 0; - $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype); - $fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype); - $fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype); + $fieldParams['option_weight'][$rowCount] = $membetype['weight'] ?? NULL; + $fieldParams['option_description'][$rowCount] = $membetype['description'] ?? NULL; + $fieldParams['option_financial_type_id'][$rowCount] = $membetype['financial_type_id'] ?? NULL; $fieldParams['membership_type_id'][$rowCount] = $type; } $priceField = CRM_Price_BAO_PriceField::create($fieldParams); -- 2.25.1