From 52b4f292fd8b8d7e702fc49bdebbeb8a9bb8ed62 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 15 Sep 2021 02:02:05 -0700 Subject: [PATCH] Civi\Test::example() - Make it a bit easier for the typical case This changes the signature on a new helper method. This method is not widely used, and each reference is updated here. Before: `Civi\Test::example($name)` returns the *metadata* for the example. After: `Civi\Test::example($name)` returns the *data* for the example. Comment: It's more convenient to stitch together examples from the data. Of course, metadata may also be useful -- it's still available through `Civi\Test::examples()->getFoo(...)` (with a few different `getFoo()` methods). --- Civi/Test.php | 11 +++++++++-- .../CaseActivity/CaseAdhocExample.ex.php | 2 +- .../CaseActivity/CaseModelExample.ex.php | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Civi/Test.php b/Civi/Test.php index ff49854423..1509481623 100644 --- a/Civi/Test.php +++ b/Civi/Test.php @@ -193,16 +193,23 @@ class Test { } /** + * Lookup the content of an example data-set. + * + * This helper is for the common case of looking up the data for a specific example. + * If you need more detailed information (eg the list of examples or other metadata), + * then use `\Civi\Test::examples(): ExampleDataLoader`. It provides more methods. + * * @param string $name * Symbolic name of the data-set. * @return array + * The example data. */ public static function example(string $name): array { $result = static::examples()->getFull($name); - if ($result === NULL) { + if (!isset($result['data'])) { throw new \CRM_Core_Exception("Failed to load example data-set: $name"); } - return $result; + return $result['data']; } /** diff --git a/tests/phpunit/CRM/Case/WorkflowMessage/CaseActivity/CaseAdhocExample.ex.php b/tests/phpunit/CRM/Case/WorkflowMessage/CaseActivity/CaseAdhocExample.ex.php index cfee7653c8..fefd6868a9 100644 --- a/tests/phpunit/CRM/Case/WorkflowMessage/CaseActivity/CaseAdhocExample.ex.php +++ b/tests/phpunit/CRM/Case/WorkflowMessage/CaseActivity/CaseAdhocExample.ex.php @@ -21,7 +21,7 @@ class CRM_Case_WorkflowMessage_CaseActivity_CaseAdhocExample extends \Civi\Workf */ public function build(array &$example): void { $alex = \Civi\Test::example('workflow/generic/Alex'); - $contact = $this->extend($alex['data']['modelProps']['contact'], [ + $contact = $this->extend($alex['modelProps']['contact'], [ 'role' => 'myrole', ]); $example['data'] = [ diff --git a/tests/phpunit/CRM/Case/WorkflowMessage/CaseActivity/CaseModelExample.ex.php b/tests/phpunit/CRM/Case/WorkflowMessage/CaseActivity/CaseModelExample.ex.php index d716e63982..a7a9919cc9 100644 --- a/tests/phpunit/CRM/Case/WorkflowMessage/CaseActivity/CaseModelExample.ex.php +++ b/tests/phpunit/CRM/Case/WorkflowMessage/CaseActivity/CaseModelExample.ex.php @@ -20,7 +20,7 @@ class CRM_Case_WorkflowMessage_CaseActivity_CaseModelExample extends \Civi\Workf */ public function build(array &$example): void { $alex = \Civi\Test::example('workflow/generic/Alex'); - $example['data'] = $this->extend($alex['data'], [ + $example['data'] = $this->extend($alex, [ 'workflow' => $this->wfName, 'modelProps' => [ 'contact' => [ -- 2.25.1