From 059b13a1a3a5b4f8559a22ebac1d4e1911489b19 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Mon, 15 Feb 2021 17:45:21 -0500 Subject: [PATCH] compare nonexistent array keys to 0 better --- tests/phpunit/CRM/Case/BAO/CaseTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/CRM/Case/BAO/CaseTest.php b/tests/phpunit/CRM/Case/BAO/CaseTest.php index 5152570706..162738c171 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTest.php @@ -104,7 +104,16 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { $caseRoles = CRM_Case_BAO_Case::getCaseRoles($loggedInUser, $caseId); $this->assertEquals($caseCount, $upcomingCases, 'Upcoming case count must be ' . $caseCount); - $this->assertEquals($caseCount, $summary['rows']['Housing Support']['Ongoing']['count'], 'Housing Support Ongoing case summary must be ' . $caseCount); + if ($caseCount === 0) { + // If there really are 0 cases then there won't be any subelements for + // status and count, so we get a false error if we use the assertEquals + // check since it tries to get a subelement on type int. In this case + // the summary rows are just the case type pseudoconstant list. + $this->assertSame(array_flip(CRM_Case_PseudoConstant::caseType()), $summary['rows']); + } + else { + $this->assertEquals($caseCount, $summary['rows']['Housing Support']['Ongoing']['count'], 'Housing Support Ongoing case summary must be ' . $caseCount); + } $this->assertEquals($caseCount, count($caseRoles), 'Total case roles for logged in users must be ' . $caseCount); } -- 2.25.1