From 4ba2b939eecc3e29b191f9079f7a972847ababfd Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 25 Jan 2023 11:24:52 +1300 Subject: [PATCH] Clarify function signature It was doing both pass-by-ref and return to give back the value - this settles on using return. --- Civi/Test/Api4TestTrait.php | 10 ++++------ tests/phpunit/api/v4/Entity/DomainTest.php | 7 ++++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Civi/Test/Api4TestTrait.php b/Civi/Test/Api4TestTrait.php index eaded65524..fa88143042 100644 --- a/Civi/Test/Api4TestTrait.php +++ b/Civi/Test/Api4TestTrait.php @@ -48,14 +48,12 @@ trait Api4TestTrait { 'defaults' => [], ]; $idField = CoreUtil::getIdFieldName($entityName); - foreach ($saveParams['records'] as &$record) { - $record += $saveParams['defaults']; + foreach ($saveParams['records'] as $index => $record) { + $saveParams['records'][$index] += $saveParams['defaults']; if (empty($record[$idField])) { - $this->getRequiredValuesToCreate($entityName, $record); + $saveParams['records'][$index] = $this->getRequiredValuesToCreate($entityName, $saveParams['records'][$index]); } } - // Unset for clarity as it leaks from the foreach & is a reference. - unset($record); $saved = civicrm_api4($entityName, 'save', $saveParams); foreach ($saved as $item) { $this->testRecords[] = [$entityName, [[$idField, '=', $item[$idField]]]]; @@ -81,7 +79,7 @@ trait Api4TestTrait { * @return array * @throws \CRM_Core_Exception */ - public function getRequiredValuesToCreate(string $entity, array &$values = []): array { + public function getRequiredValuesToCreate(string $entity, array $values = []): array { $requiredFields = civicrm_api4($entity, 'getfields', [ 'action' => 'create', 'loadOptions' => TRUE, diff --git a/tests/phpunit/api/v4/Entity/DomainTest.php b/tests/phpunit/api/v4/Entity/DomainTest.php index 951209184e..40c919910b 100644 --- a/tests/phpunit/api/v4/Entity/DomainTest.php +++ b/tests/phpunit/api/v4/Entity/DomainTest.php @@ -28,7 +28,12 @@ use Civi\Test\TransactionalInterface; */ class DomainTest extends Api4TestBase implements TransactionalInterface { - public function testActiveDomain() { + /** + * Test active domain and domain_id.name parameters. + * + * @throws \CRM_Core_Exception + */ + public function testActiveDomain(): void { Domain::create(FALSE) ->addValue('name', 'Not current') ->addValue('version', \CRM_Utils_System::version()) -- 2.25.1