Skip to content

Commit 39278b7

Browse files
Show helper-style imports in v2 workflow scaffolding
The v2 authoring API supports two equivalent styles: namespaced helpers (the primary API, `use function Workflow\V2\activity;`) and the static facade (`Workflow::activity()`). The scaffolded workflow stub previously only demonstrated the static facade, which made helper-style imports feel secondary even though most authors and test fixtures use them. Update the `make:workflow --v2` stub to show helper-style imports and calls in the inline example, and cover the new content in the existing `WorkflowMakeCommand` test. The static facade is still mentioned as an equivalent alternative for teams that prefer Temporal-style calls.
1 parent 847bd05 commit 39278b7

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/Commands/stubs/workflow.v2.stub

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,25 @@ class {{ class }} extends Workflow
1212
{
1313
public function handle(): mixed
1414
{
15-
// Example:
15+
// Example (helper-style is the primary authoring API):
1616
//
17-
// $startedAt = Workflow::now();
18-
// $result = Workflow::activity(MyActivity::class, $input);
19-
// Workflow::timer('5 seconds');
20-
// Workflow::upsertMemo(['stage' => 'done']);
17+
// use function Workflow\V2\activity;
18+
// use function Workflow\V2\now;
19+
// use function Workflow\V2\timer;
20+
// use function Workflow\V2\upsertMemo;
21+
//
22+
// $startedAt = now();
23+
// $result = activity(MyActivity::class, $input);
24+
// timer('5 seconds');
25+
// upsertMemo(['stage' => 'done']);
2126
//
2227
// return $result;
2328
//
24-
// Determinism: prefer Workflow::now() over Laravel's now() inside a
25-
// workflow body. Workflow::now() advances with history events during
29+
// Determinism: prefer Workflow\V2\now() over Laravel's now() inside a
30+
// workflow body. Workflow\V2\now() advances with history events during
2631
// replay, so the same workflow run always observes the same timeline.
32+
// The static facade (Workflow::activity(), Workflow::now(), ...) is an
33+
// equivalent alternative for teams that prefer Temporal-style calls.
2734
return null;
2835
}
2936
}

tests/Unit/Commands/WorkflowMakeCommandTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public function testMakeCommandCanCreateV2WorkflowScaffold(): void
5757
$this->assertStringContainsString("#[Type('test-workflow')]", $contents);
5858
$this->assertStringContainsString('public function handle(): mixed', $contents);
5959
$this->assertStringContainsString('return null;', $contents);
60+
$this->assertStringContainsString('use function Workflow\\V2\\activity;', $contents);
61+
$this->assertStringContainsString('use function Workflow\\V2\\now;', $contents);
62+
$this->assertStringContainsString('use function Workflow\\V2\\timer;', $contents);
63+
$this->assertStringContainsString('$result = activity(MyActivity::class, $input);', $contents);
64+
$this->assertStringContainsString('timer(\'5 seconds\');', $contents);
6065
$this->assertStringNotContainsString('Generator', $contents);
6166
$this->assertStringNotContainsString('yield', $contents);
6267
$this->assertStringNotContainsString('use Workflow\\Workflow;', $contents);

0 commit comments

Comments
 (0)