From 45a4c6ea449e969924e41c0eb9636d92e547aaad Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 23 Nov 2022 14:17:11 -0800 Subject: [PATCH] Mixin LifecycleTest - Add phpCall() helper This is similar to the existing phpEval() helper, but it only calls one function, and it handles escaping the params. Tangentially, relax the return type for `phpEval()` - since it's equally valid to return scalars. --- .../tests/phpunit/E2E/Shimmy/LifecycleTest.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/extensions/shimmy/tests/phpunit/E2E/Shimmy/LifecycleTest.php b/tests/extensions/shimmy/tests/phpunit/E2E/Shimmy/LifecycleTest.php index d823af8c32..f80850e265 100644 --- a/tests/extensions/shimmy/tests/phpunit/E2E/Shimmy/LifecycleTest.php +++ b/tests/extensions/shimmy/tests/phpunit/E2E/Shimmy/LifecycleTest.php @@ -109,7 +109,11 @@ class E2E_Shimmy_LifecycleTest extends \PHPUnit\Framework\TestCase implements \C return (array) civicrm_api4($entity, $action, $params); } - public function phpEval(string $expr): array { + public function phpCall($func, array $args = []) { + return call_user_func_array($func, $args); + } + + public function phpEval(string $expr) { // phpcs:ignore return eval($expr); } @@ -129,7 +133,11 @@ class E2E_Shimmy_LifecycleTest extends \PHPUnit\Framework\TestCase implements \C return $this->cv('api4 --in=json ' . escapeshellarg("$entity.$action"), json_encode($params)); } - public function phpEval(string $expr): array { + public function phpCall($func, array $args = []) { + return $this->phpEval(sprintf('return call_user_func_array(%s, %s);', var_export($func, 1), var_export($args, 1))); + } + + public function phpEval(string $expr) { return $this->cv('php:eval ' . escapeshellarg($expr)); } -- 2.25.1