Skip to content

Commit 20fc7bb

Browse files
committed
chore: enhanced docs, applied code style adjustments
1 parent c8b5825 commit 20fc7bb

20 files changed

+292
-208
lines changed

resources/client.meta-storm.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,24 @@
2929
argument="0"
3030
>
3131
<collection name="temporal/sdk:workflow-class" argument="0" />
32+
<collection name="temporal/sdk:workflow-type" argument="0" />
3233
<stopCompletion />
3334
</classMethod>
35+
<classMethod
36+
class="\Temporal\Client\Schedule\Action\StartWorkflowAction"
37+
method="new"
38+
argument="0"
39+
>
40+
<collection name="temporal/sdk:workflow-class" />
41+
<collection name="temporal/sdk:workflow-type" argument="0" />
42+
<stopCompletion />
43+
</classMethod>
44+
<classMethod
45+
class="\Temporal\DataConverter\ValuesInterface"
46+
method="getValue"
47+
argument="1"
48+
>
49+
<languageInjection language="InjectablePHP" prefix="/** @var " suffix=" $_ **/" />
50+
</classMethod>
3451
</definitions>
3552
</meta-storm>

tests/.meta-storm.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<meta-storm>
2+
<definitions>
3+
<classConstructor class="\Temporal\Tests\Acceptance\App\Attribute\Stub" argument="0">
4+
<collection name="temporal/sdk:workflow-type" />
5+
</classConstructor>
6+
</definitions>
7+
</meta-storm>

tests/Acceptance/App/Attribute/RetryOptions.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,25 @@ class RetryOptions
2525
* @param int<0, max> $maximumAttempts
2626
*/
2727
public function __construct(
28+
/**
29+
* @see CommonOptions::withInitialInterval()
30+
*/
2831
public ?string $initialInterval = CommonOptions::DEFAULT_INITIAL_INTERVAL,
32+
/**
33+
* @see CommonOptions::withBackoffCoefficient()
34+
*/
2935
public float $backoffCoefficient = CommonOptions::DEFAULT_BACKOFF_COEFFICIENT,
36+
/**
37+
* @see CommonOptions::withMaximumInterval()
38+
*/
3039
public ?string $maximumInterval = CommonOptions::DEFAULT_MAXIMUM_INTERVAL,
40+
/**
41+
* @see CommonOptions::withMaximumAttempts()
42+
*/
3143
public int $maximumAttempts = CommonOptions::DEFAULT_MAXIMUM_ATTEMPTS,
44+
/**
45+
* @see CommonOptions::withNonRetryableExceptions()
46+
*/
3247
public array $nonRetryableExceptions = CommonOptions::DEFAULT_NON_RETRYABLE_EXCEPTIONS,
3348
) {}
3449

tests/Acceptance/App/Attribute/Stub.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,26 @@ final class Stub
2323
*/
2424
public function __construct(
2525
public string $type,
26+
/**
27+
* @see WorkflowOptions::withEagerStart()
28+
*/
2629
public bool $eagerStart = false,
30+
/**
31+
* @see WorkflowOptions::withWorkflowId()
32+
*/
2733
public ?string $workflowId = null,
34+
/**
35+
* @see WorkflowOptions::withWorkflowExecutionTimeout()
36+
*/
2837
public ?string $executionTimeout = null,
2938
public array $args = [],
39+
/**
40+
* @see WorkflowOptions::withMemo()
41+
*/
3042
public array $memo = [],
43+
/**
44+
* @see WorkflowOptions::withRetryOptions()
45+
*/
3146
?RetryOptions $retryOptions = null,
3247
) {
3348
$this->retryOptions = $retryOptions?->toRetryOptions();

tests/Acceptance/Harness/Activity/BasicTest.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,25 @@
1515
use Temporal\Workflow\WorkflowInterface;
1616
use Temporal\Workflow\WorkflowMethod;
1717

18-
/*
19-
20-
# Basic activity
21-
22-
The most basic workflow which just runs an activity and returns its result.
23-
Importantly, without setting a workflow execution timeout.
24-
25-
# Detailed spec
26-
27-
It's important that the workflow execution timeout is not set here, because server will propagate that to all un-set
28-
activity timeouts. We had a bug where TS would crash (after proto changes from gogo to google) because it was expecting
29-
timeouts to be set to zero rather than null.
30-
31-
*/
32-
18+
/**
19+
* # Basic activity
20+
*
21+
* The most basic workflow which just runs an activity and returns its result.
22+
* Importantly, without setting a workflow execution timeout.
23+
*
24+
* # Detailed spec
25+
*
26+
* It's important that the workflow execution timeout is not set here, because server will propagate that to all un-set
27+
* activity timeouts. We had a bug where TS would crash (after proto changes from gogo to google) because it was expecting
28+
* timeouts to be set to zero rather than null.
29+
*/
3330
class BasicTest extends TestCase
3431
{
3532
#[Test]
36-
public static function check(#[Stub('Harness_Activity_Basic')]WorkflowStubInterface $stub): void
37-
{
33+
public static function check(
34+
#[Stub('Harness_Activity_Basic')]
35+
WorkflowStubInterface $stub,
36+
): void {
3837
self::assertSame('echo', $stub->getResult());
3938
}
4039
}

tests/Acceptance/Harness/Activity/CancelTryCancelTest.php

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Temporal\Tests\Acceptance\Harness\Activity\CancelTryCancel;
66

77
use PHPUnit\Framework\Attributes\Test;
8-
use React\Promise\PromiseInterface;
98
use Temporal\Activity;
109
use Temporal\Activity\ActivityInterface;
1110
use Temporal\Activity\ActivityMethod;
@@ -21,41 +20,41 @@
2120
use Temporal\Workflow\WorkflowInterface;
2221
use Temporal\Workflow\WorkflowMethod;
2322

24-
/*
25-
26-
# Activity cancellation - Try Cancel mode
27-
Activities may be cancelled in three different ways, this feature spec covers the
28-
Try Cancel mode.
29-
30-
Each feature workflow in this folder should start an activity and cancel it
31-
using the Try Cancel mode. The implementation should demonstrate that the activity
32-
keeps receives a cancel request after the workflow has issued it, but the workflow
33-
immediately should proceed with the activity result being cancelled.
34-
35-
## Detailed spec
36-
37-
* When the SDK issues the activity cancel request command, server will write an
38-
activity cancel requested event to history
39-
* The workflow immediately resolves the activity with its result being cancelled
40-
* Server will notify the activity cancellation has been requested via a response
41-
to activity heartbeating
42-
* The activity may ignore the cancellation request if it explicitly chooses to
43-
44-
## Feature implementation
45-
46-
* Execute activity that heartbeats and checks cancellation
47-
* If a minute passes without cancellation, send workflow a signal that it timed out
48-
* If cancellation is received, send workflow a signal that it was cancelled
49-
* Cancel activity and confirm cancellation error is returned
50-
* Check in the workflow that the signal sent from the activity is showing it was cancelled
51-
52-
*/
53-
23+
/**
24+
* # Activity cancellation - Try Cancel mode
25+
*
26+
* Activities may be cancelled in three different ways, this feature spec covers the
27+
* Try Cancel mode.
28+
*
29+
* Each feature workflow in this folder should start an activity and cancel it
30+
* using the Try Cancel mode. The implementation should demonstrate that the activity
31+
* keeps receives a cancel request after the workflow has issued it, but the workflow
32+
* immediately should proceed with the activity result being cancelled.
33+
*
34+
* ## Detailed spec
35+
*
36+
* When the SDK issues the activity cancel request command, server will write an
37+
* activity cancel requested event to history
38+
* The workflow immediately resolves the activity with its result being cancelled
39+
* Server will notify the activity cancellation has been requested via a response
40+
* to activity heartbeating
41+
* The activity may ignore the cancellation request if it explicitly chooses to
42+
*
43+
* ## Feature implementation
44+
*
45+
* Execute activity that heartbeats and checks cancellation
46+
* If a minute passes without cancellation, send workflow a signal that it timed out
47+
* If cancellation is received, send workflow a signal that it was cancelled
48+
* Cancel activity and confirm cancellation error is returned
49+
* Check in the workflow that the signal sent from the activity is showing it was cancelled
50+
*/
5451
class CancelTryCancelTest extends TestCase
5552
{
5653
#[Test]
57-
public static function check(#[Stub('Harness_Activity_CancelTryCancel')]WorkflowStubInterface $stub): void
58-
{
54+
public static function check(
55+
#[Stub('Harness_Activity_CancelTryCancel')]
56+
WorkflowStubInterface $stub,
57+
): void {
5958
self::assertSame('cancelled', $stub->getResult(timeout: 10));
6059
}
6160
}
@@ -76,7 +75,7 @@ public function run()
7675
->withHeartbeatTimeout('5 seconds')
7776
# Disable retry
7877
->withRetryOptions(RetryOptions::new()->withMaximumAttempts(1))
79-
->withCancellationType(Activity\ActivityCancellationType::TryCancel)
78+
->withCancellationType(Activity\ActivityCancellationType::TryCancel),
8079
);
8180

8281
$scope = Workflow::async(static fn() => $activity->cancellableActivity());
@@ -98,7 +97,7 @@ public function run()
9897
}
9998

10099
#[Workflow\SignalMethod('activity_result')]
101-
public function activityResult(string $result)
100+
public function activityResult(string $result): void
102101
{
103102
$this->result = $result;
104103
}
@@ -109,14 +108,10 @@ class FeatureActivity
109108
{
110109
public function __construct(
111110
private readonly WorkflowClientInterface $client,
112-
) {
113-
}
111+
) {}
114112

115-
/**
116-
* @return PromiseInterface<null>
117-
*/
118113
#[ActivityMethod('cancellable_activity')]
119-
public function cancellableActivity()
114+
public function cancellableActivity(): void
120115
{
121116
# Heartbeat every second for a minute
122117
$result = 'timeout';

tests/Acceptance/Harness/Activity/RetryOnErrorTest.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,46 @@
2020
use Temporal\Workflow\WorkflowInterface;
2121
use Temporal\Workflow\WorkflowMethod;
2222

23-
/*
24-
25-
# Retrying activities on error
26-
27-
Failed activities can retry in a number of ways. This is configurable by retry policies that govern if and
28-
how a failed activity may retry.
29-
30-
## Feature implementation
31-
32-
* Workflow executes activity with 5 max attempts and low backoff
33-
* Activity errors every time with the attempt that failed
34-
* Workflow waits on activity and re-bubbles its same error
35-
* Confirm the right attempt error message is present
36-
37-
*/
38-
23+
/**
24+
* # Retrying activities on error
25+
*
26+
* Failed activities can retry in a number of ways. This is configurable by retry policies that govern if and
27+
* how a failed activity may retry.
28+
*
29+
* ## Feature implementation
30+
*
31+
* Workflow executes activity with 5 max attempts and low backoff
32+
* Activity errors every time with the attempt that failed
33+
* Workflow waits on activity and re-bubbles its same error
34+
* Confirm the right attempt error message is present
35+
*/
3936
class RetryOnErrorTest extends TestCase
4037
{
4138
#[Test]
42-
public static function check(#[Stub('Harness_Activity_CancelTryCancel')]WorkflowStubInterface $stub): void
43-
{
39+
public static function check(
40+
#[Stub('Harness_Activity_CancelTryCancel')]
41+
WorkflowStubInterface $stub,
42+
): void {
4443
try {
4544
$stub->getResult();
46-
throw new \Exception('Expected WorkflowFailedException');
4745
} catch (WorkflowFailedException $e) {
4846
self::assertInstanceOf(ActivityFailure::class, $e->getPrevious());
4947
/** @var ActivityFailure $failure */
5048
$failure = $e->getPrevious()->getPrevious();
5149
self::assertInstanceOf(ApplicationFailure::class, $failure);
5250
self::assertStringContainsStringIgnoringCase('activity attempt 5 failed', $failure->getOriginalMessage());
51+
return;
5352
}
53+
54+
throw new \Exception('Expected getResult() produced WorkflowFailedException');
5455
}
5556
}
5657

5758
#[WorkflowInterface]
5859
class FeatureWorkflow
5960
{
6061
#[WorkflowMethod('Harness_Activity_CancelTryCancel')]
61-
public function run()
62+
public function run(): iterable
6263
{
6364
# Allow 4 retries with basically no backoff
6465
yield Workflow::newActivityStub(
@@ -71,7 +72,7 @@ public function run()
7172
# Do not increase retry backoff each time
7273
->withBackoffCoefficient(1)
7374
# 5 total maximum attempts
74-
->withMaximumAttempts(5)
75+
->withMaximumAttempts(5),
7576
),
7677
)->alwaysFailActivity();
7778
}

tests/Acceptance/Harness/ContinueAsNew/ContinueAsSameTest.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,41 @@
1212
use Temporal\Workflow\WorkflowInterface;
1313
use Temporal\Workflow\WorkflowMethod;
1414

15-
\define('INPUT_DATA', 'InputData');
16-
\define('MEMO_KEY', 'MemoKey');
17-
\define('MEMO_VALUE', 'MemoValue');
18-
\define('WORKFLOW_ID', 'TestID');
19-
15+
/**
16+
* # Continues workflow execution
17+
*/
2018
class ContinueAsSameTest extends TestCase
2119
{
20+
private const INPUT_DATA = 'InputData';
21+
private const MEMO_KEY = 'MemoKey';
22+
private const MEMO_VALUE = 'MemoValue';
23+
private const WORKFLOW_ID = 'TestID';
24+
2225
#[Test]
2326
public static function check(
2427
#[Stub(
2528
type: 'Harness_ContinueAsNew_ContinueAsSame',
26-
workflowId: WORKFLOW_ID,
27-
args: [INPUT_DATA],
28-
memo: [MEMO_KEY => MEMO_VALUE],
29+
workflowId: self::WORKFLOW_ID,
30+
args: [self::INPUT_DATA],
31+
memo: [self::MEMO_KEY => self::MEMO_VALUE],
2932
)]
3033
WorkflowStubInterface $stub,
3134
): void {
32-
self::assertSame(INPUT_DATA, $stub->getResult());
35+
self::assertSame(self::INPUT_DATA, $stub->getResult());
3336
# Workflow ID does not change after continue as new
34-
self::assertSame(WORKFLOW_ID, $stub->getExecution()->getID());
37+
self::assertSame(self::WORKFLOW_ID, $stub->getExecution()->getID());
3538
# Memos do not change after continue as new
3639
$description = $stub->describe();
37-
self::assertSame([MEMO_KEY => MEMO_VALUE], $description->info->memo->getValues());
40+
self::assertSame(5, $description->info->historyLength);
41+
self::assertSame([self::MEMO_KEY => self::MEMO_VALUE], $description->info->memo->getValues());
3842
}
3943
}
4044

4145
#[WorkflowInterface]
4246
class FeatureWorkflow
4347
{
4448
#[WorkflowMethod('Harness_ContinueAsNew_ContinueAsSame')]
45-
public function run(string $input)
49+
public function run(string $input): iterable
4650
{
4751
if (!empty(Workflow::getInfo()->continuedExecutionRunId)) {
4852
return $input;

0 commit comments

Comments
 (0)