|
4 | 4 |
|
5 | 5 | namespace Tests\Unit; |
6 | 6 |
|
| 7 | +use Exception; |
7 | 8 | use Mockery; |
8 | 9 | use Tests\Fixtures\TestChildWorkflow; |
| 10 | +use Tests\Fixtures\TestExceptionWorkflow; |
9 | 11 | use Tests\Fixtures\TestParentWorkflow; |
10 | 12 | use Tests\TestCase; |
11 | 13 | use Workflow\ChildWorkflowStub; |
| 14 | +use Workflow\Exception as WorkflowException; |
12 | 15 | use Workflow\Models\StoredWorkflow; |
13 | 16 | use Workflow\Serializers\Serializer; |
14 | 17 | use Workflow\States\WorkflowPendingStatus; |
@@ -91,6 +94,43 @@ public function testLoadsChildWorkflow(): void |
91 | 94 | $this->assertNull($result); |
92 | 95 | } |
93 | 96 |
|
| 97 | + public function testSkipsStoredExceptionForDifferentSourceClass(): void |
| 98 | + { |
| 99 | + $workflow = WorkflowStub::load(WorkflowStub::make(TestParentWorkflow::class)->id()); |
| 100 | + $storedWorkflow = StoredWorkflow::findOrFail($workflow->id()); |
| 101 | + $storedWorkflow->update([ |
| 102 | + 'arguments' => Serializer::serialize([]), |
| 103 | + 'status' => WorkflowPendingStatus::$name, |
| 104 | + ]); |
| 105 | + $storedWorkflow->logs() |
| 106 | + ->create([ |
| 107 | + 'index' => 0, |
| 108 | + 'now' => WorkflowStub::now(), |
| 109 | + 'class' => WorkflowException::class, |
| 110 | + 'result' => Serializer::serialize([ |
| 111 | + 'class' => Exception::class, |
| 112 | + 'message' => 'foreign child', |
| 113 | + 'code' => 0, |
| 114 | + 'sourceClass' => TestExceptionWorkflow::class, |
| 115 | + ]), |
| 116 | + ]); |
| 117 | + $storedWorkflow->logs() |
| 118 | + ->create([ |
| 119 | + 'index' => 1, |
| 120 | + 'now' => WorkflowStub::now(), |
| 121 | + 'class' => TestChildWorkflow::class, |
| 122 | + 'result' => Serializer::serialize('test'), |
| 123 | + ]); |
| 124 | + |
| 125 | + ChildWorkflowStub::make(TestChildWorkflow::class) |
| 126 | + ->then(static function ($value) use (&$result) { |
| 127 | + $result = $value; |
| 128 | + }); |
| 129 | + |
| 130 | + $this->assertSame('test', $result); |
| 131 | + $this->assertSame(2, WorkflowStub::getContext()->index); |
| 132 | + } |
| 133 | + |
94 | 134 | public function testDoesNotResumeRunningStartedChildWorkflow(): void |
95 | 135 | { |
96 | 136 | $childWorkflow = Mockery::mock(); |
|
0 commit comments