diff --git a/tests/Feature/WorkflowTest.php b/tests/Feature/WorkflowTest.php index f85bdb7..316ce29 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 16d6ce5..8ee3c66 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 378e0fe..be164a4 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 b9b9214..e4dcff2 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 4c60a06..40940a8 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 06e691d..5028b0c 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 be5b031..c902983 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');