Skip to content

Commit

Permalink
Merge pull request #109 from ricventu/receives-job-property
Browse files Browse the repository at this point in the history
receives job property
  • Loading branch information
freekmurze authored Jan 17, 2025
2 parents 66da70a + 63b1e16 commit 6ed3d68
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ActionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function failed(Throwable $exception)
public function handle()
{
$action = app($this->actionClass);
$action->job = $this->job;
$action->{$action->queueMethod()}(...$this->parameters);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/QueueableActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Facades\Schema;
use Spatie\QueueableAction\ActionJob;
use Spatie\QueueableAction\Exceptions\InvalidConfiguration;
use Spatie\QueueableAction\Tests\TestClasses\ActionReturningJob;
use Spatie\QueueableAction\Tests\TestClasses\ActionWithFailedMethod;
use Spatie\QueueableAction\Tests\TestClasses\BackoffAction;
use Spatie\QueueableAction\Tests\TestClasses\BackoffPropertyAction;
Expand All @@ -29,6 +30,8 @@
use Spatie\QueueableAction\Tests\TestClasses\SimpleAction;
use Spatie\QueueableAction\Tests\TestClasses\TaggedAction;
use stdClass;
use function PHPUnit\Framework\assertInstanceOf;
use function PHPUnit\Framework\assertTrue;

beforeEach(function () {
config()->set('database.default', 'testing');
Expand All @@ -49,6 +52,12 @@
Queue::assertPushed(ActionJob::class);
});

test('an action can be queued and receives job property', function () {
$action = new ActionReturningJob();
$job = $action->onQueue()->execute();
expect($job)->toBeInstanceOf(\Illuminate\Foundation\Bus\PendingDispatch::class);
});

test('an action with dependencies and input can be executed on the queue', function () {
/** @var \Spatie\QueueableAction\Tests\TestClasses\ComplexAction $action */
$action = app(ComplexAction::class);
Expand Down
18 changes: 18 additions & 0 deletions tests/TestClasses/ActionReturningJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Spatie\QueueableAction\Tests\TestClasses;

use Spatie\QueueableAction\QueueableAction;

/**
* @property $job
*/
class ActionReturningJob
{
use QueueableAction;

public function execute()
{
return $this->job;
}
}

0 comments on commit 6ed3d68

Please sign in to comment.