[REF] Replace CRM_Utils_Array::value with ?? in variable assignments
authoreileen <emcnaughton@wikimedia.org>
Tue, 17 Mar 2020 03:24:50 +0000 (16:24 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 17 Mar 2020 03:24:50 +0000 (16:24 +1300)
Partial of  #16768 - only contains test lines which I don't think need individual review

tests/phpunit/CRM/Contact/BAO/ContactTest.php
tests/phpunit/CRM/Core/BAO/AddressTest.php
tests/phpunit/CRM/Core/Page/AJAXTest.php
tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php
tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php
tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php
tests/phpunit/CiviTest/CiviTestSMSProvider.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/ContributionPageTest.php
tests/phpunit/api/v3/MembershipTypeTest.php

index 77e6020f6a9631f512b3fe39c79b0c9d3178cffa..f5b75760fadc0081980ff7896f7d5e7f964e2f2b 100644 (file)
@@ -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');
     }
index 6509776640ab128b720030fa20bc94c9c192f154..b8264bbb7dab17364f265dcc71b91231ee2d6853 100644 (file)
@@ -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);
 
   }
index 330f0daa9eb79edb9bef58e83700d253e62c22ce..6855a6dbf9775568f85291d1092c8134c80ca987 100644 (file)
@@ -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,
index 6d8aa149211525c36f1d44720d1d2b58c3cfba46..b5dcf0133a56759a3b6d0bd5e3c9b53f5ad991e0 100644 (file)
@@ -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;
 
index 50311c0166e3190e2df062d8faf48b71a22eae6c..894ea803dd14de13948099e86e3d171df48b6dbb 100644 (file)
@@ -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,
index cbe95e1db8896a6ec1c11c672af6409adaa5ed22..ab848b86512c323264c06dd2dc39412ced58f94d 100644 (file)
@@ -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]);
index e687ac411b8bf8ccf08d145541732cc7e4ff91f4..db73e2a5ad19c83cef5e28ab8e0f163cee6bb5d7 100644 (file)
@@ -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;
index 173c06e6e1ebf239ecc31515661961246b5db6ec..74e1675b7f1ce8a332f80a6ebe157a2675e0bdac 100644 (file)
@@ -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
index b35c227b0c871881fd278e4ada7f627530f1e483..5d4b4a8a10730d8978cd3dcbe033ed567c6a11c0 100644 (file)
@@ -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.");
     }
index bf78045c5589d24e27c0f2f34aef4a038b9d6ca7..328e8cf2a79d398f0e964a56094eea4f522d6441 100644 (file)
@@ -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);