Skip to content

Commit 2b4202b

Browse files
authored
Merge pull request #569: Add default implementation for upsertMemo method in interceptors
2 parents 7489256 + ee29f10 commit 2b4202b

File tree

5 files changed

+116
-19
lines changed

5 files changed

+116
-19
lines changed

src/Interceptor/Trait/WorkflowOutboundCallsInterceptorTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Temporal\Interceptor\WorkflowOutboundCalls\SideEffectInput;
2626
use Temporal\Interceptor\WorkflowOutboundCalls\SignalExternalWorkflowInput;
2727
use Temporal\Interceptor\WorkflowOutboundCalls\TimerInput;
28+
use Temporal\Interceptor\WorkflowOutboundCalls\UpsertMemoInput;
2829
use Temporal\Interceptor\WorkflowOutboundCalls\UpsertSearchAttributesInput;
2930
use Temporal\Interceptor\WorkflowOutboundCalls\UpsertTypedSearchAttributesInput;
3031
use Temporal\Interceptor\WorkflowOutboundCallsInterceptor;
@@ -148,6 +149,16 @@ public function getVersion(GetVersionInput $input, callable $next): PromiseInter
148149
return $next($input);
149150
}
150151

152+
/**
153+
* Default implementation of the `upsertMemo` method.
154+
*
155+
* @see WorkflowOutboundCallsInterceptor::upsertMemo()
156+
*/
157+
public function upsertMemo(UpsertMemoInput $input, callable $next): PromiseInterface
158+
{
159+
return $next($input);
160+
}
161+
151162
/**
152163
* Default implementation of the `upsertSearchAttributes` method.
153164
*

src/Workflow.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -912,34 +912,35 @@ public static function allHandlersFinished(): bool
912912
* For example:
913913
*
914914
* ```php
915-
* Workflow::upsertMemo([
916-
* 'key1' => 'value',
917-
* 'key3' => ['subkey1' => 'value']
918-
* 'key4' => 'value',
919-
* });
920-
*
921-
* Workflow::upsertMemo([
922-
* 'key2' => 'value',
923-
* 'key3' => ['subkey2' => 'value']
924-
* 'key4' => null,
925-
* ]);
915+
* Workflow::upsertMemo([
916+
* 'key1' => 'value',
917+
* 'key3' => ['subkey1' => 'value']
918+
* 'key4' => 'value',
919+
* });
920+
*
921+
* Workflow::upsertMemo([
922+
* 'key2' => 'value',
923+
* 'key3' => ['subkey2' => 'value']
924+
* 'key4' => null,
925+
* ]);
926926
* ```
927927
*
928928
* would result in the Workflow having these Memo:
929929
*
930930
* ```php
931-
* [
932-
* 'key1' => 'value',
933-
* 'key2' => 'value',
934-
* 'key3' => ['subkey2' => 'value'], // Note this object was completely replaced
935-
* // Note that 'key4' was completely removed
936-
* ]
931+
* [
932+
* 'key1' => 'value',
933+
* 'key2' => 'value',
934+
* 'key3' => ['subkey2' => 'value'], // Note this object was completely replaced
935+
* // Note that 'key4' was completely removed
936+
* ]
937937
* ```
938938
*
939939
* @param array<non-empty-string, mixed> $values
940940
*
941941
* @since SDK 2.13.0
942942
* @since RoadRunner 2024.3.3
943+
* @link https://docs.temporal.io/glossary#memo
943944
*/
944945
public static function upsertMemo(array $values): void
945946
{

tests/Acceptance/App/Runtime/RRStarter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ public function stop(): void
6363
$this->environment->stop();
6464
$this->started = false;
6565
}
66+
67+
public function __destruct()
68+
{
69+
$this->stop();
70+
}
6671
}

tests/Acceptance/Extra/Workflow/MemoTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ public function handle()
109109
fn(): bool => $this->exit,
110110
);
111111

112-
tr(Workflow::getInfo()->memo);
113-
114112
return Workflow::getInfo()->memo;
115113
}
116114

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Temporal package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Temporal\Tests\Unit\Interceptor;
13+
14+
use PHPUnit\Framework\Attributes\DataProvider;
15+
use Temporal\DataConverter\DataConverter;
16+
use Temporal\DataConverter\DataConverterInterface;
17+
use Temporal\Interceptor\ActivityInboundInterceptor;
18+
use Temporal\Interceptor\Header;
19+
use Temporal\Interceptor\Trait\ActivityInboundInterceptorTrait;
20+
use Temporal\Interceptor\Trait\WorkflowClientCallsInterceptorTrait;
21+
use Temporal\Interceptor\Trait\WorkflowInboundCallsInterceptorTrait;
22+
use Temporal\Interceptor\Trait\WorkflowOutboundCallsInterceptorTrait;
23+
use Temporal\Interceptor\Trait\WorkflowOutboundRequestInterceptorTrait;
24+
use Temporal\Interceptor\WorkflowClientCallsInterceptor;
25+
use Temporal\Interceptor\WorkflowInboundCallsInterceptor;
26+
use Temporal\Interceptor\WorkflowOutboundCallsInterceptor;
27+
use Temporal\Interceptor\WorkflowOutboundRequestInterceptor;
28+
use Temporal\Tests\Unit\AbstractUnit;
29+
30+
/**
31+
* Check that interceptor traits cover all interfaces methods.
32+
*
33+
* @group unit
34+
* @group interceptor
35+
*/
36+
class TraitsTestCase extends AbstractUnit
37+
{
38+
public function testActivityInboundInterceptor(): void
39+
{
40+
new class implements ActivityInboundInterceptor {
41+
use ActivityInboundInterceptorTrait;
42+
};
43+
44+
self::assertTrue(true);
45+
}
46+
47+
public function testWorkflowClientCallsInterceptor(): void
48+
{
49+
new class implements WorkflowClientCallsInterceptor {
50+
use WorkflowClientCallsInterceptorTrait;
51+
};
52+
53+
self::assertTrue(true);
54+
}
55+
56+
public function testWorkflowInboundCallsInterceptor(): void
57+
{
58+
new class implements WorkflowInboundCallsInterceptor {
59+
use WorkflowInboundCallsInterceptorTrait;
60+
};
61+
62+
self::assertTrue(true);
63+
}
64+
65+
public function testWorkflowOutboundCallsInterceptor(): void
66+
{
67+
new class implements WorkflowOutboundCallsInterceptor {
68+
use WorkflowOutboundCallsInterceptorTrait;
69+
};
70+
71+
self::assertTrue(true);
72+
}
73+
74+
public function testWorkflowOutboundRequestInterceptor(): void
75+
{
76+
new class implements WorkflowOutboundRequestInterceptor {
77+
use WorkflowOutboundRequestInterceptorTrait;
78+
};
79+
80+
self::assertTrue(true);
81+
}
82+
}

0 commit comments

Comments
 (0)