diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 8013dfe1..85a1f23c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -65,7 +65,7 @@ jobs: mysql -e 'CREATE DATABASE testbench' -h127.0.0.1 -uroot -ppassword -P ${{ job.services.mysql.ports[3306] }} - name: Run test suite (MySQL) - run: vendor/bin/phpunit --testdox --testsuite feature + run: vendor/bin/phpunit --testdox --debug --testsuite feature env: APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= DB_CONNECTION: mysql @@ -81,7 +81,7 @@ jobs: REDIS_PORT: 6379 - name: Run test suite (PostgreSQL) - run: vendor/bin/phpunit --testdox --testsuite feature + run: vendor/bin/phpunit --testdox --debug --testsuite feature env: APP_KEY: base64:i3g6f+dV8FfsIkcxqd7gbiPn2oXk5r00sTmdD6V5utI= DB_CONNECTION: pgsql diff --git a/composer.json b/composer.json index 3523a1c4..b08aa9b8 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,10 @@ "autoload": { "psr-4": { "Workflow\\": "src/" - } + }, + "files": [ + "src/functions.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/functions.php b/src/functions.php new file mode 100644 index 00000000..0891df41 --- /dev/null +++ b/src/functions.php @@ -0,0 +1,130 @@ + $this->firstApproved); + yield await(fn () => $this->firstApproved); - yield ActivityStub::make(TestActivity::class); + yield activity(TestActivity::class); - yield WorkflowStub::await(fn () => $this->secondApproved); + yield await(fn () => $this->secondApproved); return 'completed'; } diff --git a/tests/Fixtures/TestActivityThenAwaitWorkflow.php b/tests/Fixtures/TestActivityThenAwaitWorkflow.php index 1dd3f4e7..c7306b45 100644 --- a/tests/Fixtures/TestActivityThenAwaitWorkflow.php +++ b/tests/Fixtures/TestActivityThenAwaitWorkflow.php @@ -4,10 +4,9 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, await}; final class TestActivityThenAwaitWorkflow extends Workflow { @@ -21,9 +20,9 @@ public function approve(bool $value): void public function execute() { - yield ActivityStub::make(TestActivity::class); + yield activity(TestActivity::class); - yield WorkflowStub::await(fn () => $this->approved); + yield await(fn () => $this->approved); return 'approved'; } diff --git a/tests/Fixtures/TestActivityThrowsAwaitRetryWorkflow.php b/tests/Fixtures/TestActivityThrowsAwaitRetryWorkflow.php index 4f344c9f..d3cd39a6 100644 --- a/tests/Fixtures/TestActivityThrowsAwaitRetryWorkflow.php +++ b/tests/Fixtures/TestActivityThrowsAwaitRetryWorkflow.php @@ -5,10 +5,9 @@ namespace Tests\Fixtures; use Throwable; -use Workflow\ActivityStub; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, await}; final class TestActivityThrowsAwaitRetryWorkflow extends Workflow { @@ -29,10 +28,10 @@ public function execute() $shouldThrow = true; while (true) { try { - yield ActivityStub::make(TestSingleTryExceptionActivity::class, $shouldThrow); + yield activity(TestSingleTryExceptionActivity::class, $shouldThrow); return true; } catch (Throwable) { - yield WorkflowStub::await(fn () => $this->shouldRetry); + yield await(fn () => $this->shouldRetry); $this->shouldRetry = false; $shouldThrow = false; } diff --git a/tests/Fixtures/TestAsyncWorkflow.php b/tests/Fixtures/TestAsyncWorkflow.php index 10304ec7..378e0fea 100644 --- a/tests/Fixtures/TestAsyncWorkflow.php +++ b/tests/Fixtures/TestAsyncWorkflow.php @@ -5,19 +5,19 @@ namespace Tests\Fixtures; use Illuminate\Contracts\Foundation\Application; -use Workflow\ActivityStub; use Workflow\Workflow; +use function Workflow\{activity, async}; final class TestAsyncWorkflow extends Workflow { public function execute() { - $results = yield ActivityStub::async(static function (Application $app) { + $results = yield async(static function (Application $app) { assert($app->runningInConsole()); - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); return [$otherResult, $result]; }); diff --git a/tests/Fixtures/TestAwaitWithTimeoutWorkflow.php b/tests/Fixtures/TestAwaitWithTimeoutWorkflow.php index 8a3651d6..5809fbed 100644 --- a/tests/Fixtures/TestAwaitWithTimeoutWorkflow.php +++ b/tests/Fixtures/TestAwaitWithTimeoutWorkflow.php @@ -4,14 +4,14 @@ namespace Tests\Fixtures; +use function Workflow\awaitWithTimeout; use Workflow\Workflow; -use Workflow\WorkflowStub; final class TestAwaitWithTimeoutWorkflow extends Workflow { public function execute($shouldTimeout = false) { - $result = yield WorkflowStub::awaitWithTimeout(5, static fn (): bool => ! $shouldTimeout); + $result = yield awaitWithTimeout(5, static fn (): bool => ! $shouldTimeout); return $result ? 'workflow' : 'workflow_timed_out'; } diff --git a/tests/Fixtures/TestAwaitWorkflow.php b/tests/Fixtures/TestAwaitWorkflow.php index c1f2609a..1307b43c 100644 --- a/tests/Fixtures/TestAwaitWorkflow.php +++ b/tests/Fixtures/TestAwaitWorkflow.php @@ -4,9 +4,9 @@ namespace Tests\Fixtures; +use function Workflow\await; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; final class TestAwaitWorkflow extends Workflow { @@ -20,7 +20,7 @@ public function cancel(): void public function execute() { - yield WorkflowStub::await(fn (): bool => $this->canceled); + yield await(fn (): bool => $this->canceled); return 'workflow'; } diff --git a/tests/Fixtures/TestBadConnectionWorkflow.php b/tests/Fixtures/TestBadConnectionWorkflow.php index d1494ac8..a3e626b5 100644 --- a/tests/Fixtures/TestBadConnectionWorkflow.php +++ b/tests/Fixtures/TestBadConnectionWorkflow.php @@ -5,11 +5,10 @@ namespace Tests\Fixtures; use Illuminate\Contracts\Foundation\Application; -use Workflow\ActivityStub; use Workflow\QueryMethod; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, await}; class TestBadConnectionWorkflow extends Workflow { @@ -39,15 +38,15 @@ public function execute(Application $app, $shouldAssert = false) assert(! $this->canceled); } - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); if ($shouldAssert) { assert(! $this->canceled); } - yield WorkflowStub::await(fn (): bool => $this->canceled); + yield await(fn (): bool => $this->canceled); - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); return 'workflow_' . $result . '_' . $otherResult; } diff --git a/tests/Fixtures/TestChildContinueAsNewWorkflow.php b/tests/Fixtures/TestChildContinueAsNewWorkflow.php index 1fd8b605..5cd0f9e2 100644 --- a/tests/Fixtures/TestChildContinueAsNewWorkflow.php +++ b/tests/Fixtures/TestChildContinueAsNewWorkflow.php @@ -4,20 +4,19 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, continueAsNew}; class TestChildContinueAsNewWorkflow extends Workflow { public function execute(int $count = 0, int $totalCount = 3) { - $activityResult = yield ActivityStub::make(TestCountActivity::class, $count); + $activityResult = yield activity(TestCountActivity::class, $count); if ($count >= $totalCount) { return 'child_workflow_' . $activityResult; } - return yield WorkflowStub::continueAsNew($count + 1, $totalCount); + return yield continueAsNew($count + 1, $totalCount); } } diff --git a/tests/Fixtures/TestChildExceptionWorkflow.php b/tests/Fixtures/TestChildExceptionWorkflow.php index c156d4c4..952bb2f5 100644 --- a/tests/Fixtures/TestChildExceptionWorkflow.php +++ b/tests/Fixtures/TestChildExceptionWorkflow.php @@ -5,7 +5,7 @@ namespace Tests\Fixtures; use Exception; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; class TestChildExceptionWorkflow extends Workflow @@ -20,7 +20,7 @@ public function execute($shouldThrow = false) throw new Exception('failed'); } - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); return $otherResult; } diff --git a/tests/Fixtures/TestChildTimerWorkflow.php b/tests/Fixtures/TestChildTimerWorkflow.php index 0ed972f0..a6b49b22 100644 --- a/tests/Fixtures/TestChildTimerWorkflow.php +++ b/tests/Fixtures/TestChildTimerWorkflow.php @@ -4,9 +4,8 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, timer}; class TestChildTimerWorkflow extends Workflow { @@ -16,9 +15,9 @@ class TestChildTimerWorkflow extends Workflow public function execute($seconds = 1) { - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); - yield WorkflowStub::timer($seconds); + yield timer($seconds); return $otherResult; } diff --git a/tests/Fixtures/TestChildWorkflow.php b/tests/Fixtures/TestChildWorkflow.php index 3d895a37..037f7f10 100644 --- a/tests/Fixtures/TestChildWorkflow.php +++ b/tests/Fixtures/TestChildWorkflow.php @@ -4,14 +4,14 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; class TestChildWorkflow extends Workflow { public function execute() { - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); return $otherResult; } diff --git a/tests/Fixtures/TestConcurrentWorkflow.php b/tests/Fixtures/TestConcurrentWorkflow.php index 302c5fb5..0986cf87 100644 --- a/tests/Fixtures/TestConcurrentWorkflow.php +++ b/tests/Fixtures/TestConcurrentWorkflow.php @@ -4,18 +4,18 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; use Workflow\Workflow; +use function Workflow\{activity, all}; final class TestConcurrentWorkflow extends Workflow { public function execute() { - $otherResultPromise = ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResultPromise = activity(TestOtherActivity::class, 'other'); - $resultPromise = ActivityStub::make(TestActivity::class); + $resultPromise = activity(TestActivity::class); - $results = yield ActivityStub::all([$otherResultPromise, $resultPromise]); + $results = yield all([$otherResultPromise, $resultPromise]); return 'workflow_' . $results[1] . '_' . $results[0]; } diff --git a/tests/Fixtures/TestContinueAsNewWorkflow.php b/tests/Fixtures/TestContinueAsNewWorkflow.php index b0ffde68..be123158 100644 --- a/tests/Fixtures/TestContinueAsNewWorkflow.php +++ b/tests/Fixtures/TestContinueAsNewWorkflow.php @@ -4,20 +4,19 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, continueAsNew}; class TestContinueAsNewWorkflow extends Workflow { public function execute(int $count = 0, int $totalCount = 3) { - $activityResult = yield ActivityStub::make(TestCountActivity::class, $count); + $activityResult = yield activity(TestCountActivity::class, $count); if ($count >= $totalCount) { return 'workflow_' . $activityResult; } - return yield WorkflowStub::continueAsNew($count + 1, $totalCount); + return yield continueAsNew($count + 1, $totalCount); } } diff --git a/tests/Fixtures/TestCoroutineSendExceptionWorkflow.php b/tests/Fixtures/TestCoroutineSendExceptionWorkflow.php index 26318dbb..7aabb12a 100644 --- a/tests/Fixtures/TestCoroutineSendExceptionWorkflow.php +++ b/tests/Fixtures/TestCoroutineSendExceptionWorkflow.php @@ -5,14 +5,14 @@ namespace Tests\Fixtures; use Exception; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; class TestCoroutineSendExceptionWorkflow extends Workflow { public function execute() { - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); throw new Exception('exception test'); } diff --git a/tests/Fixtures/TestExceptionWorkflow.php b/tests/Fixtures/TestExceptionWorkflow.php index 075e3b71..985d5eeb 100644 --- a/tests/Fixtures/TestExceptionWorkflow.php +++ b/tests/Fixtures/TestExceptionWorkflow.php @@ -4,16 +4,16 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; final class TestExceptionWorkflow extends Workflow { public function execute() { - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); - $result = yield ActivityStub::make(TestExceptionActivity::class); + $result = yield activity(TestExceptionActivity::class); return 'workflow_' . $result . '_' . $otherResult; } diff --git a/tests/Fixtures/TestFailingWorkflow.php b/tests/Fixtures/TestFailingWorkflow.php index a762a3b7..10bcf14d 100644 --- a/tests/Fixtures/TestFailingWorkflow.php +++ b/tests/Fixtures/TestFailingWorkflow.php @@ -5,20 +5,20 @@ namespace Tests\Fixtures; use Exception; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; final class TestFailingWorkflow extends Workflow { public function execute($shouldFail = false) { - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); if ($shouldFail) { throw new Exception('failed'); } - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); return 'workflow_' . $result . '_' . $otherResult; } diff --git a/tests/Fixtures/TestHeartbeatWorkflow.php b/tests/Fixtures/TestHeartbeatWorkflow.php index 26855d65..14499e6f 100644 --- a/tests/Fixtures/TestHeartbeatWorkflow.php +++ b/tests/Fixtures/TestHeartbeatWorkflow.php @@ -4,16 +4,16 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; final class TestHeartbeatWorkflow extends Workflow { public function execute() { - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); - $result = yield ActivityStub::make(TestHeartbeatActivity::class); + $result = yield activity(TestHeartbeatActivity::class); return 'workflow_' . $result . '_' . $otherResult; } diff --git a/tests/Fixtures/TestModelWorkflow.php b/tests/Fixtures/TestModelWorkflow.php index 417f87d6..3a83eb30 100644 --- a/tests/Fixtures/TestModelWorkflow.php +++ b/tests/Fixtures/TestModelWorkflow.php @@ -5,14 +5,14 @@ namespace Tests\Fixtures; use Workbench\App\Models\User; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; class TestModelWorkflow extends Workflow { public function execute(User $user) { - $result = yield ActivityStub::make(TestModelActivity::class, $user); + $result = yield activity(TestModelActivity::class, $user); return $result; } diff --git a/tests/Fixtures/TestMultiStageApprovalWorkflow.php b/tests/Fixtures/TestMultiStageApprovalWorkflow.php index 3e712487..ef6ddc98 100644 --- a/tests/Fixtures/TestMultiStageApprovalWorkflow.php +++ b/tests/Fixtures/TestMultiStageApprovalWorkflow.php @@ -4,10 +4,9 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, all, await}; final class TestMultiStageApprovalWorkflow extends Workflow { @@ -45,20 +44,20 @@ public function approveExecutive(bool $value): void public function execute() { - yield ActivityStub::make(TestRequestManagerApprovalActivity::class); + yield activity(TestRequestManagerApprovalActivity::class); - yield WorkflowStub::await(fn () => $this->managerApproved); + yield await(fn () => $this->managerApproved); - yield ActivityStub::all([ - ActivityStub::make(TestRequestFinanceApprovalActivity::class), - ActivityStub::make(TestRequestLegalApprovalActivity::class), + yield all([ + activity(TestRequestFinanceApprovalActivity::class), + activity(TestRequestLegalApprovalActivity::class), ]); - yield WorkflowStub::await(fn () => $this->financeApproved && $this->legalApproved); + yield await(fn () => $this->financeApproved && $this->legalApproved); - yield ActivityStub::make(TestRequestExecutiveApprovalActivity::class); + yield activity(TestRequestExecutiveApprovalActivity::class); - yield WorkflowStub::await(fn () => $this->executiveApproved); + yield await(fn () => $this->executiveApproved); return 'approved'; } diff --git a/tests/Fixtures/TestMultipleAwaitsWorkflow.php b/tests/Fixtures/TestMultipleAwaitsWorkflow.php index 1b77e214..abc30705 100644 --- a/tests/Fixtures/TestMultipleAwaitsWorkflow.php +++ b/tests/Fixtures/TestMultipleAwaitsWorkflow.php @@ -4,9 +4,9 @@ namespace Tests\Fixtures; +use function Workflow\await; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; final class TestMultipleAwaitsWorkflow extends Workflow { @@ -28,9 +28,9 @@ public function approveSecond(bool $value): void public function execute() { - yield WorkflowStub::await(fn () => $this->firstApproved); + yield await(fn () => $this->firstApproved); - yield WorkflowStub::await(fn () => $this->secondApproved); + yield await(fn () => $this->secondApproved); return 'both_approved'; } diff --git a/tests/Fixtures/TestNonRetryableExceptionWorkflow.php b/tests/Fixtures/TestNonRetryableExceptionWorkflow.php index a72f910a..e775d0ee 100644 --- a/tests/Fixtures/TestNonRetryableExceptionWorkflow.php +++ b/tests/Fixtures/TestNonRetryableExceptionWorkflow.php @@ -4,15 +4,15 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; final class TestNonRetryableExceptionWorkflow extends Workflow { public function execute() { - yield ActivityStub::make(TestNonRetryableExceptionActivity::class); - yield ActivityStub::make(TestActivity::class); + yield activity(TestNonRetryableExceptionActivity::class); + yield activity(TestActivity::class); return 'Workflow completes'; } diff --git a/tests/Fixtures/TestParentAsyncWorkflow.php b/tests/Fixtures/TestParentAsyncWorkflow.php index b856e339..c261c320 100644 --- a/tests/Fixtures/TestParentAsyncWorkflow.php +++ b/tests/Fixtures/TestParentAsyncWorkflow.php @@ -4,9 +4,8 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; -use Workflow\ChildWorkflowStub; use Workflow\Workflow; +use function Workflow\{activity, async, child}; class TestParentAsyncWorkflow extends Workflow { @@ -16,10 +15,10 @@ class TestParentAsyncWorkflow extends Workflow public function execute() { - $results = yield ActivityStub::async(static function () { - $otherResult = yield ChildWorkflowStub::make(TestChildWorkflow::class); + $results = yield async(static function () { + $otherResult = yield child(TestChildWorkflow::class); - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); return [$otherResult, $result]; }); diff --git a/tests/Fixtures/TestParentContinueAsNewChildWorkflow.php b/tests/Fixtures/TestParentContinueAsNewChildWorkflow.php index bda091f6..614f805a 100644 --- a/tests/Fixtures/TestParentContinueAsNewChildWorkflow.php +++ b/tests/Fixtures/TestParentContinueAsNewChildWorkflow.php @@ -4,14 +4,14 @@ namespace Tests\Fixtures; -use Workflow\ChildWorkflowStub; +use function Workflow\child; use Workflow\Workflow; class TestParentContinueAsNewChildWorkflow extends Workflow { public function execute() { - $childResult = yield ChildWorkflowStub::make(TestChildContinueAsNewWorkflow::class); + $childResult = yield child(TestChildContinueAsNewWorkflow::class); return 'parent_' . $childResult; } diff --git a/tests/Fixtures/TestParentExceptionWorkflow.php b/tests/Fixtures/TestParentExceptionWorkflow.php index e6d67850..dae26d04 100644 --- a/tests/Fixtures/TestParentExceptionWorkflow.php +++ b/tests/Fixtures/TestParentExceptionWorkflow.php @@ -4,9 +4,8 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; -use Workflow\ChildWorkflowStub; use Workflow\Workflow; +use function Workflow\{activity, child}; class TestParentExceptionWorkflow extends Workflow { @@ -16,9 +15,9 @@ class TestParentExceptionWorkflow extends Workflow public function execute($shouldThrow = false) { - $otherResult = yield ChildWorkflowStub::make(TestChildExceptionWorkflow::class, $shouldThrow); + $otherResult = yield child(TestChildExceptionWorkflow::class, $shouldThrow); - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); return 'workflow_' . $result . '_' . $otherResult; } diff --git a/tests/Fixtures/TestParentSignalingChildViaSignal.php b/tests/Fixtures/TestParentSignalingChildViaSignal.php index a8d71388..b9150a18 100644 --- a/tests/Fixtures/TestParentSignalingChildViaSignal.php +++ b/tests/Fixtures/TestParentSignalingChildViaSignal.php @@ -4,10 +4,9 @@ namespace Tests\Fixtures; -use Workflow\ChildWorkflowStub; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{await, child}; class TestParentSignalingChildViaSignal extends Workflow { @@ -24,11 +23,11 @@ public function forwardApproval(string $status): void public function execute() { - $childPromise = ChildWorkflowStub::make(TestSimpleChildWorkflowWithSignal::class, 'forwarded'); + $childPromise = child(TestSimpleChildWorkflowWithSignal::class, 'forwarded'); $childHandle = $this->child(); - yield WorkflowStub::await(fn () => $this->receivedSignal); + yield await(fn () => $this->receivedSignal); if ($childHandle && $this->signalStatus) { $childHandle->approve($this->signalStatus); diff --git a/tests/Fixtures/TestParentTimerWorkflow.php b/tests/Fixtures/TestParentTimerWorkflow.php index f338a883..7ef3e656 100644 --- a/tests/Fixtures/TestParentTimerWorkflow.php +++ b/tests/Fixtures/TestParentTimerWorkflow.php @@ -4,9 +4,8 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; -use Workflow\ChildWorkflowStub; use Workflow\Workflow; +use function Workflow\{activity, child}; class TestParentTimerWorkflow extends Workflow { @@ -16,9 +15,9 @@ class TestParentTimerWorkflow extends Workflow public function execute($seconds = 1) { - $otherResult = yield ChildWorkflowStub::make(TestChildTimerWorkflow::class, $seconds); + $otherResult = yield child(TestChildTimerWorkflow::class, $seconds); - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); return 'workflow_' . $result . '_' . $otherResult; } diff --git a/tests/Fixtures/TestParentWorkflow.php b/tests/Fixtures/TestParentWorkflow.php index ce0b7560..b0e97a35 100644 --- a/tests/Fixtures/TestParentWorkflow.php +++ b/tests/Fixtures/TestParentWorkflow.php @@ -4,10 +4,9 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; -use Workflow\ChildWorkflowStub; use Workflow\SignalMethod; use Workflow\Workflow; +use function Workflow\{activity, child}; class TestParentWorkflow extends Workflow { @@ -19,9 +18,9 @@ public function ping(): void public function execute() { - $otherResult = yield ChildWorkflowStub::make(TestChildWorkflow::class); + $otherResult = yield child(TestChildWorkflow::class); - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); return 'workflow_' . $result . '_' . $otherResult; } diff --git a/tests/Fixtures/TestParentWorkflowSignalingChildDirectly.php b/tests/Fixtures/TestParentWorkflowSignalingChildDirectly.php index 89cde3e2..f91c09f5 100644 --- a/tests/Fixtures/TestParentWorkflowSignalingChildDirectly.php +++ b/tests/Fixtures/TestParentWorkflowSignalingChildDirectly.php @@ -4,14 +4,14 @@ namespace Tests\Fixtures; -use Workflow\ChildWorkflowStub; +use function Workflow\child; use Workflow\Workflow; final class TestParentWorkflowSignalingChildDirectly extends Workflow { public function execute() { - $childPromise = ChildWorkflowStub::make(TestSimpleChildWorkflowWithSignal::class, 'direct_signaling'); + $childPromise = child(TestSimpleChildWorkflowWithSignal::class, 'direct_signaling'); $childHandle = $this->child(); diff --git a/tests/Fixtures/TestParentWorkflowWithContextCheck.php b/tests/Fixtures/TestParentWorkflowWithContextCheck.php index 06588682..b4ed68c1 100644 --- a/tests/Fixtures/TestParentWorkflowWithContextCheck.php +++ b/tests/Fixtures/TestParentWorkflowWithContextCheck.php @@ -4,16 +4,15 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; -use Workflow\ChildWorkflowStub; use Workflow\Workflow; use Workflow\WorkflowStub; +use function Workflow\{activity, child}; final class TestParentWorkflowWithContextCheck extends Workflow { public function execute() { - $childPromise = ChildWorkflowStub::make(TestSimpleChildWorkflowWithSignal::class, 'context_check'); + $childPromise = child(TestSimpleChildWorkflowWithSignal::class, 'context_check'); $contextBefore = WorkflowStub::getContext(); $indexBefore = $contextBefore->index; @@ -40,7 +39,7 @@ public function execute() return 'context_corrupted:workflow:' . $storedWorkflowBefore . ':' . $storedWorkflowAfter; } - yield ActivityStub::make(TestActivity::class); + yield activity(TestActivity::class); $result = yield $childPromise; diff --git a/tests/Fixtures/TestParentWorkflowWithMultipleChildren.php b/tests/Fixtures/TestParentWorkflowWithMultipleChildren.php index 11654a5a..f62acb69 100644 --- a/tests/Fixtures/TestParentWorkflowWithMultipleChildren.php +++ b/tests/Fixtures/TestParentWorkflowWithMultipleChildren.php @@ -4,6 +4,7 @@ namespace Tests\Fixtures; +use function Workflow\child; use Workflow\ChildWorkflowStub; use Workflow\Workflow; @@ -11,15 +12,15 @@ final class TestParentWorkflowWithMultipleChildren extends Workflow { public function execute() { - $child1Promise = ChildWorkflowStub::make(TestSimpleChildWorkflowWithSignal::class, 'child1'); + $child1Promise = child(TestSimpleChildWorkflowWithSignal::class, 'child1'); $child1Handle = $this->child(); $child1Handle->approve('first'); - $child2Promise = ChildWorkflowStub::make(TestSimpleChildWorkflowWithSignal::class, 'child2'); + $child2Promise = child(TestSimpleChildWorkflowWithSignal::class, 'child2'); $child2Handle = $this->child(); $child2Handle->approve('second'); - $child3Promise = ChildWorkflowStub::make(TestSimpleChildWorkflowWithSignal::class, 'child3'); + $child3Promise = child(TestSimpleChildWorkflowWithSignal::class, 'child3'); $child3Handle = $this->child(); $child3Handle->approve('third'); diff --git a/tests/Fixtures/TestPureAwaitWorkflow.php b/tests/Fixtures/TestPureAwaitWorkflow.php index 485cb532..9d48cf6b 100644 --- a/tests/Fixtures/TestPureAwaitWorkflow.php +++ b/tests/Fixtures/TestPureAwaitWorkflow.php @@ -4,9 +4,9 @@ namespace Tests\Fixtures; +use function Workflow\await; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; final class TestPureAwaitWorkflow extends Workflow { @@ -20,7 +20,7 @@ public function approve(bool $value): void public function execute() { - yield WorkflowStub::await(fn () => $this->approved); + yield await(fn () => $this->approved); return 'approved'; } diff --git a/tests/Fixtures/TestRetriesWorkflow.php b/tests/Fixtures/TestRetriesWorkflow.php index 9c5ef750..f4c9c424 100644 --- a/tests/Fixtures/TestRetriesWorkflow.php +++ b/tests/Fixtures/TestRetriesWorkflow.php @@ -4,7 +4,7 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; class TestRetriesWorkflow extends Workflow @@ -15,6 +15,6 @@ class TestRetriesWorkflow extends Workflow public function execute() { - yield ActivityStub::make(TestRetriesActivity::class); + yield activity(TestRetriesActivity::class); } } diff --git a/tests/Fixtures/TestSagaWorkflow.php b/tests/Fixtures/TestSagaWorkflow.php index cd729d04..04ad3719 100644 --- a/tests/Fixtures/TestSagaWorkflow.php +++ b/tests/Fixtures/TestSagaWorkflow.php @@ -4,7 +4,7 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; class TestSagaWorkflow extends Workflow @@ -12,11 +12,11 @@ class TestSagaWorkflow extends Workflow public function execute($shouldThrow = false) { try { - yield ActivityStub::make(TestActivity::class); - $this->addCompensation(static fn () => ActivityStub::make(TestUndoActivity::class)); + yield activity(TestActivity::class); + $this->addCompensation(static fn () => activity(TestUndoActivity::class)); - yield ActivityStub::make(TestSagaActivity::class); - $this->addCompensation(static fn () => ActivityStub::make(TestSagaUndoActivity::class)); + yield activity(TestSagaActivity::class); + $this->addCompensation(static fn () => activity(TestSagaUndoActivity::class)); } catch (\Throwable $th) { yield from $this->compensate(); if ($shouldThrow) { diff --git a/tests/Fixtures/TestSideEffectWorkflow.php b/tests/Fixtures/TestSideEffectWorkflow.php index 97903c61..436a3e79 100644 --- a/tests/Fixtures/TestSideEffectWorkflow.php +++ b/tests/Fixtures/TestSideEffectWorkflow.php @@ -5,9 +5,8 @@ namespace Tests\Fixtures; use Exception; -use Workflow\ActivityStub; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, sideEffect}; class TestSideEffectWorkflow extends Workflow { @@ -17,15 +16,15 @@ class TestSideEffectWorkflow extends Workflow public function execute() { - $sideEffect = yield WorkflowStub::sideEffect(static fn () => random_int(PHP_INT_MIN, PHP_INT_MAX)); + $sideEffect = yield sideEffect(static fn () => random_int(PHP_INT_MIN, PHP_INT_MAX)); $badSideEffect = random_int(PHP_INT_MIN, PHP_INT_MAX); - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); - $otherResult1 = yield ActivityStub::make(TestOtherActivity::class, $sideEffect); + $otherResult1 = yield activity(TestOtherActivity::class, $sideEffect); - $otherResult2 = yield ActivityStub::make(TestOtherActivity::class, $badSideEffect); + $otherResult2 = yield activity(TestOtherActivity::class, $badSideEffect); if ($sideEffect !== $otherResult1) { throw new Exception( diff --git a/tests/Fixtures/TestSignalExceptionWorkflow.php b/tests/Fixtures/TestSignalExceptionWorkflow.php index c8186d74..cefd0612 100644 --- a/tests/Fixtures/TestSignalExceptionWorkflow.php +++ b/tests/Fixtures/TestSignalExceptionWorkflow.php @@ -5,10 +5,9 @@ namespace Tests\Fixtures; use Throwable; -use Workflow\ActivityStub; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, await}; class TestSignalExceptionWorkflow extends Workflow { @@ -25,11 +24,11 @@ public function execute(array $data = []) $shouldThrow = true; while (true) { try { - yield ActivityStub::make(TestActivity::class); - yield ActivityStub::make(TestSingleTryExceptionActivity::class, $shouldThrow); + yield activity(TestActivity::class); + yield activity(TestSingleTryExceptionActivity::class, $shouldThrow); return true; } catch (Throwable) { - yield WorkflowStub::await(fn () => $this->shouldRetry); + yield await(fn () => $this->shouldRetry); $this->shouldRetry = false; $shouldThrow = false; } diff --git a/tests/Fixtures/TestSignalExceptionWorkflowLeader.php b/tests/Fixtures/TestSignalExceptionWorkflowLeader.php index 9d6ed013..e7382db9 100644 --- a/tests/Fixtures/TestSignalExceptionWorkflowLeader.php +++ b/tests/Fixtures/TestSignalExceptionWorkflowLeader.php @@ -5,10 +5,9 @@ namespace Tests\Fixtures; use Throwable; -use Workflow\ActivityStub; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, await}; class TestSignalExceptionWorkflowLeader extends Workflow { @@ -25,10 +24,10 @@ public function execute(array $data = []) $shouldThrow = true; while (true) { try { - yield ActivityStub::make(TestSingleTryExceptionActivity::class, $shouldThrow); + yield activity(TestSingleTryExceptionActivity::class, $shouldThrow); return true; } catch (Throwable) { - yield WorkflowStub::await(fn () => $this->shouldRetry); + yield await(fn () => $this->shouldRetry); $this->shouldRetry = false; $shouldThrow = false; } diff --git a/tests/Fixtures/TestSimpleChildWorkflowWithSignal.php b/tests/Fixtures/TestSimpleChildWorkflowWithSignal.php index a8e5465b..c26af20b 100644 --- a/tests/Fixtures/TestSimpleChildWorkflowWithSignal.php +++ b/tests/Fixtures/TestSimpleChildWorkflowWithSignal.php @@ -4,9 +4,9 @@ namespace Tests\Fixtures; +use function Workflow\await; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; class TestSimpleChildWorkflowWithSignal extends Workflow { @@ -20,7 +20,7 @@ public function approve(string $status): void public function execute(string $prefix) { - yield WorkflowStub::await(fn () => $this->approved !== null); + yield await(fn () => $this->approved !== null); return $prefix . '_' . $this->approved; } diff --git a/tests/Fixtures/TestSimpleWorkflow.php b/tests/Fixtures/TestSimpleWorkflow.php index 400a509f..df518966 100644 --- a/tests/Fixtures/TestSimpleWorkflow.php +++ b/tests/Fixtures/TestSimpleWorkflow.php @@ -4,7 +4,7 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; class TestSimpleWorkflow extends Workflow @@ -15,7 +15,7 @@ class TestSimpleWorkflow extends Workflow public function execute() { - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); return 'workflow_' . $result; } diff --git a/tests/Fixtures/TestStateMachineWorkflow.php b/tests/Fixtures/TestStateMachineWorkflow.php index 178a4827..89a8db02 100644 --- a/tests/Fixtures/TestStateMachineWorkflow.php +++ b/tests/Fixtures/TestStateMachineWorkflow.php @@ -4,10 +4,10 @@ namespace Tests\Fixtures; +use function Workflow\await; use Workflow\Models\StoredWorkflow; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; class TestStateMachineWorkflow extends Workflow { @@ -72,9 +72,9 @@ public function isDenied() public function execute() { - yield WorkflowStub::await(fn () => $this->isSubmitted()); + yield await(fn () => $this->isSubmitted()); - yield WorkflowStub::await(fn () => $this->isApproved() || $this->isDenied()); + yield await(fn () => $this->isApproved() || $this->isDenied()); return $this->stateMachine->getCurrentState(); } diff --git a/tests/Fixtures/TestTimeTravelWorkflow.php b/tests/Fixtures/TestTimeTravelWorkflow.php index c56a2a73..2ff0a910 100644 --- a/tests/Fixtures/TestTimeTravelWorkflow.php +++ b/tests/Fixtures/TestTimeTravelWorkflow.php @@ -4,11 +4,10 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; use Workflow\QueryMethod; use Workflow\SignalMethod; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, await, minutes}; class TestTimeTravelWorkflow extends Workflow { @@ -28,13 +27,13 @@ public function isCanceled(): bool public function execute() { - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); - yield WorkflowStub::await(fn (): bool => $this->canceled); + yield await(fn (): bool => $this->canceled); - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); - yield WorkflowStub::timer(60); + yield minutes(1); return 'workflow_' . $result . '_' . $otherResult; } diff --git a/tests/Fixtures/TestTimeoutWorkflow.php b/tests/Fixtures/TestTimeoutWorkflow.php index cb76b1b7..87c8ba18 100644 --- a/tests/Fixtures/TestTimeoutWorkflow.php +++ b/tests/Fixtures/TestTimeoutWorkflow.php @@ -4,7 +4,7 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; +use function Workflow\activity; use Workflow\Workflow; class TestTimeoutWorkflow extends Workflow @@ -15,6 +15,6 @@ class TestTimeoutWorkflow extends Workflow public function execute() { - yield ActivityStub::make(TestTimeoutActivity::class); + yield activity(TestTimeoutActivity::class); } } diff --git a/tests/Fixtures/TestTimerQueryWorkflow.php b/tests/Fixtures/TestTimerQueryWorkflow.php index d72b61c7..f778e4f5 100644 --- a/tests/Fixtures/TestTimerQueryWorkflow.php +++ b/tests/Fixtures/TestTimerQueryWorkflow.php @@ -5,8 +5,8 @@ namespace Tests\Fixtures; use Workflow\QueryMethod; +use function Workflow\timer; use Workflow\Workflow; -use Workflow\WorkflowStub; final class TestTimerQueryWorkflow extends Workflow { @@ -20,7 +20,7 @@ public function getStatus(): string public function execute($seconds = 10) { - yield WorkflowStub::timer($seconds); + yield timer($seconds); $this->status = 'completed'; diff --git a/tests/Fixtures/TestTimerWorkflow.php b/tests/Fixtures/TestTimerWorkflow.php index 8969dacf..3138fe8b 100644 --- a/tests/Fixtures/TestTimerWorkflow.php +++ b/tests/Fixtures/TestTimerWorkflow.php @@ -4,14 +4,14 @@ namespace Tests\Fixtures; +use function Workflow\timer; use Workflow\Workflow; -use Workflow\WorkflowStub; final class TestTimerWorkflow extends Workflow { public function execute($seconds = 1) { - yield WorkflowStub::timer($seconds); + yield timer($seconds); return 'workflow'; } diff --git a/tests/Fixtures/TestVersionMinSupportedWorkflow.php b/tests/Fixtures/TestVersionMinSupportedWorkflow.php index b00a2f63..0f54d796 100644 --- a/tests/Fixtures/TestVersionMinSupportedWorkflow.php +++ b/tests/Fixtures/TestVersionMinSupportedWorkflow.php @@ -4,9 +4,8 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, getVersion}; class TestVersionMinSupportedWorkflow extends Workflow { @@ -17,15 +16,15 @@ class TestVersionMinSupportedWorkflow extends Workflow public function execute() { // minSupported is 1, so DEFAULT_VERSION (-1) is no longer supported - $version = yield WorkflowStub::getVersion( + $version = yield getVersion( 'step-1', 1, // minSupported: we dropped support for DEFAULT_VERSION 2 // maxSupported: current version ); $result = match ($version) { - 1 => yield ActivityStub::make(TestVersionedActivityV2::class), - 2 => yield ActivityStub::make(TestVersionedActivityV3::class), + 1 => yield activity(TestVersionedActivityV2::class), + 2 => yield activity(TestVersionedActivityV3::class), }; return [ diff --git a/tests/Fixtures/TestVersionWorkflow.php b/tests/Fixtures/TestVersionWorkflow.php index 50505c04..b6666013 100644 --- a/tests/Fixtures/TestVersionWorkflow.php +++ b/tests/Fixtures/TestVersionWorkflow.php @@ -4,9 +4,9 @@ namespace Tests\Fixtures; -use Workflow\ActivityStub; use Workflow\Workflow; use Workflow\WorkflowStub; +use function Workflow\{activity, getVersion}; class TestVersionWorkflow extends Workflow { @@ -16,15 +16,15 @@ class TestVersionWorkflow extends Workflow public function execute() { - $version = yield WorkflowStub::getVersion('step-1', WorkflowStub::DEFAULT_VERSION, 2); + $version = yield getVersion('step-1', WorkflowStub::DEFAULT_VERSION, 2); $result = match ($version) { - WorkflowStub::DEFAULT_VERSION => yield ActivityStub::make(TestVersionedActivityV1::class), - 1 => yield ActivityStub::make(TestVersionedActivityV2::class), - 2 => yield ActivityStub::make(TestVersionedActivityV3::class), + WorkflowStub::DEFAULT_VERSION => yield activity(TestVersionedActivityV1::class), + 1 => yield activity(TestVersionedActivityV2::class), + 2 => yield activity(TestVersionedActivityV3::class), }; - $version2 = yield WorkflowStub::getVersion('step-2', WorkflowStub::DEFAULT_VERSION, 1); + $version2 = yield getVersion('step-2', WorkflowStub::DEFAULT_VERSION, 1); $result2 = $version2 === WorkflowStub::DEFAULT_VERSION ? 'old_path' diff --git a/tests/Fixtures/TestWebhookWorkflow.php b/tests/Fixtures/TestWebhookWorkflow.php index a500a543..1a893a84 100644 --- a/tests/Fixtures/TestWebhookWorkflow.php +++ b/tests/Fixtures/TestWebhookWorkflow.php @@ -5,12 +5,11 @@ namespace Tests\Fixtures; use Illuminate\Contracts\Foundation\Application; -use Workflow\ActivityStub; use Workflow\QueryMethod; use Workflow\SignalMethod; use Workflow\Webhook; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, await}; #[Webhook] class TestWebhookWorkflow extends Workflow @@ -42,15 +41,15 @@ public function execute(Application $app, $shouldAssert = false) assert(! $this->canceled); } - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); if ($shouldAssert) { assert(! $this->canceled); } - yield WorkflowStub::await(fn (): bool => $this->canceled); + yield await(fn (): bool => $this->canceled); - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); return 'workflow_' . $result . '_' . $otherResult; } diff --git a/tests/Fixtures/TestWorkflow.php b/tests/Fixtures/TestWorkflow.php index fe4b63c3..49c2e22f 100644 --- a/tests/Fixtures/TestWorkflow.php +++ b/tests/Fixtures/TestWorkflow.php @@ -5,12 +5,11 @@ namespace Tests\Fixtures; use Illuminate\Contracts\Foundation\Application; -use Workflow\ActivityStub; use Workflow\QueryMethod; use Workflow\SignalMethod; use Workflow\Webhook; use Workflow\Workflow; -use Workflow\WorkflowStub; +use function Workflow\{activity, await}; #[Webhook] class TestWorkflow extends Workflow @@ -42,11 +41,11 @@ public function execute(Application $app, $shouldAssert = false) assert(! $this->canceled); } - $otherResult = yield ActivityStub::make(TestOtherActivity::class, 'other'); + $otherResult = yield activity(TestOtherActivity::class, 'other'); - yield WorkflowStub::await(fn (): bool => $this->canceled); + yield await(fn (): bool => $this->canceled); - $result = yield ActivityStub::make(TestActivity::class); + $result = yield activity(TestActivity::class); return 'workflow_' . $result . '_' . $otherResult; } diff --git a/tests/Unit/FunctionsTest.php b/tests/Unit/FunctionsTest.php new file mode 100644 index 00000000..8bc9dd06 --- /dev/null +++ b/tests/Unit/FunctionsTest.php @@ -0,0 +1,386 @@ +start(); + + $workflow->approve(); + + $this->assertSame('approved', $workflow->output()); + } + + public function testTimerFunction(): void + { + WorkflowStub::mock(TestActivity::class, 'result'); + + $workflow = WorkflowStub::make(TestTimerWorkflow::class); + $workflow->start(); + + $this->assertNull($workflow->output()); + + $this->travel(2) + ->seconds(); + $workflow->resume(); + + $this->assertSame('result', $workflow->output()); + } + + public function testActivityFunction(): void + { + WorkflowStub::mock(TestActivity::class, 'activity_result'); + + $workflow = WorkflowStub::make(TestActivityWorkflow::class); + $workflow->start(); + + WorkflowStub::assertDispatched(TestActivity::class); + $this->assertSame('activity_result', $workflow->output()); + } + + public function testChildFunction(): void + { + WorkflowStub::mock(TestChildWorkflow::class, 'child_result'); + + $workflow = WorkflowStub::make(TestChildFunctionWorkflow::class); + $workflow->start(); + + WorkflowStub::assertDispatched(TestChildWorkflow::class); + $this->assertSame('child_result', $workflow->output()); + } + + public function testAllFunction(): void + { + WorkflowStub::mock(TestActivity::class, 'result1'); + + $workflow = WorkflowStub::make(TestAllWorkflow::class); + $workflow->start(); + + $this->assertIsArray($workflow->output()); + } + + public function testAsyncFunction(): void + { + $promise = async(static fn () => 'test'); + $this->assertInstanceOf(PromiseInterface::class, $promise); + } + + public function testSecondsFunction(): void + { + WorkflowStub::mock(TestActivity::class, 'result'); + + $workflow = WorkflowStub::make(TestSecondsWorkflow::class); + $workflow->start(); + + $this->assertNull($workflow->output()); + + $this->travel(30) + ->seconds(); + $workflow->resume(); + + $this->assertSame('result', $workflow->output()); + } + + public function testMinutesFunction(): void + { + WorkflowStub::mock(TestActivity::class, 'result'); + + $workflow = WorkflowStub::make(TestMinutesWorkflow::class); + $workflow->start(); + + $this->assertNull($workflow->output()); + + $this->travel(5) + ->minutes(); + $workflow->resume(); + + $this->assertSame('result', $workflow->output()); + } + + public function testHoursFunction(): void + { + WorkflowStub::mock(TestActivity::class, 'result'); + + $workflow = WorkflowStub::make(TestHoursWorkflow::class); + $workflow->start(); + + $this->assertNull($workflow->output()); + + $this->travel(2) + ->hours(); + $workflow->resume(); + + $this->assertSame('result', $workflow->output()); + } + + public function testDaysFunction(): void + { + WorkflowStub::mock(TestActivity::class, 'result'); + + $workflow = WorkflowStub::make(TestDaysWorkflow::class); + $workflow->start(); + + $this->assertNull($workflow->output()); + + $this->travel(1) + ->days(); + $workflow->resume(); + + $this->assertSame('result', $workflow->output()); + } + + public function testWeeksFunction(): void + { + WorkflowStub::mock(TestActivity::class, 'result'); + + $workflow = WorkflowStub::make(TestWeeksWorkflow::class); + $workflow->start(); + + $this->assertNull($workflow->output()); + + $this->travel(1) + ->weeks(); + $workflow->resume(); + + $this->assertSame('result', $workflow->output()); + } + + public function testMonthsFunction(): void + { + WorkflowStub::mock(TestActivity::class, 'result'); + + $workflow = WorkflowStub::make(TestMonthsWorkflow::class); + $workflow->start(); + + $this->assertNull($workflow->output()); + + $this->travel(1) + ->months(); + $workflow->resume(); + + $this->assertSame('result', $workflow->output()); + } + + public function testYearsFunction(): void + { + WorkflowStub::mock(TestActivity::class, 'result'); + + $workflow = WorkflowStub::make(TestYearsWorkflow::class); + $workflow->start(); + + $this->assertNull($workflow->output()); + + $this->travel(1) + ->years(); + $workflow->resume(); + + $this->assertSame('result', $workflow->output()); + } + + public function testAwaitWithTimeoutFunction(): void + { + $workflow = WorkflowStub::make(TestAwaitWithTimeoutWorkflow::class); + $workflow->start(); + + $workflow->approve(); + + $this->assertSame('approved', $workflow->output()); + } + + public function testSideEffectFunction(): void + { + $workflow = WorkflowStub::make(TestSideEffectWorkflow::class); + $workflow->start(); + + $this->assertSame('side_effect_result', $workflow->output()); + } + + public function testContinueAsNewFunction(): void + { + $promise = continueAsNew(); + $this->assertInstanceOf(PromiseInterface::class, $promise); + } + + public function testGetVersionFunction(): void + { + $workflow = WorkflowStub::make(TestGetVersionWorkflow::class); + $workflow->start(); + + $this->assertSame('completed', $workflow->output()); + } +} + +class TestAwaitWorkflow extends Workflow +{ + public bool $approved = false; + + #[SignalMethod] + public function approve(): void + { + $this->approved = true; + } + + public function execute() + { + yield await(fn () => $this->approved); + return 'approved'; + } +} + +class TestTimerWorkflow extends Workflow +{ + public function execute() + { + yield timer(1); + return yield activity(TestActivity::class); + } +} + +class TestActivityWorkflow extends Workflow +{ + public function execute() + { + return yield activity(TestActivity::class); + } +} + +class TestChildFunctionWorkflow extends Workflow +{ + public function execute() + { + return yield child(TestChildWorkflow::class); + } +} + +class TestAllWorkflow extends Workflow +{ + public function execute() + { + return yield all([activity(TestActivity::class), activity(TestActivity::class)]); + } +} + +class TestSecondsWorkflow extends Workflow +{ + public function execute() + { + yield seconds(30); + return yield activity(TestActivity::class); + } +} + +class TestMinutesWorkflow extends Workflow +{ + public function execute() + { + yield minutes(5); + return yield activity(TestActivity::class); + } +} + +class TestHoursWorkflow extends Workflow +{ + public function execute() + { + yield hours(2); + return yield activity(TestActivity::class); + } +} + +class TestDaysWorkflow extends Workflow +{ + public function execute() + { + yield days(1); + return yield activity(TestActivity::class); + } +} + +class TestWeeksWorkflow extends Workflow +{ + public function execute() + { + yield weeks(1); + return yield activity(TestActivity::class); + } +} + +class TestMonthsWorkflow extends Workflow +{ + public function execute() + { + yield months(1); + return yield activity(TestActivity::class); + } +} + +class TestYearsWorkflow extends Workflow +{ + public function execute() + { + yield years(1); + return yield activity(TestActivity::class); + } +} + +class TestAwaitWithTimeoutWorkflow extends Workflow +{ + public bool $approved = false; + + #[SignalMethod] + public function approve(): void + { + $this->approved = true; + } + + public function execute() + { + yield awaitWithTimeout(60, fn () => $this->approved); + return 'approved'; + } +} + +class TestSideEffectWorkflow extends Workflow +{ + public function execute() + { + return yield sideEffect(static fn () => 'side_effect_result'); + } +} + +class TestContinueAsNewWorkflow extends Workflow +{ + public function execute() + { + return yield continueAsNew(); + } +} + +class TestGetVersionWorkflow extends Workflow +{ + public function execute() + { + yield getVersion('test_change', 1, 2); + return 'completed'; + } +}