summaryrefslogtreecommitdiff
path: root/tests/temporal/Workflow/ActivityStubWorkflow.php
blob: 58dcdafb1f11d1aa09b2c73eddfb199644b944b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

namespace Temporal\Tests\Workflow;

use Temporal\Activity\ActivityOptions;
use Temporal\Tests\Activity\SimpleActivity;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class ActivityStubWorkflow
{
    #[WorkflowMethod(name: 'ActivityStubWorkflow')]
    public function handler(
        string $input
    ) {
        // typed stub
        $simple = Workflow::newActivityStub(
            SimpleActivity::class,
            ActivityOptions::new()->withStartToCloseTimeout(5)
        );

        $result = [];
        $result[] = yield $simple->echo($input);

        try {
            $simple->undefined($input);
        } catch (\BadMethodCallException $e) {
            $result[] = 'invalid method call';
        }

        // untyped stub
        $untyped = Workflow::newUntypedActivityStub(ActivityOptions::new()->withStartToCloseTimeout(1));

        $result[] = yield $untyped->execute('SimpleActivity.echo', ['untyped']);

        return $result;
    }
}