-
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathTestWebhookWorkflow.php
More file actions
63 lines (48 loc) · 1.54 KB
/
TestWebhookWorkflow.php
File metadata and controls
63 lines (48 loc) · 1.54 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
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace Tests\Fixtures;
use AssertionError;
use Illuminate\Contracts\Foundation\Application;
use Workflow\QueryMethod;
use Workflow\SignalMethod;
use Workflow\Webhook;
use Workflow\Workflow;
use function Workflow\{activity, await, sideEffect};
#[Webhook]
class TestWebhookWorkflow extends Workflow
{
public $connection = 'redis';
public $queue = 'default';
private bool $canceled = false;
#[SignalMethod]
#[Webhook]
public function cancel(): void
{
$this->canceled = true;
}
#[QueryMethod]
public function isCanceled(): bool
{
return $this->canceled;
}
public function execute(Application $app, $shouldAssert = false)
{
if (! $app->runningInConsole()) {
throw new AssertionError('Test workflows must run in console.');
}
if ($shouldAssert) {
if (! (yield sideEffect(fn (): bool => ! $this->canceled))) {
throw new AssertionError('Workflow should not be canceled before the first activity.');
}
}
$otherResult = yield activity(TestOtherActivity::class, 'other');
if ($shouldAssert) {
if (! (yield sideEffect(fn (): bool => ! $this->canceled))) {
throw new AssertionError('Workflow should not be canceled before awaiting the signal.');
}
}
yield await(fn (): bool => $this->canceled);
$result = yield activity(TestActivity::class);
return 'workflow_' . $result . '_' . $otherResult;
}
}