From 3d2811484b576e78146843dc54b6f0edc6b0afd7 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 5 Apr 2023 11:17:40 +1200 Subject: [PATCH] Strictness cleanups in test class --- Civi/Test/DbTestTrait.php | 12 ++-- .../Civi/FlexMailer/MailingPreviewTest.php | 3 +- tests/phpunit/CRM/Contact/BAO/QueryTest.php | 14 ++--- .../CRM/Contribute/BAO/ContributionTest.php | 24 +++---- .../CRM/Event/Form/ParticipantTest.php | 8 +-- tests/phpunit/CRM/Event/Form/SearchTest.php | 2 +- tests/phpunit/CRM/Price/Form/OptionTest.php | 9 ++- tests/phpunit/CRM/Utils/SQL/DeleteTest.php | 11 ---- tests/phpunit/CRM/Utils/SQL/SelectTest.php | 11 ---- .../CRMTraits/Financial/FinancialACLTrait.php | 2 +- .../CRMTraits/Financial/PriceSetTrait.php | 10 ++- tests/phpunit/CiviTest/CiviUnitTestCase.php | 63 +++++++++++-------- 12 files changed, 80 insertions(+), 89 deletions(-) diff --git a/Civi/Test/DbTestTrait.php b/Civi/Test/DbTestTrait.php index a16239c4a7..700aad2804 100644 --- a/Civi/Test/DbTestTrait.php +++ b/Civi/Test/DbTestTrait.php @@ -25,9 +25,8 @@ trait DbTestTrait { * @param $id * @param $match * @param bool $delete - * @throws \PHPUnit_Framework_AssertionFailedError */ - public function assertDBState($daoName, $id, $match, $delete = FALSE) { + public function assertDBState($daoName, $id, $match, $delete = FALSE): void { if (empty($id)) { // adding this here since developers forget to check for an id // and hence we get the first value in the db @@ -170,14 +169,15 @@ trait DbTestTrait { * Example: $this->assertSql(2, 'select count(*) from foo where foo.bar like "%1"', * array(1 => array("Whiz", "String"))); * - * @param $expected - * @param $query + * @param string|null $expected + * @param string $query * @param array $params * @param string $message * - * @throws \CRM_Core_Exception + * @noinspection PhpUnhandledExceptionInspection + * @noinspection PhpDocMissingThrowsInspection */ - public function assertDBQuery($expected, $query, $params = [], $message = '') { + public function assertDBQuery(?string $expected, string $query, array $params = [], string $message = ''): void { if ($message) { $message .= ': '; } diff --git a/ext/flexmailer/tests/phpunit/Civi/FlexMailer/MailingPreviewTest.php b/ext/flexmailer/tests/phpunit/Civi/FlexMailer/MailingPreviewTest.php index f15d8dffeb..d6c72e15c9 100644 --- a/ext/flexmailer/tests/phpunit/Civi/FlexMailer/MailingPreviewTest.php +++ b/ext/flexmailer/tests/phpunit/Civi/FlexMailer/MailingPreviewTest.php @@ -10,8 +10,7 @@ class MailingPreviewTest extends \CiviUnitTestCase { protected $_groupID; protected $_email; - protected $_apiversion = 3; - protected $_params = array(); + protected $_params = []; protected $_entity = 'Mailing'; protected $_contactID; diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index 427add5ff3..ed34f6a0c4 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -1364,7 +1364,7 @@ civicrm_relationship.is_active = 1 AND * * @return array */ - public function relativeDateFilters() { + public function relativeDateFilters(): array { $dataProvider[] = ['this.year', "WHERE ( contact_a.created_date BETWEEN 'date0' AND 'date1' ) AND (contact_a.is_deleted = 0)"]; $dataProvider[] = ['greater.day', "WHERE ( contact_a.created_date >= 'date0' ) AND (contact_a.is_deleted = 0)"]; $dataProvider[] = ['earlier.week', "WHERE ( contact_a.created_date <= 'date1' ) AND (contact_a.is_deleted = 0)"]; @@ -1382,10 +1382,8 @@ civicrm_relationship.is_active = 1 AND * Donation |NULL | 300.00 |SSF | Donation,Donation | 2 | 200.00,100.00 * Donation |2019-02-13 00:00:00 | 50.00 |SSF | Donation | 1 | 50.00 * Member Dues |2019-02-13 00:00:00 | 50.00 |SSF | Member Dues | 1 | 50.00 - * - * @throws \CRM_Core_Exception */ - protected function createContributionsForSummaryQueryTests() { + protected function createContributionsForSummaryQueryTests(): void { $contactID = $this->individualCreate(); $this->contributionCreate(['contact_id' => $contactID]); $this->contributionCreate([ @@ -1398,15 +1396,15 @@ civicrm_relationship.is_active = 1 AND $this->createContributionWithTwoLineItemsAgainstPriceSet(['contact_id' => $contactID, 'source' => 'SSF'], [ CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'), $eventFeeType, - ]); + ], 'event_fee'); $this->createContributionWithTwoLineItemsAgainstPriceSet(['contact_id' => $contactID, 'source' => 'SSF'], [ CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'), CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'), - ]); + ], 'two_donations'); $this->createContributionWithTwoLineItemsAgainstPriceSet(['contact_id' => $contactID, 'source' => 'SSF', 'financial_type_id' => $eventFeeType], [ CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'), CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'), - ]); + ], 'two_more_donations'); $this->contributionCreate([ 'contact_id' => $contactID, 'total_amount' => 50, @@ -1438,7 +1436,7 @@ civicrm_relationship.is_active = 1 AND * * @throws \CRM_Core_Exception */ - public function testGenericWhereHandling() { + public function testGenericWhereHandling(): void { $query = new CRM_Contact_BAO_Query([['suffix_id', '=', 2, 0]]); $this->assertEquals('contact_a.suffix_id = 2', $query->_where[0][0]); $this->assertEquals('Individual Suffix = Sr.', $query->_qill[0][0]); diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index bd2d5eb9b7..1edc9c8df5 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -746,13 +746,11 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; /** * Test allowUpdateRevenueRecognitionDate. - * - * @throws \CRM_Core_Exception */ - public function testAllowUpdateRevenueRecognitionDate() { - $contactId = $this->individualCreate(); + public function testAllowUpdateRevenueRecognitionDate(): void { + $contactID = $this->individualCreate(); $params = [ - 'contact_id' => $contactId, + 'contact_id' => $contactID, 'receive_date' => '2010-01-20', 'total_amount' => 100, 'financial_type_id' => 4, @@ -764,10 +762,10 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $event = $this->eventCreate(); $params = [ - 'contact_id' => $contactId, + 'contact_id' => $contactID, 'receive_date' => '2010-01-20', 'total_amount' => 300, - 'financial_type_id' => $this->getFinancialTypeId('Event Fee'), + 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Price_BAO_PriceSet', 'financial_type_id', 'Event Fee'), 'contribution_status_id' => 'Pending', ]; $priceFields = $this->createPriceSet('event', $event['id']); @@ -787,7 +785,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $params['line_items'][] = [ 'line_item' => $lineItems, 'params' => [ - 'contact_id' => $contactId, + 'contact_id' => $contactID, 'event_id' => $event['id'], 'status_id' => 1, 'role_id' => 1, @@ -800,14 +798,14 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $this->assertFalse($allowUpdate); $params = [ - 'contact_id' => $contactId, + 'contact_id' => $contactID, 'receive_date' => '2010-01-20', 'total_amount' => 200, 'financial_type_id' => $this->getFinancialTypeId('Member Dues'), 'contribution_status_id' => 'Pending', ]; $membershipType = $this->membershipTypeCreate(); - $priceFields = $this->createPriceSet(); + $priceFields = $this->createPriceSet('contribution_page', NULL, [], 'membership'); $lineItems = []; foreach ($priceFields['values'] as $key => $priceField) { $lineItems[$key] = [ @@ -826,7 +824,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $params['line_items'][] = [ 'line_item' => [array_pop($lineItems)], 'params' => [ - 'contact_id' => $contactId, + 'contact_id' => $contactID, 'membership_type_id' => $membershipType, 'join_date' => '2006-01-21', 'start_date' => '2006-01-21', @@ -843,10 +841,8 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; /** * Test recording of amount with comma separator. - * - * @throws \CRM_Core_Exception */ - public function testCommaSeparatorAmount() { + public function testCommaSeparatorAmount(): void { $contactId = $this->individualCreate(); $params = [ diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index 2bda22c7dd..aaf48369d5 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -54,7 +54,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 0 => [ 13 => [ 'price_field_id' => $this->getPriceFieldID(), - 'price_field_value_id' => $this->_ids['price_field_value'][0], + 'price_field_value_id' => $this->ids['PriceFieldValue']['price_field'], 'label' => 'Tiny-tots (ages 5-8)', 'field_title' => 'Tournament Fees', 'description' => NULL, @@ -81,7 +81,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'role_id' => 1, 'event_id' => $form->_eventId, 'priceSetId' => $this->getPriceSetID('event'), - $this->getPriceFieldKey() => $this->_ids['price_field_value'][0], + $this->getPriceFieldKey() => $this->ids['PriceFieldValue']['price_field'], 'is_pay_later' => 1, 'amount_level' => 'Too much', 'fee_amount' => 55, @@ -212,7 +212,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'line_total' => 1550.55, 'participant_count' => 0, 'price_field_id' => $this->getPriceFieldID(), - 'price_field_value_id' => $this->_ids['price_field_value'][1], + 'price_field_value_id' => $this->ids['PriceFieldValue']['big'], 'tax_amount' => 0, // Interestingly the financial_type_id set in this test is ignored but currently locking in what is happening with this test so setting to 'actual' 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Event Fee'), @@ -768,7 +768,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * @return int */ protected function getPriceFieldValueID(): int { - return (int) $this->_ids['price_field_value'][1]; + return (int) $this->ids['PriceFieldValue']['big']; } /** diff --git a/tests/phpunit/CRM/Event/Form/SearchTest.php b/tests/phpunit/CRM/Event/Form/SearchTest.php index 5155b19d1a..df66707fd5 100644 --- a/tests/phpunit/CRM/Event/Form/SearchTest.php +++ b/tests/phpunit/CRM/Event/Form/SearchTest.php @@ -19,7 +19,7 @@ class CRM_Event_Form_SearchTest extends CiviUnitTestCase { parent::setUp(); $this->individualID = $this->individualCreate(); $event = $this->eventCreate(); - $priceFieldValues = $this->createPriceSet('event', $event, [ + $priceFieldValues = $this->createPriceSet('event', $event['id'], [ 'html_type' => 'Radio', 'option_label' => ['1' => 'Radio Label A (inc. GST)', '2' => 'Radio Label B (inc. GST)'], 'option_name' => ['1' => 'Radio Label A', '2' => 'Radio Label B'], diff --git a/tests/phpunit/CRM/Price/Form/OptionTest.php b/tests/phpunit/CRM/Price/Form/OptionTest.php index 5d8d125afb..830d26be1c 100644 --- a/tests/phpunit/CRM/Price/Form/OptionTest.php +++ b/tests/phpunit/CRM/Price/Form/OptionTest.php @@ -24,7 +24,12 @@ class CRM_Price_Form_OptionTest extends CiviUnitTestCase { ]); } - public function testChangingUniquePublicOptionOnPublicFieldIsNotAllowed() { + public function tearDown(): void { + $this->quickCleanUpFinancialEntities(); + parent::tearDown(); + } + + public function testChangingUniquePublicOptionOnPublicFieldIsNotAllowed(): void { $this->setUpPriceSet([ 'html_type' => 'Select', 'visibility_id' => $this->visibilityOptionsKeys['public'], @@ -51,7 +56,7 @@ class CRM_Price_Form_OptionTest extends CiviUnitTestCase { $this->assertTrue(array_key_exists('visibility_id', $validationResult)); } - public function testAddingPublicOptionToAdminFieldIsNotAllowed() { + public function testAddingPublicOptionToAdminFieldIsNotAllowed(): void { $this->setUpPriceSet([ 'html_type' => 'Select', 'visibility_id' => $this->visibilityOptionsKeys['admin'], diff --git a/tests/phpunit/CRM/Utils/SQL/DeleteTest.php b/tests/phpunit/CRM/Utils/SQL/DeleteTest.php index 852de07973..7935f70a3f 100644 --- a/tests/phpunit/CRM/Utils/SQL/DeleteTest.php +++ b/tests/phpunit/CRM/Utils/SQL/DeleteTest.php @@ -39,15 +39,4 @@ class CRM_Utils_SQL_DeleteTest extends CiviUnitTestCase { $this->assertLike('DELETE FROM foo WHERE (foo IS NULL) AND (nonexistent IS @nonexistent) AND (morenonexistent IS @nonexistent) AND (bar IS "null")', $del->toSQL()); } - /** - * @param $expected - * @param $actual - * @param string $message - */ - public function assertLike($expected, $actual, $message = '') { - $expected = trim((preg_replace('/[ \r\n\t]+/', ' ', $expected))); - $actual = trim((preg_replace('/[ \r\n\t]+/', ' ', $actual))); - $this->assertEquals($expected, $actual, $message); - } - } diff --git a/tests/phpunit/CRM/Utils/SQL/SelectTest.php b/tests/phpunit/CRM/Utils/SQL/SelectTest.php index ab601cc6b7..734371e1df 100644 --- a/tests/phpunit/CRM/Utils/SQL/SelectTest.php +++ b/tests/phpunit/CRM/Utils/SQL/SelectTest.php @@ -364,15 +364,4 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { $this->assertLike('INSERT INTO bar (name, first, second) SELECT foo.name, concat(foo.one, " and on and on"), foo.two FROM foo WHERE (foo.whiz = 100) ON DUPLICATE KEY UPDATE first = concat(foo.one, " and on and on"), second = foo.two', $select->toSQL()); } - /** - * @param $expected - * @param $actual - * @param string $message - */ - public function assertLike($expected, $actual, $message = '') { - $expected = trim((preg_replace('/[ \r\n\t]+/', ' ', $expected))); - $actual = trim((preg_replace('/[ \r\n\t]+/', ' ', $actual))); - $this->assertEquals($expected, $actual, $message); - } - } diff --git a/tests/phpunit/CRMTraits/Financial/FinancialACLTrait.php b/tests/phpunit/CRMTraits/Financial/FinancialACLTrait.php index 28e6647afb..e4e2b86cdb 100644 --- a/tests/phpunit/CRMTraits/Financial/FinancialACLTrait.php +++ b/tests/phpunit/CRMTraits/Financial/FinancialACLTrait.php @@ -82,7 +82,7 @@ trait CRMTraits_Financial_FinancialACLTrait { * @param array $permissions * Array of permissions e.g ['access CiviCRM','access CiviContribute'], */ - protected function setPermissions($permissions) { + protected function setPermissions(array $permissions): void { CRM_Core_Config::singleton()->userPermissionClass->permissions = $permissions; if (isset(\Civi::$statics['CRM_Financial_BAO_FinancialType'])) { unset(\Civi::$statics['CRM_Financial_BAO_FinancialType']); diff --git a/tests/phpunit/CRMTraits/Financial/PriceSetTrait.php b/tests/phpunit/CRMTraits/Financial/PriceSetTrait.php index cd05d168c7..84a0de4ed7 100644 --- a/tests/phpunit/CRMTraits/Financial/PriceSetTrait.php +++ b/tests/phpunit/CRMTraits/Financial/PriceSetTrait.php @@ -36,12 +36,14 @@ trait CRMTraits_Financial_PriceSetTrait { * * This works for quick config pages with only one option. * + * @param int $contributionPageID + * * @return string * * @noinspection PhpUnhandledExceptionInspection * @noinspection PhpDocMissingThrowsInspection */ - protected function getPriceFieldLabelForContributionPage($contributionPageID): string { + protected function getPriceFieldLabelForContributionPage(int $contributionPageID): string { $this->ids['PriceSet']['contribution_page' . $contributionPageID] = (int) PriceSetEntity::get(FALSE) ->addWhere('entity_id', '=', $contributionPageID) ->addWhere('entity_table', '=', 'civicrm_contribution_page') @@ -70,14 +72,16 @@ trait CRMTraits_Financial_PriceSetTrait { * @param $params * @param array $lineItemFinancialTypes * Financial Types, if an override is intended. + * @param string $identifier + * Name to to identify price set. */ - protected function createContributionWithTwoLineItemsAgainstPriceSet($params, array $lineItemFinancialTypes = []): void { + protected function createContributionWithTwoLineItemsAgainstPriceSet($params, array $lineItemFinancialTypes = [], string $identifier = 'Donation'): void { $params = (array) array_merge([ 'total_amount' => 300, 'financial_type_id' => 'Donation', 'contribution_status_id' => 'Pending', ], $params); - $priceFields = $this->createPriceSet('contribution'); + $priceFields = $this->createPriceSet('contribution', NULL, [], $identifier); foreach ($priceFields['values'] as $key => $priceField) { $financialTypeID = (!empty($lineItemFinancialTypes) ? array_shift($lineItemFinancialTypes) : $priceField['financial_type_id']); $params['line_items'][]['line_item'][$key] = [ diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 334a68ff23..0f0eccc25a 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -2470,15 +2470,14 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * @param bool $exists * @param array $apiResult */ - protected function assertAttachmentExistence($exists, $apiResult) { - $fileId = $apiResult['id']; - $this->assertTrue(is_numeric($fileId)); - $this->assertEquals($exists, file_exists($apiResult['values'][$fileId]['path'])); + protected function assertAttachmentExistence(bool $exists, array $apiResult): void { + $this->assertIsNumeric($apiResult['id']); + $this->assertEquals($exists, file_exists($apiResult['values'][$apiResult['id']]['path'])); $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_file WHERE id = %1', [ - 1 => [$fileId, 'Int'], + 1 => [$apiResult['id'], 'Int'], ]); $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_entity_file WHERE id = %1', [ - 1 => [$fileId, 'Int'], + 1 => [$apiResult['id'], 'Int'], ]); } @@ -2489,7 +2488,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * @param string $actualSQL * @param string $message */ - protected function assertLike($expectedSQL, $actualSQL, $message = 'different sql') { + protected function assertLike(string $expectedSQL, string $actualSQL, string $message = 'different sql'): void { $expected = trim((preg_replace('/[ \r\n\t]+/', ' ', $expectedSQL))); $actual = trim((preg_replace('/[ \r\n\t]+/', ' ', $actualSQL))); $this->assertEquals($expected, $actual, $message); @@ -2498,8 +2497,8 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { /** * Create a price set for an event. * - * @param int $feeTotal - * @param int $minAmt + * @param float $feeTotal + * @param float $minAmt * @param string $type * * @param array $options @@ -2507,8 +2506,9 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * @return int * Price Set ID. * @noinspection PhpUnhandledExceptionInspection + * @noinspection PhpDocMissingThrowsInspection */ - protected function eventPriceSetCreate($feeTotal, $minAmt = 0, string $type = 'Text', array $options = [['name' => 'hundred', 'amount' => 100]]): int { + protected function eventPriceSetCreate(float $feeTotal, float $minAmt = 0, string $type = 'Text', array $options = [['name' => 'hundred', 'amount' => 100]]): int { $paramsSet['title'] = 'Price Set'; $paramsSet['name'] = 'price_set'; $paramsSet['is_active'] = FALSE; @@ -2546,12 +2546,10 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { } $priceFieldID = $this->callAPISuccess('PriceField', 'create', $paramsField)['id']; $this->ids['PriceField']['event_' . strtolower($type)] = $priceFieldID; - $this->_ids['price_field'] = [$priceFieldID]; $fieldValues = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceFieldID])['values']; foreach ($fieldValues as $priceFieldValue) { $this->ids['PriceFieldValue'][strtolower($priceFieldValue['name'])] = $priceFieldValue['id']; } - $this->_ids['price_field_value'] = array_keys($fieldValues); return $priceSetID; } @@ -2593,24 +2591,25 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * Create price set that includes one price field with two option values. * * @param string $component - * @param int $componentId + * @param int|null $componentID * @param array $priceFieldOptions + * @param string $identifier * * @return array - the result of API3 PriceFieldValue.get for the new PriceField */ - protected function createPriceSet($component = 'contribution_page', $componentId = NULL, $priceFieldOptions = []) { - $paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 7); - $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']); + protected function createPriceSet(string $component = 'contribution_page', ?int $componentID = NULL, array $priceFieldOptions = [], $identifier = 'price_set_test'): array { + $paramsSet['title'] = 'Price Set' . $identifier; + $paramsSet['name'] = $identifier; $paramsSet['is_active'] = TRUE; $paramsSet['financial_type_id'] = 'Event Fee'; $paramsSet['extends'] = 1; - $priceSet = $this->callAPISuccess('price_set', 'create', $paramsSet); - if ($componentId) { - CRM_Price_BAO_PriceSet::addTo('civicrm_' . $component, $componentId, $priceSet['id']); + $priceSet = $this->callAPISuccess('PriceSet', 'create', $paramsSet); + if ($componentID) { + CRM_Price_BAO_PriceSet::addTo('civicrm_' . $component, $componentID, $priceSet['id']); } $paramsField = array_merge([ 'label' => 'Price Field', - 'name' => CRM_Utils_String::titleToVar('Price Field'), + 'name' => 'Price_Field', 'html_type' => 'CheckBox', 'option_label' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], 'option_value' => ['1' => 100, '2' => 200], @@ -2623,11 +2622,11 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { 'is_active' => ['1' => 1, '2' => 1], 'price_set_id' => $priceSet['id'], 'is_enter_qty' => 1, - 'financial_type_id' => $this->getFinancialTypeId('Event Fee'), + 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Price_BAO_PriceSet', 'financial_type_id', 'Event Fee'), ], $priceFieldOptions); - $priceField = CRM_Price_BAO_PriceField::create($paramsField); - return $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField->id]); + $priceField = $this->callAPISuccess('PriceField', 'create', $paramsField); + return $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField['id']]); } /** @@ -2636,6 +2635,9 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * @param string $templateName * @param string $input * @param string $type + * + * @noinspection PhpUnhandledExceptionInspection + * @noinspection PhpDocMissingThrowsInspection */ protected function swapMessageTemplateForInput(string $templateName, string $input, string $type = 'html'): void { CRM_Core_DAO::executeQuery( @@ -2651,6 +2653,9 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * * @param string $templateName * @param string $type + * + * @noinspection PhpUnhandledExceptionInspection + * @noinspection PhpDocMissingThrowsInspection */ protected function swapMessageTemplateForTestTemplate($templateName = 'contribution_online_receipt', $type = 'html'): void { $testTemplate = file_get_contents(__DIR__ . '/../../templates/message_templates/' . $templateName . '_' . $type . '.tpl'); @@ -2667,8 +2672,11 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * * @param string $templateName * @param string $type + * + * @noinspection PhpUnhandledExceptionInspection + * @noinspection PhpDocMissingThrowsInspection */ - protected function revertTemplateToReservedTemplate($templateName = 'contribution_online_receipt', $type = 'html') { + protected function revertTemplateToReservedTemplate(string $templateName = 'contribution_online_receipt', string $type = 'html'): void { CRM_Core_DAO::executeQuery( "UPDATE civicrm_option_group og LEFT JOIN civicrm_option_value ov ON ov.option_group_id = og.id @@ -2683,8 +2691,11 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { /** * Flush statics relating to financial type. + * + * @noinspection PhpUnhandledExceptionInspection + * @noinspection PhpDocMissingThrowsInspection */ - protected function flushFinancialTypeStatics() { + protected function flushFinancialTypeStatics(): void { if (isset(\Civi::$statics['CRM_Financial_BAO_FinancialType'])) { unset(\Civi::$statics['CRM_Financial_BAO_FinancialType']); } @@ -2704,7 +2715,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * * @param array $permissions */ - protected function setPermissions($permissions) { + protected function setPermissions(array $permissions): void { CRM_Core_Config::singleton()->userPermissionClass->permissions = $permissions; $this->flushFinancialTypeStatics(); } -- 2.25.1