Skip to content

Commit 0a7dda2

Browse files
committed
WorkerMock: register classes only as workflows, skip interfaces
(cherry picked from commit d4ad7db)
1 parent 3ba6fc9 commit 0a7dda2

4 files changed

Lines changed: 15 additions & 22 deletions

File tree

src/Worker/Transport/Codec/CodecInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ interface CodecInterface
2020
{
2121
/**
2222
* @param iterable<CommandInterface> $commands
23+
* @return non-empty-string
24+
*
2325
* @throws ProtocolException
2426
*/
2527
public function encode(iterable $commands): string;
2628

2729
/**
2830
* @return iterable<ServerRequestInterface|ServerResponseInterface>
31+
*
2932
* @throws ProtocolException
3033
*/
3134
public function decode(string $batch, array $headers = []): iterable;

src/Worker/Transport/HostConnectionInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface HostConnectionInterface
2424
public function waitBatch(): ?CommandBatch;
2525

2626
/**
27+
* @param non-empty-string $frame
2728
* @throws TransportException
2829
*/
2930
public function send(string $frame): void;

src/WorkerFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ private function createCodec(): CodecInterface
284284
}
285285
}
286286

287+
/**
288+
* @return non-empty-string The encoded responses to be sent back to the parent process.
289+
*/
287290
private function dispatch(string $messages, array $headers): string
288291
{
289292
$commands = $this->codec->decode($messages, $headers);

tests/Fixtures/WorkerMock.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,14 @@ class WorkerMock implements HostConnectionInterface
2424
{
2525
private WorkerFactoryInterface $factory;
2626

27-
/** @var array */
2827
private array $in;
2928

30-
/** @var array */
3129
private array $out;
3230

33-
/** @var int */
3431
private int $indexIn;
3532

36-
/** @var int */
3733
private int $indexOut;
3834

39-
/** @var bool */
4035
private bool $debug;
4136

4237
private TestCase $testCase;
@@ -55,29 +50,27 @@ public static function createMock(): WorkerMock
5550
return $mock;
5651
}
5752

58-
public function registerWorkflowAndActivities()
53+
public function registerWorkflowAndActivities(): void
5954
{
6055
$taskQueue = $this->factory->newWorker('default');
6156

6257
foreach ($this->getClasses(__DIR__ . '/src/Workflow') as $name) {
63-
$taskQueue->registerWorkflowTypes('Temporal\\Tests\\Workflow\\' . $name);
58+
$class = 'Temporal\\Tests\\Workflow\\' . $name;
59+
if (\class_exists($class)) {
60+
$taskQueue->registerWorkflowTypes($class);
61+
}
6462
}
6563

6664
// register all activity
6765
foreach ($this->getClasses(__DIR__ . '/src/Activity') as $name) {
6866
$class = '\\Temporal\\Tests\\Activity\\' . $name;
6967
if (\class_exists($class)) {
70-
$taskQueue->registerActivityImplementations(new $class);
68+
$taskQueue->registerActivityImplementations(new $class());
7169
}
7270
}
7371
}
7472

75-
/**
76-
* @param TestCase $testCase
77-
* @param array $queue
78-
* @param bool $debug
79-
*/
80-
public function run(TestCase $testCase, array $queue, bool $debug = false)
73+
public function run(TestCase $testCase, array $queue, bool $debug = false): void
8174
{
8275
$this->debug = $debug;
8376

@@ -92,9 +85,6 @@ public function run(TestCase $testCase, array $queue, bool $debug = false)
9285
$this->factory->run($this);
9386
}
9487

95-
/**
96-
* @return CommandBatch|null
97-
*/
9888
public function waitBatch(): ?CommandBatch
9989
{
10090
if (!isset($this->out[$this->indexOut])) {
@@ -110,13 +100,10 @@ public function waitBatch(): ?CommandBatch
110100

111101
return new CommandBatch(
112102
$pair[0],
113-
json_decode($pair[1], true),
103+
\json_decode($pair[1], true),
114104
);
115105
}
116106

117-
/**
118-
* @param string $frame
119-
*/
120107
public function send(string $frame): void
121108
{
122109
$pair = $this->in[$this->indexIn];
@@ -149,7 +136,6 @@ public function send(string $frame): void
149136
}
150137

151138
/**
152-
* @param \Throwable $error
153139
* @throws \Throwable
154140
*/
155141
public function error(\Throwable $error): void

0 commit comments

Comments
 (0)