APIv4 - Create necessary fk entities in conformance test
authorColeman Watts <coleman@civicrm.org>
Fri, 18 Feb 2022 01:45:37 +0000 (20:45 -0500)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 18 Feb 2022 21:53:47 +0000 (10:53 +1300)
tests/phpunit/api/v4/Service/TestCreationParameterProvider.php

index 5bdc2ce7cea7e72294a369e651feba99bc4d30c7..4db5a44423563130db98248b020e1cd67c6939b0 100644 (file)
@@ -150,9 +150,12 @@ class TestCreationParameterProvider {
       $params['where'] = [['contact_type', '=', 'Individual']];
     }
     $entityList = civicrm_api4($fkEntity, 'get', $params);
+    // If no existing entities, create one
     if ($entityList->count() < 1) {
-      $msg = sprintf('At least one %s is required in test', $fkEntity);
-      throw new \API_Exception($msg);
+      $entityList = civicrm_api4($fkEntity, 'create', [
+        'checkPermissions' => FALSE,
+        'values' => $this->getRequired($fkEntity),
+      ]);
     }
 
     return $entityList->last()['id'];