Skip to content

Commit

Permalink
feat: pass job to ClosureWorkflowStep callback
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Kai Sassnowski <me@kai-sassnowski.com>
  • Loading branch information
wit3 and ksassnowski committed Mar 10, 2023
1 parent 628043c commit 74a804b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ClosureWorkflowStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ final class ClosureWorkflowStep implements WorkflowableJob

private SerializableClosure $callback;

/**
* @param Closure(WorkflowableJob): void $callback
*/
public function __construct(Closure $callback)
{
$this->callback = new SerializableClosure($callback);
}

public function handle(): void
{
app()->call($this->callback->getClosure());
app()->call($this->callback->getClosure(), ['job' => $this]);
}
}
12 changes: 12 additions & 0 deletions tests/ClosureWorkflowStepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sassnowski\Venture\ClosureWorkflowStep;
use Sassnowski\Venture\Dispatcher\FakeDispatcher;
use Sassnowski\Venture\Dispatcher\JobDispatcher;
use Sassnowski\Venture\WorkflowableJob;

uses(TestCase::class);

Expand Down Expand Up @@ -52,3 +53,14 @@
$step = \unserialize(\serialize($step));
$step->handle();
});

it('passes the workflow step to the closure', function (): void {
$passedStep = null;
$step = new ClosureWorkflowStep(function (WorkflowableJob $job) use (&$passedStep): void {
$passedStep = $job;
});

$step->handle();

expect($passedStep)->toBe($step);
});

0 comments on commit 74a804b

Please sign in to comment.