Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagof committed Sep 27, 2024
2 parents 570e189 + a50c7b2 commit f19fcdf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Traits/HasWorkflows.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function isInFinalStatus(): bool
protected function createModelStatus(Workflow $workflow, WorkflowStatus $status): WorkflowModelStatus
{
$wmsClass = config('workflow.workflow_model_status_class');
$modelStatus = new $wmsClass();
$modelStatus = new $wmsClass;
$modelStatus->model()->associate($this);
$modelStatus->user()->associate(Auth::user());
$modelStatus->workflow()->associate($workflow);
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/MultipleWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
});

test('it supports multiple models', function () {
($modelA = new WorkflowableModel())->setDefaultWorkflowName($this->workflowA->name)->save();
($modelB = new WorkflowableModel())->setDefaultWorkflowName($this->workflowB->name)->save();
($modelA = new WorkflowableModel)->setDefaultWorkflowName($this->workflowA->name)->save();
($modelB = new WorkflowableModel)->setDefaultWorkflowName($this->workflowB->name)->save();

expect($modelA->modelStatus->workflow)->id->toBe($this->workflowA->id);
expect($modelB->modelStatus->workflow)->id->toEqual($this->workflowB->id);
Expand All @@ -57,7 +57,7 @@
});

test('a model can have multiple workflows', function () {
($modelA = new WorkflowableModel())->setDefaultWorkflowName($this->workflowA->name)->save();
($modelA = new WorkflowableModel)->setDefaultWorkflowName($this->workflowA->name)->save();
$modelA->transition($this->entryA_to_A1);

expect($modelA->usingWorkflow($this->workflowB)->getCurrentWorkflow())
Expand Down
18 changes: 9 additions & 9 deletions tests/Feature/WorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@
});

test('it creates the first status for a newly created model', function () {
(new WorkflowableModel())->save();
(new WorkflowableModel)->save();
expect(WorkflowModelStatus::count())->toBe(0);

($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save();
($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save();
expect(WorkflowModelStatus::first())
->count()->toBe(1)
->model->id->toBe($model->id);
});

test('it gets the status(es) of a model', function () {
($modelA = new WorkflowableModel())->save();
($modelA = new WorkflowableModel)->save();
expect($modelA->modelStatuses)->toHaveCount(0);

($modelB = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save();
($modelB = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save();
$status = $modelB->getDefaultWorkflow()->entryTransitions->first()->toStatus;

expect($modelB->modelStatus->status)->toEqual($modelB->getStatus())->toEqual($status)
Expand All @@ -59,7 +59,7 @@
});

test('it can transition a model', function () {
($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save();
($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save();
$transitions = $model->possibleTransitions();

expect($transitions)->toHaveCount(1);
Expand All @@ -71,22 +71,22 @@
});

test('it fails transition if not valid', function () {
($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save();
($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save();
$transitions = $model->possibleTransitions();

expect(fn () => $model->transitionTo($transitions->first()->fromStatus))
->toThrow(InvalidTransitionException::class);
});

test('it can filter model with specific status', function () {
(new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save();
(new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save();

expect(WorkflowableModel::inStatus($this->entry->toStatus, $this->workflow)->get())->toHaveCount(1)
->and(WorkflowableModel::inStatus($this->mid1->toStatus->id, $this->workflow)->get())->toHaveCount(0);
});

test('it checks if a transition is allowed', function () {
($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save();
($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save();

expect($model->isAllowed($this->mid1))->toBeTrue()
->and($model->isAllowed($this->entry->toStatus))->toBeFalse();
Expand All @@ -112,7 +112,7 @@
});

test('it has toString', function () {
($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save();
($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save();

expect($model->getCurrentWorkflow()?->__toString())->toBe($model->getCurrentWorkflow()->name);
expect($model->possibleTransitions()->first()->__toString())->toContain($model->getCurrentWorkflow()?->__toString());
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/WorkflowsPermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
});

test('it can transition if no permissions are defined', function () {
($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save();
($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save();
/** @var \Squarebit\Workflows\Models\WorkflowTransition $transition */
$transition = $model->possibleTransitions()->first();

Expand All @@ -32,7 +32,7 @@
});

test('it cannot transition if user is missing necessary permissions', function () {
($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save();
($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save();
/** @var \Squarebit\Workflows\Models\WorkflowTransition $transition */
$transition = $model->possibleTransitions()->first();

Expand All @@ -42,7 +42,7 @@
});

test('it can transition when user has necessary permission', function () {
($model = new WorkflowableModel())->setDefaultWorkflowName($this->workflow->name)->save();
($model = new WorkflowableModel)->setDefaultWorkflowName($this->workflow->name)->save();
/** @var \Squarebit\Workflows\Models\WorkflowTransition $transition */
$transition = $model->possibleTransitions()->first();

Expand Down
4 changes: 2 additions & 2 deletions tests/Support/2000_01_01_000000_create_permission_tables.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Spatie\Permission\PermissionRegistrar;

class CreatePermissionTables extends Migration
Expand Down

0 comments on commit f19fcdf

Please sign in to comment.