Skip to content

Commit cad36f0

Browse files
committed
Fix
1 parent 4d9677e commit cad36f0

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/Traits/HasWorkflows.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
trait HasWorkflows
2929
{
30-
protected ?Workflow $usingWorkflow = null;
30+
protected static ?Workflow $usingWorkflow = null;
3131

3232
public static function bootHasWorkflows(): void
3333
{
@@ -89,7 +89,7 @@ public function getDefaultWorkflowName(): ?string
8989

9090
public function usingWorkflow(null|int|Workflow $workflow): static
9191
{
92-
$this->usingWorkflow = $workflow instanceof Workflow ? $workflow : Workflow::find($workflow);
92+
self::$usingWorkflow = $workflow instanceof Workflow ? $workflow : Workflow::find($workflow);
9393

9494
$this->unsetRelation('modelStatus');
9595
$this->unsetRelation('modelStatuses');
@@ -100,7 +100,7 @@ public function usingWorkflow(null|int|Workflow $workflow): static
100100

101101
public function getCurrentWorkflow(): ?Workflow
102102
{
103-
return $this->usingWorkflow ?? $this->getDefaultWorkflow();
103+
return self::$usingWorkflow ?? $this->getDefaultWorkflow();
104104
}
105105

106106
/**

tests/Feature/MultipleWorkflowTest.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,24 @@
3333
($modelA = new WorkflowableModel)->setDefaultWorkflowName($this->workflowA->name)->save();
3434
($modelB = new WorkflowableModel)->setDefaultWorkflowName($this->workflowB->name)->save();
3535

36+
$modelA->usingWorkflow($modelA->getDefaultWorkflow());
3637
expect($modelA->modelStatus->workflow)->id->toBe($this->workflowA->id);
37-
expect($modelB->modelStatus->workflow)->id->toEqual($this->workflowB->id);
38-
3938
expect($modelA->transition($this->entryA_to_A1))
4039
->modelStatus->status->toEqual($this->entryA_to_A1->toStatus);
41-
expect($modelB->transition($this->entryB_to_B1))
42-
->modelStatus->status->toEqual($this->entryB_to_B1->toStatus);
43-
4440
expect($modelA->possibleTransitions())->toHaveCount(2);
45-
expect($modelB->possibleTransitions())->toHaveCount(2);
46-
4741
expect($modelA->transition($this->A1_to_exitA))
4842
->modelStatus->status->toEqual($this->A1_to_exitA->toStatus);
43+
expect($modelA->possibleTransitions())->toHaveCount(0);
44+
expect($modelA->isInFinalStatus())->toBeTrue();
45+
46+
$modelB->usingWorkflow($modelB->getDefaultWorkflow());
47+
expect($modelB->modelStatus->workflow)->id->toEqual($this->workflowB->id);
48+
expect($modelB->transition($this->entryB_to_B1))
49+
->modelStatus->status->toEqual($this->entryB_to_B1->toStatus);
50+
expect($modelB->possibleTransitions())->toHaveCount(2);
4951
expect($modelB->transition($this->B1_to_B2))
5052
->modelStatus->status->toEqual($this->B1_to_B2->toStatus);
51-
52-
expect($modelA->possibleTransitions())->toHaveCount(0);
5353
expect($modelB->possibleTransitions())->toHaveCount(1);
54-
55-
expect($modelA->isInFinalStatus())->toBeTrue();
5654
expect($modelB->isInFinalStatus())->toBeFalse();
5755
});
5856

0 commit comments

Comments
 (0)