From ebf5dbf6f106ca9b7b6a3ccbe480d65ab1e91826 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 29 Jun 2022 20:54:19 -0700 Subject: [PATCH] WorkflowMessageTest - Fix weird inconsistency in resolving `@dataProvider` We see a failure scenario where: * The first execution of WorkflowMessageTest runs fine. * The second execution of WorkflowMessageTest fails to boot (while evaluating `@dataProvider`) * If you reset the DB, then it works again - but only once. --- .../api/v4/Entity/WorkflowMessageTest.php | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/api/v4/Entity/WorkflowMessageTest.php b/tests/phpunit/api/v4/Entity/WorkflowMessageTest.php index cdb6bd92a5..b8f331f6d5 100644 --- a/tests/phpunit/api/v4/Entity/WorkflowMessageTest.php +++ b/tests/phpunit/api/v4/Entity/WorkflowMessageTest.php @@ -72,21 +72,28 @@ class WorkflowMessageTest extends Api4TestBase implements TransactionalInterface } public function getRenderExamples(): array { - $metas = \Civi\Test::examples()->getMetas(); + // Phpunit resolves data-providers at a moment where bootstrap is awkward. + // Dynamic data-providers should call-out to subprocess which can do full/normal boot. + $uf = getenv('CIVICRM_UF'); + try { + putenv('CIVICRM_UF='); + $metas = cv('api4 ExampleData.get +s name,workflow \'{"where":[["tags","CONTAINS","phpunit"]]}\''); + } + finally { + putenv("CIVICRM_UF={$uf}"); + } + $results = []; - foreach ($metas as $name => $meta) { - if (!empty($meta['data']['workflow'])) { - continue; - } - if (empty($meta['tags']) || !in_array('phpunit', $meta['tags'])) { + foreach ($metas as $meta) { + if (!empty($meta['workflow'])) { continue; } if ($exampleFilter = getenv('WORKFLOW_EXAMPLES')) { - if (!preg_match($exampleFilter, $name)) { + if (!preg_match($exampleFilter, $meta['name'])) { continue; } } - $results[$name] = [$meta['name']]; + $results[$meta['name']] = [$meta['name']]; } return $results; } -- 2.25.1