|
33 | 33 | });
|
34 | 34 |
|
35 | 35 | test('it creates the first status for a newly created model', function () {
|
36 |
| - (new WorkflowableModel())->save(); |
| 36 | + (new WorkflowableModel)->save(); |
37 | 37 | expect(WorkflowModelStatus::count())->toBe(0);
|
38 | 38 |
|
39 |
| - ($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 39 | + ($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
40 | 40 | expect(WorkflowModelStatus::first())
|
41 | 41 | ->count()->toBe(1)
|
42 | 42 | ->model->id->toBe($model->id);
|
43 | 43 | });
|
44 | 44 |
|
45 | 45 | test('it gets the status(es) of a model', function () {
|
46 |
| - ($modelA = new WorkflowableModel())->save(); |
| 46 | + ($modelA = new WorkflowableModel)->save(); |
47 | 47 | expect($modelA->modelStatuses)->toHaveCount(0);
|
48 | 48 |
|
49 |
| - ($modelB = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 49 | + ($modelB = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
50 | 50 | $status = $modelB->getDefaultWorkflow()->entryTransitions->first()->toStatus;
|
51 | 51 |
|
52 | 52 | expect($modelB->modelStatus->status)->toEqual($modelB->getStatus())->toEqual($status)
|
|
55 | 55 | });
|
56 | 56 |
|
57 | 57 | test('it can transition a model', function () {
|
58 |
| - ($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 58 | + ($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
59 | 59 | $transitions = $model->possibleTransitions();
|
60 | 60 |
|
61 | 61 | expect($transitions)->toHaveCount(1);
|
|
67 | 67 | });
|
68 | 68 |
|
69 | 69 | test('it fails transition if not valid', function () {
|
70 |
| - ($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 70 | + ($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
71 | 71 | $transitions = $model->possibleTransitions();
|
72 | 72 |
|
73 | 73 | expect(fn () => $model->transitionTo($transitions->first()->fromStatus))
|
74 | 74 | ->toThrow(InvalidTransitionException::class);
|
75 | 75 | });
|
76 | 76 |
|
77 | 77 | test('it can filter model with specific status', function () {
|
78 |
| - (new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 78 | + (new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
79 | 79 |
|
80 | 80 | expect(WorkflowableModel::inStatus($this->entry->toStatus, $this->workflow)->get())->toHaveCount(1)
|
81 | 81 | ->and(WorkflowableModel::inStatus($this->mid1->toStatus->id, $this->workflow)->get())->toHaveCount(0);
|
82 | 82 | });
|
83 | 83 |
|
84 | 84 | test('it checks if a transition is allowed', function () {
|
85 |
| - ($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 85 | + ($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
86 | 86 |
|
87 | 87 | expect($model->isAllowed($this->mid1))->toBeTrue()
|
88 | 88 | ->and($model->isAllowed($this->entry->toStatus))->toBeFalse();
|
|
93 | 93 | });
|
94 | 94 |
|
95 | 95 | test('it has toString', function () {
|
96 |
| - ($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save(); |
| 96 | + ($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save(); |
97 | 97 |
|
98 | 98 | expect($model->getCurrentWorkflow()?->__toString())->toBe($model->getCurrentWorkflow()->name);
|
99 | 99 | expect($model->possibleTransitions()->first()->__toString())->toContain($model->getCurrentWorkflow()?->__toString());
|
|
0 commit comments