Mitigate flaky test failure about "CRM_Utils_Check_Component_Env->checkVersion()"
authorTim Otten <totten@civicrm.org>
Thu, 9 Apr 2020 04:20:40 +0000 (21:20 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 9 Apr 2020 04:31:41 +0000 (21:31 -0700)
This function relies on an external data feed. If it fails to fetch the feed, then we
wind up with a PHP warning:

```
Invalid argument supplied for foreach() in CRM_Utils_Check_Component_Env->checkVersion()
(line 475 of /home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/CRM/Utils/Check/Component/Env.php).
```

In certain unit-tests, this warning becomes a false-negative test-failure.
I saw these tests failing recently:

```
CRM_Contact_Page_View_UserDashBoardTest.testDashboardContentContributionsWithInvoicingEnabled
CRM_Contact_Page_View_UserDashBoardTest.testDashboardContentContributions
CRM_Core_Page_HookTest.testFormsCallBuildFormOnce
CRM_Core_Page_HookTest.testPagesCallPageRunOnce
```

Note that it is legit to have some QA signals if the web-service fials, but
that's more of a monitoring issue for the web-service.  It shouldn't
manifest in random unit-tests or random page-views.

CRM/Utils/Check/Component/Env.php

index 185ed5f9c2de3654f46acca6ed0b088b6ed44336..63efaddef8261373bb051f18351eec0942afdb0e 100644 (file)
@@ -471,7 +471,7 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
         'warning' => CRM_Utils_Check::severityMap(\Psr\Log\LogLevel::WARNING) ,
         'critical' => CRM_Utils_Check::severityMap(\Psr\Log\LogLevel::CRITICAL),
       ];
-      foreach ($vc->getVersionMessages() as $msg) {
+      foreach ($vc->getVersionMessages() ?? [] as $msg) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__ . '_' . $msg['name'],
           $msg['message'], $msg['title'], $severities[$msg['severity']], 'fa-cloud-upload');
       }