From 913ef862fc165325f9e87e75b867ebb3fba5441b Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Sun, 23 Mar 2025 02:15:29 +0000 Subject: [PATCH] Improve test coverage --- tests/Fixtures/TestThrowOnReturnWorkflow.php | 20 ++++++++ .../Fixtures/TestYieldNonPromiseWorkflow.php | 15 ++++++ tests/Unit/WorkflowTest.php | 51 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 tests/Fixtures/TestThrowOnReturnWorkflow.php create mode 100644 tests/Fixtures/TestYieldNonPromiseWorkflow.php diff --git a/tests/Fixtures/TestThrowOnReturnWorkflow.php b/tests/Fixtures/TestThrowOnReturnWorkflow.php new file mode 100644 index 0000000..7ee9360 --- /dev/null +++ b/tests/Fixtures/TestThrowOnReturnWorkflow.php @@ -0,0 +1,20 @@ +assertSame(WorkflowCompletedStatus::class, $childWorkflow->status()); $this->assertSame('other', $childWorkflow->output()); } + + public function testThrowsWhenExecuteMethodIsMissing(): void + { + $stub = WorkflowStub::load(WorkflowStub::make(TestWorkflow::class)->id()); + $storedWorkflow = StoredWorkflow::findOrFail($stub->id()); + $storedWorkflow->update([ + 'arguments' => Serializer::serialize([]), + 'status' => WorkflowPendingStatus::class, + ]); + + $this->expectException(BadMethodCallException::class); + $this->expectExceptionMessage('Execute method not implemented.'); + + $workflow = new Workflow($storedWorkflow); + $workflow->handle(); + } + + public function testThrowsWhenYieldNonPromise(): void + { + $stub = WorkflowStub::load(WorkflowStub::make(TestYieldNonPromiseWorkflow::class)->id()); + $storedWorkflow = StoredWorkflow::findOrFail($stub->id()); + $storedWorkflow->update([ + 'arguments' => Serializer::serialize([]), + 'status' => WorkflowPendingStatus::class, + ]); + + $this->expectException(\Exception::class); + $this->expectExceptionMessage('something went wrong'); + + $workflow = new TestYieldNonPromiseWorkflow($storedWorkflow); + $workflow->handle(); + } + + public function testThrowsWrappedException(): void + { + $stub = WorkflowStub::load(WorkflowStub::make(TestThrowOnReturnWorkflow::class)->id()); + $storedWorkflow = StoredWorkflow::findOrFail($stub->id()); + $storedWorkflow->update([ + 'arguments' => Serializer::serialize([]), + 'status' => WorkflowPendingStatus::class, + ]); + + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Workflow failed.'); + + $workflow = new TestThrowOnReturnWorkflow($storedWorkflow); + $workflow->handle(); + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy