Skip to content

Commit 960fcbb

Browse files
committed
Fix unit tests
1 parent e03c92d commit 960fcbb

File tree

6 files changed

+31
-35
lines changed

6 files changed

+31
-35
lines changed

tests/Functional/WorkflowTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,6 @@ public function setUp(): void
436436
*/
437437
private static function getPrivate(object $object, string $key): mixed
438438
{
439-
return (fn (object $value) => $value->{$key} ?? null)->call($object, $object);
439+
return (static fn(object $value) => $value->{$key} ?? null)->call($object, $object);
440440
}
441441
}

tests/Unit/Framework/ClientMock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function reject(CommandInterface $command, \Throwable $reason): void
106106

107107
public function fork(): self
108108
{
109-
return new self($this->queue);
109+
return $this;
110110
}
111111

112112
public function destroy(): void {}

tests/Unit/Framework/Expectation/WorkflowResult.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Temporal\Tests\Unit\Framework\Expectation;
66

7-
use DateTimeImmutable;
87
use Temporal\DataConverter\EncodedValues;
98
use Temporal\Internal\Transport\Request\CompleteWorkflow;
109
use Temporal\Worker\Transport\Command\CommandInterface;
@@ -38,7 +37,7 @@ public function matches(CommandInterface $command): bool
3837

3938
public function run(CommandInterface $command): CommandInterface
4039
{
41-
return new SuccessResponse(EncodedValues::empty(), $command->getID(), new TickInfo(new DateTimeImmutable()));
40+
return new SuccessResponse(EncodedValues::empty(), $command->getID(), new TickInfo(new \DateTimeImmutable()));
4241
}
4342

4443
public function fail(): void

tests/Unit/Framework/Server/ServerMock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getBatch(): CommandBatchMock
4444

4545
public function addCommand(CommandInterface ...$commands): void
4646
{
47-
$this->queue = array_merge($this->queue, $commands);
47+
$this->queue = \array_merge($this->queue, $commands);
4848
}
4949

5050
public function handleCommand(CommandInterface $command): ?CommandInterface

tests/Unit/Framework/WorkerMock.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
namespace Temporal\Tests\Unit\Framework;
66

7-
use Closure;
87
use PHPUnit\Framework\Exception;
98
use React\Promise\PromiseInterface;
109
use Temporal\Common\Uuid;
1110
use Temporal\Interceptor\PipelineProvider;
1211
use Temporal\Interceptor\SimplePipelineProvider;
1312
use Temporal\Internal\Declaration\Prototype\ActivityPrototype;
1413
use Temporal\Internal\Queue\QueueInterface;
15-
use Temporal\Internal\Repository\Identifiable;
1614
use Temporal\Internal\ServiceContainer;
1715
use Temporal\Internal\Transport\Router;
1816
use Temporal\Internal\Transport\RouterInterface;
@@ -28,7 +26,6 @@
2826
use Temporal\Worker\Transport\Goridge;
2927
use Temporal\Worker\WorkerInterface;
3028
use Temporal\Worker\WorkerOptions;
31-
use Throwable;
3229

3330
/**
3431
* @internal
@@ -61,25 +58,14 @@ public function __construct(
6158
$this->server = new ServerMock(CommandHandlerFactory::create());
6259
}
6360

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-
7561
public function runWorkflow(string $workflowCLass, ...$args): void
7662
{
7763
$runId = Uuid::v4();
7864
$this->execution[$workflowCLass] = $runId;
7965
$this->server->addCommand(new StartWorkflow($runId, $workflowCLass, ...$args));
8066
}
8167

82-
public function sendSignal(string $workflow, string $name, ...$args): void
68+
public function sendSignal(string $workflow, string $name, mixed ...$args): void
8369
{
8470
$workflowRunId = $this->execution[$workflow] ?? null;
8571
if ($workflowRunId === null) {
@@ -109,9 +95,9 @@ public function send(QueueInterface $commands): void
10995
}
11096

11197
/**
112-
* @throws Throwable
98+
* @throws \Throwable
11399
*/
114-
public function error(Throwable $error): void
100+
public function error(\Throwable $error): void
115101
{
116102
if ($error instanceof Exception) {
117103
throw $error;
@@ -154,14 +140,13 @@ public function getWorkflows(): iterable
154140
public function registerActivityImplementations(object ...$activity): WorkerInterface
155141
{
156142
foreach ($activity as $act) {
157-
$this->registerActivity(\get_class($act), fn() => $act);
143+
$this->registerActivity(\get_class($act), static fn() => $act);
158144
}
159145

160146
return $this;
161147
}
162148

163-
164-
public function registerActivity(string $type, callable $factory = null): WorkerInterface
149+
public function registerActivity(string $type, ?callable $factory = null): WorkerInterface
165150
{
166151
foreach ($this->services->activitiesReader->fromClass($type) as $proto) {
167152
/** @var ActivityPrototype $proto */
@@ -205,10 +190,21 @@ public function complete(): void
205190
$this->execution = [];
206191
}
207192

208-
public function registerActivityFinalizer(Closure $finalizer): WorkerInterface
193+
public function registerActivityFinalizer(\Closure $finalizer): WorkerInterface
209194
{
210195
$this->services->activities->addFinalizer($finalizer);
211196

212197
return $this;
213198
}
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+
}
214210
}

tests/Unit/WorkflowContext/GetVersionTestCase.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@
1515
final class GetVersionTestCase extends AbstractUnit
1616
{
1717
private WorkerFactoryInterface $factory;
18+
1819
/** @var WorkerMock|WorkerInterface */
1920
private $worker;
2021

21-
protected function setUp(): void
22-
{
23-
$this->factory = WorkerFactoryMock::create();
24-
$this->worker = $this->factory->newWorker();
25-
26-
parent::setUp();
27-
}
28-
2922
public function testVersionIsRetrieved(): void
3023
{
3124
// We don't have native PHPUnit assertions in this scenario
@@ -50,11 +43,19 @@ public function handler(): iterable
5043

5144
return 'ERROR';
5245
}
53-
}
46+
},
5447
);
5548

5649
$this->worker->runWorkflow('VersionWorkflow');
5750
$this->worker->assertWorkflowReturns('OK');
5851
$this->factory->run($this->worker);
5952
}
53+
54+
protected function setUp(): void
55+
{
56+
$this->factory = WorkerFactoryMock::create();
57+
$this->worker = $this->factory->newWorker();
58+
59+
parent::setUp();
60+
}
6061
}

0 commit comments

Comments
 (0)