-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathSideEffectTest.php
More file actions
57 lines (49 loc) · 1.6 KB
/
SideEffectTest.php
File metadata and controls
57 lines (49 loc) · 1.6 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace Temporal\Tests\Acceptance\Extra\Workflow\SideEffect;
use PHPUnit\Framework\Attributes\Test;
use Temporal\Client\WorkflowStubInterface;
use Temporal\Common\SideEffectOptions;
use Temporal\Tests\Acceptance\App\Attribute\Stub;
use Temporal\Tests\Acceptance\App\TestCase;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;
class SideEffectTest extends TestCase
{
#[Test]
public static function currentTime(
#[Stub('Extra_Workflow_SideEffect')]
WorkflowStubInterface $stub,
): void {
$result = $stub->getResult(type: 'array');
self::assertEquals($result['system'], $result['current']);
}
}
#[WorkflowInterface]
class MainWorkflow
{
#[WorkflowMethod('Extra_Workflow_SideEffect')]
public function run()
{
yield Workflow::timer('1 seconds');
/**
* @var \DateTimeImmutable $currentDate
*/
$currentDate = yield Workflow::sideEffect(
static fn(): \DateTimeImmutable => new \DateTimeImmutable(),
SideEffectOptions::new()
->withSummary('Side Effect Summary'),
);
return yield [
'current' => [
'timestamp' => $currentDate->getTimestamp(),
'timezone.offset' => $currentDate->getTimeZone()->getOffset($currentDate),
],
'system' => [
'timestamp' => Workflow::now()->getTimestamp(),
'timezone.offset' => Workflow::now()->getTimezone()->getOffset(Workflow::now()),
],
];
}
}