From 9cec87271d2dbbae93946353bf82858fe3a7c421 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 26 Jul 2021 17:26:00 +1200 Subject: [PATCH] [Test] Opt a couple more classes into validateFinancials --- Civi/Test/ContactTestTrait.php | 2 -- .../phpunit/CRM/Contribute/BAO/ContributionTest.php | 11 ++++++++++- tests/phpunit/CRM/Event/Form/ParticipantTest.php | 13 ++++--------- tests/phpunit/CiviTest/CiviUnitTestCase.php | 1 - tests/phpunit/api/v3/LineItemTest.php | 11 ++++++++++- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Civi/Test/ContactTestTrait.php b/Civi/Test/ContactTestTrait.php index 1073bab350..93e9264320 100644 --- a/Civi/Test/ContactTestTrait.php +++ b/Civi/Test/ContactTestTrait.php @@ -54,8 +54,6 @@ trait ContactTestTrait { * * @return int * id of Organisation created - * - * @throws \CiviCRM_API3_Exception */ public function organizationCreate($params = [], $seq = 0): int { if (!$params) { diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index fd6b55795e..17686476ac 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -20,6 +20,13 @@ class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase { use CRMTraits_Financial_FinancialACLTrait; use CRMTraits_Financial_PriceSetTrait; + /** + * Should financials be checked after the test but before tear down. + * + * @var bool + */ + protected $isValidateFinancialsOnPostAssert = TRUE; + /** * Clean up after tests. */ @@ -666,7 +673,9 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ - public function testAssignProportionalLineItems() { + public function testAssignProportionalLineItems(): void { + // This test doesn't seem to manage financials properly, possibly by design + $this->isValidateFinancialsOnPostAssert = FALSE; $contribution = $this->addParticipantWithContribution(); // Delete existing financial_trxns. This is because we are testing a code flow we // want to deprecate & remove & the test relies on bad data asa starting point. diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index 2d93dffbca..c406b743f6 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -21,18 +21,13 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { parent::setUp(); } + /** - * CHeck that all tests that have created payments have created them with the right financial entities. - * - * Ideally this would be on CiviUnitTestCase but many classes would still fail. Also, it might - * be good if it only ran on tests that created at least one contribution. + * Should financials be checked after the test but before tear down. * - * @throws \CRM_Core_Exception + * @var bool */ - protected function assertPostConditions(): void { - $this->validateAllPayments(); - $this->validateAllContributions(); - } + protected $isValidateFinancialsOnPostAssert = TRUE; /** * Initial test of submit function. diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 5c46e94887..5213f7d437 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -486,7 +486,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * Create default domain contacts for the two domains added during test class. * database population. * - * @throws \CiviCRM_API3_Exception * @throws \API_Exception */ public function createDomainContacts(): void { diff --git a/tests/phpunit/api/v3/LineItemTest.php b/tests/phpunit/api/v3/LineItemTest.php index 9c73b82133..75c34d0787 100644 --- a/tests/phpunit/api/v3/LineItemTest.php +++ b/tests/phpunit/api/v3/LineItemTest.php @@ -19,6 +19,13 @@ class api_v3_LineItemTest extends CiviUnitTestCase { protected $params; protected $_entity = 'line_item'; + /** + * Should financials be checked after the test but before tear down. + * + * @var bool + */ + protected $isValidateFinancialsOnPostAssert = TRUE; + /** * Prepare for test. * @@ -143,7 +150,9 @@ class api_v3_LineItemTest extends CiviUnitTestCase { * * @throws \CRM_Core_Exception */ - public function testDeleteLineItem($version): void { + public function testDeleteLineItem(int $version): void { + // Deleting line items does not leave valid financial data. + $this->isValidateFinancialsOnPostAssert = FALSE; $this->_apiversion = $version; $getParams = [ 'entity_table' => 'civicrm_contribution', -- 2.25.1