From 537389f4ae6e3061c97bb947184253bd18540a6b Mon Sep 17 00:00:00 2001 From: Durable Workflow Date: Tue, 24 Mar 2026 02:19:35 +0000 Subject: [PATCH] Stabilize workflow fixture assertions --- tests/Feature/WorkflowTest.php | 13 ++++++++----- tests/Fixtures/TestActivity.php | 5 ++++- tests/Fixtures/TestAsyncWorkflow.php | 5 ++++- tests/Fixtures/TestBadConnectionWorkflow.php | 13 ++++++++++--- tests/Fixtures/TestOtherActivity.php | 5 ++++- tests/Fixtures/TestWebhookWorkflow.php | 13 ++++++++++--- tests/Fixtures/TestWorkflow.php | 9 +++++++-- 7 files changed, 47 insertions(+), 16 deletions(-) diff --git a/tests/Feature/WorkflowTest.php b/tests/Feature/WorkflowTest.php index f85bdb76..316ce29a 100644 --- a/tests/Feature/WorkflowTest.php +++ b/tests/Feature/WorkflowTest.php @@ -51,11 +51,14 @@ public function testCompletedDelay(): void $this->assertSame(WorkflowCompletedStatus::class, $workflow->status()); $this->assertSame('workflow_activity_other', $workflow->output()); - $this->assertSame([TestActivity::class, TestOtherActivity::class, Signal::class], $workflow->logs() - ->pluck('class') - ->sort() - ->values() - ->toArray()); + $this->assertSame( + [TestActivity::class, TestOtherActivity::class, TestWorkflow::class, Signal::class], + $workflow->logs() + ->pluck('class') + ->sort() + ->values() + ->toArray() + ); } public function testTestSignalExceptionWorkflowEarly(): void diff --git a/tests/Fixtures/TestActivity.php b/tests/Fixtures/TestActivity.php index 16d6ce57..8ee3c660 100644 --- a/tests/Fixtures/TestActivity.php +++ b/tests/Fixtures/TestActivity.php @@ -4,6 +4,7 @@ namespace Tests\Fixtures; +use AssertionError; use Illuminate\Contracts\Foundation\Application; use Workflow\Activity; @@ -11,7 +12,9 @@ class TestActivity extends Activity { public function execute(Application $app) { - assert($app->runningInConsole()); + if (! $app->runningInConsole()) { + throw new AssertionError('Test activities must run in console.'); + } return 'activity'; } diff --git a/tests/Fixtures/TestAsyncWorkflow.php b/tests/Fixtures/TestAsyncWorkflow.php index 378e0fea..be164a4e 100644 --- a/tests/Fixtures/TestAsyncWorkflow.php +++ b/tests/Fixtures/TestAsyncWorkflow.php @@ -4,6 +4,7 @@ namespace Tests\Fixtures; +use AssertionError; use Illuminate\Contracts\Foundation\Application; use Workflow\Workflow; use function Workflow\{activity, async}; @@ -13,7 +14,9 @@ final class TestAsyncWorkflow extends Workflow public function execute() { $results = yield async(static function (Application $app) { - assert($app->runningInConsole()); + if (! $app->runningInConsole()) { + throw new AssertionError('Test workflows must run in console.'); + } $otherResult = yield activity(TestOtherActivity::class, 'other'); diff --git a/tests/Fixtures/TestBadConnectionWorkflow.php b/tests/Fixtures/TestBadConnectionWorkflow.php index b9b92146..e4dcff24 100644 --- a/tests/Fixtures/TestBadConnectionWorkflow.php +++ b/tests/Fixtures/TestBadConnectionWorkflow.php @@ -4,6 +4,7 @@ namespace Tests\Fixtures; +use AssertionError; use Illuminate\Contracts\Foundation\Application; use Workflow\QueryMethod; use Workflow\SignalMethod; @@ -32,16 +33,22 @@ public function isCanceled(): bool public function execute(Application $app, $shouldAssert = false) { - assert($app->runningInConsole()); + if (! $app->runningInConsole()) { + throw new AssertionError('Test workflows must run in console.'); + } if ($shouldAssert) { - assert(yield sideEffect(fn (): bool => ! $this->canceled)); + 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) { - assert(yield sideEffect(fn (): bool => ! $this->canceled)); + 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); diff --git a/tests/Fixtures/TestOtherActivity.php b/tests/Fixtures/TestOtherActivity.php index 4c60a064..40940a8f 100644 --- a/tests/Fixtures/TestOtherActivity.php +++ b/tests/Fixtures/TestOtherActivity.php @@ -4,6 +4,7 @@ namespace Tests\Fixtures; +use AssertionError; use Illuminate\Contracts\Foundation\Application; use Workflow\Activity; @@ -11,7 +12,9 @@ final class TestOtherActivity extends Activity { public function execute(Application $app, $string) { - assert($app->runningInConsole()); + if (! $app->runningInConsole()) { + throw new AssertionError('Test activities must run in console.'); + } return $string; } diff --git a/tests/Fixtures/TestWebhookWorkflow.php b/tests/Fixtures/TestWebhookWorkflow.php index 06e691d7..5028b0c1 100644 --- a/tests/Fixtures/TestWebhookWorkflow.php +++ b/tests/Fixtures/TestWebhookWorkflow.php @@ -4,6 +4,7 @@ namespace Tests\Fixtures; +use AssertionError; use Illuminate\Contracts\Foundation\Application; use Workflow\QueryMethod; use Workflow\SignalMethod; @@ -35,16 +36,22 @@ public function isCanceled(): bool public function execute(Application $app, $shouldAssert = false) { - assert($app->runningInConsole()); + if (! $app->runningInConsole()) { + throw new AssertionError('Test workflows must run in console.'); + } if ($shouldAssert) { - assert(yield sideEffect(fn (): bool => ! $this->canceled)); + 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) { - assert(yield sideEffect(fn (): bool => ! $this->canceled)); + 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); diff --git a/tests/Fixtures/TestWorkflow.php b/tests/Fixtures/TestWorkflow.php index be5b031d..c9029837 100644 --- a/tests/Fixtures/TestWorkflow.php +++ b/tests/Fixtures/TestWorkflow.php @@ -4,6 +4,7 @@ namespace Tests\Fixtures; +use AssertionError; use Illuminate\Contracts\Foundation\Application; use Workflow\QueryMethod; use Workflow\SignalMethod; @@ -35,10 +36,14 @@ public function isCanceled(): bool public function execute(Application $app, $shouldAssert = false) { - assert($app->runningInConsole()); + if (! $app->runningInConsole()) { + throw new AssertionError('Test workflows must run in console.'); + } if ($shouldAssert) { - assert(yield sideEffect(fn (): bool => ! $this->canceled)); + 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');