Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/ChildWorkflowStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ public static function make($workflow, ...$arguments): PromiseInterface
->contains(static fn ($argument): bool => $argument instanceof WorkflowOptions);

if (! $hasOptions) {
$options = new WorkflowOptions(
$context->storedWorkflow->effectiveConnection(),
$context->storedWorkflow->effectiveQueue()
);
$options = $context->storedWorkflow->workflowOptions();

if ($options->connection !== null || $options->queue !== null) {
$arguments[] = $options;
Expand Down
81 changes: 69 additions & 12 deletions tests/Unit/ChildWorkflowStubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,9 @@ public function startAsChild(...$arguments): void
$storedWorkflow->shouldReceive('children')
->once()
->andReturn($children);
$storedWorkflow->shouldReceive('effectiveConnection')
$storedWorkflow->shouldReceive('workflowOptions')
->once()
->andReturn(null);
$storedWorkflow->shouldReceive('effectiveQueue')
->once()
->andReturn(null);
->andReturn(new WorkflowOptions());

WorkflowStub::setContext([
'storedWorkflow' => $storedWorkflow,
Expand All @@ -164,20 +161,16 @@ public function startAsChild(...$arguments): void
public function testUsesParentContextForInheritedWorkflowOptions(): void
{
$childContextStoredWorkflow = Mockery::mock();
$childContextStoredWorkflow->shouldNotReceive('effectiveConnection');
$childContextStoredWorkflow->shouldNotReceive('effectiveQueue');
$childContextStoredWorkflow->shouldNotReceive('workflowOptions');

$parentStoredWorkflow = Mockery::mock();
$parentStoredWorkflow->shouldReceive('findLogByIndex')
->once()
->with(0)
->andReturn(null);
$parentStoredWorkflow->shouldReceive('effectiveConnection')
->once()
->andReturn('sync');
$parentStoredWorkflow->shouldReceive('effectiveQueue')
$parentStoredWorkflow->shouldReceive('workflowOptions')
->once()
->andReturn('parent-queue');
->andReturn(new WorkflowOptions('sync', 'parent-queue'));

$childWorkflow = Mockery::mock();
$childWorkflow->shouldReceive('running')
Expand Down Expand Up @@ -244,6 +237,70 @@ static function (...$arguments) use ($parentStoredWorkflow): bool {
$this->assertSame($parentStoredWorkflow, WorkflowStub::getContext()->storedWorkflow);
}

public function testDoesNotPassWorkflowOptionsWhenParentOptionsAreUnset(): void
{
$parentStoredWorkflow = Mockery::mock();
$parentStoredWorkflow->shouldReceive('findLogByIndex')
->once()
->with(0)
->andReturn(null);
$parentStoredWorkflow->shouldReceive('workflowOptions')
->once()
->andReturn(new WorkflowOptions());

$childWorkflow = Mockery::mock();
$childWorkflow->shouldReceive('running')
->once()
->andReturn(false);
$childWorkflow->shouldReceive('completed')
->once()
->andReturn(false);
$childWorkflow->shouldReceive('startAsChild')
->once()
->withArgs(
static function (...$arguments) use ($parentStoredWorkflow): bool {
if (count($arguments) !== 3) {
return false;
}

[$parentWorkflow, $index, $_now] = $arguments;

return $parentWorkflow === $parentStoredWorkflow
&& $index === 0;
}
);

$storedChildWorkflow = Mockery::mock();
$storedChildWorkflow->shouldReceive('toWorkflow')
->once()
->andReturn($childWorkflow);

$children = Mockery::mock();
$children->shouldReceive('wherePivot')
->once()
->with('parent_index', 0)
->andReturnSelf();
$children->shouldReceive('first')
->once()
->andReturn($storedChildWorkflow);

$parentStoredWorkflow->shouldReceive('children')
->once()
->andReturn($children);

WorkflowStub::setContext([
'storedWorkflow' => $parentStoredWorkflow,
'index' => 0,
'now' => now(),
'replaying' => false,
]);

ChildWorkflowStub::make(TestChildWorkflow::class);

$this->assertSame(1, WorkflowStub::getContext()->index);
$this->assertSame($parentStoredWorkflow, WorkflowStub::getContext()->storedWorkflow);
}

public function testAll(): void
{
$workflow = WorkflowStub::load(WorkflowStub::make(TestParentWorkflow::class)->id());
Expand Down