-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(PHP): add feature
signal\signal_with_start
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Harness\Feature\Signal\SignalWithStart; | ||
|
||
use Harness\Attribute\Check; | ||
use Harness\Runtime\Feature; | ||
use Temporal\Client\WorkflowClientInterface; | ||
use Temporal\Client\WorkflowOptions; | ||
use Temporal\Workflow\SignalMethod; | ||
use Temporal\Workflow\WorkflowInterface; | ||
use Temporal\Workflow\WorkflowMethod; | ||
use Webmozart\Assert\Assert; | ||
|
||
#[WorkflowInterface] | ||
class FeatureWorkflow | ||
{ | ||
private int $value = 0; | ||
|
||
#[WorkflowMethod('Workflow')] | ||
public function run(): int | ||
{ | ||
return $this->value; | ||
} | ||
|
||
#[SignalMethod('add')] | ||
public function add(int $arg): void | ||
{ | ||
$this->value += $arg; | ||
} | ||
} | ||
|
||
class FeatureChecker | ||
{ | ||
#[Check] | ||
public static function check( | ||
WorkflowClientInterface $client, | ||
Feature $feature, | ||
): void { | ||
$stub = $client->newWorkflowStub( | ||
FeatureWorkflow::class, | ||
WorkflowOptions::new()->withTaskQueue($feature->taskQueue), | ||
); | ||
$run = $client->startWithSignal($stub, 'add', [42]); | ||
// See https://github.com/temporalio/sdk-php/issues/457 | ||
Assert::same($run->getResult(), 42, 'Signal must be executed before Workflow handler'); | ||
} | ||
} |