|
4 | 4 |
|
5 | 5 | namespace Temporal\Tests\Unit\Framework; |
6 | 6 |
|
7 | | -use Closure; |
8 | 7 | use PHPUnit\Framework\Exception; |
9 | 8 | use React\Promise\PromiseInterface; |
10 | 9 | use Temporal\Common\Uuid; |
11 | 10 | use Temporal\Interceptor\PipelineProvider; |
12 | 11 | use Temporal\Interceptor\SimplePipelineProvider; |
13 | 12 | use Temporal\Internal\Declaration\Prototype\ActivityPrototype; |
14 | 13 | use Temporal\Internal\Queue\QueueInterface; |
15 | | -use Temporal\Internal\Repository\Identifiable; |
16 | 14 | use Temporal\Internal\ServiceContainer; |
17 | 15 | use Temporal\Internal\Transport\Router; |
18 | 16 | use Temporal\Internal\Transport\RouterInterface; |
|
28 | 26 | use Temporal\Worker\Transport\Goridge; |
29 | 27 | use Temporal\Worker\WorkerInterface; |
30 | 28 | use Temporal\Worker\WorkerOptions; |
31 | | -use Throwable; |
32 | 29 |
|
33 | 30 | /** |
34 | 31 | * @internal |
@@ -61,25 +58,14 @@ public function __construct( |
61 | 58 | $this->server = new ServerMock(CommandHandlerFactory::create()); |
62 | 59 | } |
63 | 60 |
|
64 | | - private function createRouter(): RouterInterface |
65 | | - { |
66 | | - $router = new Router(); |
67 | | - $router->add(new Router\StartWorkflow($this->services)); |
68 | | - $router->add(new Router\InvokeActivity($this->services, Goridge::create(), $this->interceptorProvider)); |
69 | | - $router->add(new Router\DestroyWorkflow($this->services->running, $this->services->loop)); |
70 | | - $router->add(new Router\InvokeSignal($this->services->running)); |
71 | | - |
72 | | - return $router; |
73 | | - } |
74 | | - |
75 | 61 | public function runWorkflow(string $workflowCLass, ...$args): void |
76 | 62 | { |
77 | 63 | $runId = Uuid::v4(); |
78 | 64 | $this->execution[$workflowCLass] = $runId; |
79 | 65 | $this->server->addCommand(new StartWorkflow($runId, $workflowCLass, ...$args)); |
80 | 66 | } |
81 | 67 |
|
82 | | - public function sendSignal(string $workflow, string $name, ...$args): void |
| 68 | + public function sendSignal(string $workflow, string $name, mixed ...$args): void |
83 | 69 | { |
84 | 70 | $workflowRunId = $this->execution[$workflow] ?? null; |
85 | 71 | if ($workflowRunId === null) { |
@@ -109,9 +95,9 @@ public function send(QueueInterface $commands): void |
109 | 95 | } |
110 | 96 |
|
111 | 97 | /** |
112 | | - * @throws Throwable |
| 98 | + * @throws \Throwable |
113 | 99 | */ |
114 | | - public function error(Throwable $error): void |
| 100 | + public function error(\Throwable $error): void |
115 | 101 | { |
116 | 102 | if ($error instanceof Exception) { |
117 | 103 | throw $error; |
@@ -154,14 +140,13 @@ public function getWorkflows(): iterable |
154 | 140 | public function registerActivityImplementations(object ...$activity): WorkerInterface |
155 | 141 | { |
156 | 142 | foreach ($activity as $act) { |
157 | | - $this->registerActivity(\get_class($act), fn() => $act); |
| 143 | + $this->registerActivity(\get_class($act), static fn() => $act); |
158 | 144 | } |
159 | 145 |
|
160 | 146 | return $this; |
161 | 147 | } |
162 | 148 |
|
163 | | - |
164 | | - public function registerActivity(string $type, callable $factory = null): WorkerInterface |
| 149 | + public function registerActivity(string $type, ?callable $factory = null): WorkerInterface |
165 | 150 | { |
166 | 151 | foreach ($this->services->activitiesReader->fromClass($type) as $proto) { |
167 | 152 | /** @var ActivityPrototype $proto */ |
@@ -205,10 +190,21 @@ public function complete(): void |
205 | 190 | $this->execution = []; |
206 | 191 | } |
207 | 192 |
|
208 | | - public function registerActivityFinalizer(Closure $finalizer): WorkerInterface |
| 193 | + public function registerActivityFinalizer(\Closure $finalizer): WorkerInterface |
209 | 194 | { |
210 | 195 | $this->services->activities->addFinalizer($finalizer); |
211 | 196 |
|
212 | 197 | return $this; |
213 | 198 | } |
| 199 | + |
| 200 | + private function createRouter(): RouterInterface |
| 201 | + { |
| 202 | + $router = new Router(); |
| 203 | + $router->add(new Router\StartWorkflow($this->services)); |
| 204 | + $router->add(new Router\InvokeActivity($this->services, Goridge::create(), $this->interceptorProvider)); |
| 205 | + $router->add(new Router\DestroyWorkflow($this->services->running, $this->services->loop)); |
| 206 | + $router->add(new Router\InvokeSignal($this->services->running)); |
| 207 | + |
| 208 | + return $router; |
| 209 | + } |
214 | 210 | } |
0 commit comments