From a0fb3068f4516824773a5002e1b770e2c5292a19 Mon Sep 17 00:00:00 2001
From: demeritcowboy <demeritcowboy@hotmail.com>
Date: Sat, 4 Sep 2021 10:30:16 -0400
Subject: [PATCH] fix timing issue

---
 tests/phpunit/CRM/Utils/TokenConsistencyTest.php | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php
index edb7ada39f1..cb552fd4776 100644
--- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php
+++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php
@@ -130,19 +130,27 @@ No
    */
   protected function getCaseID(): int {
     if (!isset($this->case)) {
-      $this->case = $this->callAPISuccess('Case', 'create', [
+      $case_id = $this->callAPISuccess('Case', 'create', [
         'case_type_id' => 'housing_support',
         'activity_subject' => 'Case Subject',
         'client_id' => $this->getContactID(),
         'status_id' => 1,
         'subject' => 'Case Subject',
         'start_date' => '2021-07-23 15:39:20',
+        // Note end_date is inconsistent with status Ongoing but for the
+        // purposes of testing tokens is ok. Creating it with status Resolved
+        // then ignores our known fixed end date.
         'end_date' => '2021-07-26 18:07:20',
         'medium_id' => 2,
         'details' => 'case details',
         'activity_details' => 'blah blah',
         'sequential' => 1,
-      ])['values'][0];
+      ])['id'];
+      // Need to retrieve the case again because modified date might be updated a
+      // split-second later than the original return value because of activity
+      // triggers when the timeline is populated. The returned array from create
+      // is determined before that happens.
+      $this->case = $this->callAPISuccess('Case', 'getsingle', ['id' => $case_id]);
     }
     return $this->case['id'];
   }
-- 
GitLab