Skip to content

Commit a82923d

Browse files
committed
fix(test): inject manager or dispatcher by callable type
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 94af66a commit a82923d

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

tests/php/ControllerIntegration/Workflow/LogProfileFieldChangeOperationTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,29 @@ protected function setUp(): void {
207207
$bootContext->expects($this->any())
208208
->method('injectFn')
209209
->willReturnCallback(function (callable $fn) use ($container, $generalLogger): mixed {
210-
return $fn($this->workflowManager, $container, $generalLogger);
210+
$firstArgument = $this->workflowManager;
211+
$reflection = null;
212+
if (is_array($fn) && isset($fn[0], $fn[1])) {
213+
$reflection = new \ReflectionMethod($fn[0], (string)$fn[1]);
214+
} elseif ($fn instanceof \Closure) {
215+
$reflection = new \ReflectionFunction($fn);
216+
} elseif (is_string($fn)) {
217+
$reflection = new \ReflectionFunction($fn);
218+
}
219+
220+
if ($reflection !== null) {
221+
$parameters = $reflection->getParameters();
222+
if ($parameters !== []) {
223+
$type = $parameters[0]->getType();
224+
if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) {
225+
if (ltrim($type->getName(), '\\') === ltrim(IEventDispatcher::class, '\\')) {
226+
$firstArgument = $this->dispatcher;
227+
}
228+
}
229+
}
230+
}
231+
232+
return $fn($firstArgument, $container, $generalLogger);
211233
});
212234
$workflowApp->boot($bootContext);
213235
}

0 commit comments

Comments
 (0)