|
37 | 37 | }); |
38 | 38 |
|
39 | 39 | test('it creates the first status for a newly created model', function () { |
40 | | - (new WorkflowableModel())->save(); |
| 40 | + (new WorkflowableModel)->save(); |
41 | 41 | expect(WorkflowModelStatus::count())->toBe(0); |
42 | 42 |
|
43 | | - ($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 43 | + ($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
44 | 44 | expect(WorkflowModelStatus::first()) |
45 | 45 | ->count()->toBe(1) |
46 | 46 | ->model->id->toBe($model->id); |
47 | 47 | }); |
48 | 48 |
|
49 | 49 | test('it gets the status(es) of a model', function () { |
50 | | - ($modelA = new WorkflowableModel())->save(); |
| 50 | + ($modelA = new WorkflowableModel)->save(); |
51 | 51 | expect($modelA->modelStatuses)->toHaveCount(0); |
52 | 52 |
|
53 | | - ($modelB = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 53 | + ($modelB = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
54 | 54 | $status = $modelB->getDefaultWorkflow()->entryTransitions->first()->toStatus; |
55 | 55 |
|
56 | 56 | expect($modelB->modelStatus->status)->toEqual($modelB->getStatus())->toEqual($status) |
|
59 | 59 | }); |
60 | 60 |
|
61 | 61 | test('it can transition a model', function () { |
62 | | - ($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 62 | + ($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
63 | 63 | $transitions = $model->possibleTransitions(); |
64 | 64 |
|
65 | 65 | expect($transitions)->toHaveCount(1); |
|
71 | 71 | }); |
72 | 72 |
|
73 | 73 | test('it fails transition if not valid', function () { |
74 | | - ($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 74 | + ($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
75 | 75 | $transitions = $model->possibleTransitions(); |
76 | 76 |
|
77 | 77 | expect(fn () => $model->transitionTo($transitions->first()->fromStatus)) |
78 | 78 | ->toThrow(InvalidTransitionException::class); |
79 | 79 | }); |
80 | 80 |
|
81 | 81 | test('it can filter model with specific status', function () { |
82 | | - (new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 82 | + (new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
83 | 83 |
|
84 | 84 | expect(WorkflowableModel::inStatus($this->entry->toStatus, $this->workflow)->get())->toHaveCount(1) |
85 | 85 | ->and(WorkflowableModel::inStatus($this->mid1->toStatus->id, $this->workflow)->get())->toHaveCount(0); |
86 | 86 | }); |
87 | 87 |
|
88 | 88 | test('it checks if a transition is allowed', function () { |
89 | | - ($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 89 | + ($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
90 | 90 |
|
91 | 91 | expect($model->isAllowed($this->mid1))->toBeTrue() |
92 | 92 | ->and($model->isAllowed($this->entry->toStatus))->toBeFalse(); |
|
112 | 112 | }); |
113 | 113 |
|
114 | 114 | test('it has toString', function () { |
115 | | - ($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 115 | + ($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
116 | 116 |
|
117 | 117 | expect($model->getCurrentWorkflow()?->__toString())->toBe($model->getCurrentWorkflow()->name); |
118 | 118 | expect($model->possibleTransitions()->first()->__toString())->toContain($model->getCurrentWorkflow()?->__toString()); |
|
0 commit comments