Skip to content

Commit

Permalink
Add Venture custom model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman authored and ksassnowski committed Apr 10, 2022
1 parent 8af12eb commit 548a2a9
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/Stubs/CustomWorkflowJobModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021 Kai Sassnowski
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ksassnowski/venture
*/

namespace Stubs;

use Sassnowski\Venture\Models\WorkflowJob;

class CustomWorkflowJobModel extends WorkflowJob
{
}
20 changes: 20 additions & 0 deletions tests/Stubs/CustomWorkflowModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021 Kai Sassnowski
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ksassnowski/venture
*/

namespace Stubs;

use Sassnowski\Venture\Models\Workflow;

class CustomWorkflowModel extends Workflow
{
}
27 changes: 27 additions & 0 deletions tests/Stubs/TestJobWithHandle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021 Kai Sassnowski
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ksassnowski/venture
*/

namespace Stubs;

use Illuminate\Contracts\Queue\ShouldQueue;
use Sassnowski\Venture\WorkflowStep;

class TestJobWithHandle implements ShouldQueue
{
use WorkflowStep;

public function handle()
{
return true;
}
}
27 changes: 27 additions & 0 deletions tests/Stubs/WorkflowWithJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021 Kai Sassnowski
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ksassnowski/venture
*/

namespace Stubs;

use Sassnowski\Venture\AbstractWorkflow;
use Sassnowski\Venture\WorkflowDefinition;

class WorkflowWithJob extends AbstractWorkflow
{
public function definition(): WorkflowDefinition
{
return (new WorkflowDefinition)->addJob(
new TestJobWithHandle
);
}
}
55 changes: 55 additions & 0 deletions tests/VentureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021 Kai Sassnowski
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ksassnowski/venture
*/

use Sassnowski\Venture\Models\Workflow;
use Sassnowski\Venture\Models\WorkflowJob;
use Sassnowski\Venture\Venture;
use Stubs\CustomWorkflowJobModel;
use Stubs\CustomWorkflowModel;
use Stubs\WorkflowWithJob;
use function PHPUnit\Framework\assertCount;
use function PHPUnit\Framework\assertInstanceOf;
use function PHPUnit\Framework\assertNotInstanceOf;

uses(TestCase::class);

afterEach(function () {
Venture::useWorkflowModel(Workflow::class);
Venture::useWorkflowJobModel(WorkflowJob::class);
});

it('can override workflow model', function () {
Venture::useWorkflowModel(CustomWorkflowModel::class);

assertInstanceOf(CustomWorkflowModel::class, WorkflowWithJob::start());
});

it('can override workflow job model', function () {
Venture::useWorkflowJobModel(CustomWorkflowJobModel::class);

assertInstanceOf(Workflow::class, $workflow = WorkflowWithJob::start());
assertCount(1, $jobs = $workflow->jobs()->get());
assertInstanceOf(CustomWorkflowJobModel::class, $job = $jobs->first());
assertInstanceOf(Workflow::class, $job->workflow);
assertNotInstanceOf(CustomWorkflowModel::class, $job->workflow);
});

it('can override workflow and job model', function () {
Venture::useWorkflowModel(CustomWorkflowModel::class);
Venture::useWorkflowJobModel(CustomWorkflowJobModel::class);

assertInstanceOf(CustomWorkflowModel::class, $workflow = WorkflowWithJob::start());
assertCount(1, $jobs = $workflow->jobs()->get());
assertInstanceOf(CustomWorkflowJobModel::class, $job = $jobs->first());
assertInstanceOf(CustomWorkflowModel::class, $job->workflow);
});

0 comments on commit 548a2a9

Please sign in to comment.