Skip to content

Commit 6ed3d68

Browse files
authored
Merge pull request #109 from ricventu/receives-job-property
receives job property
2 parents 66da70a + 63b1e16 commit 6ed3d68

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/ActionJob.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function failed(Throwable $exception)
102102
public function handle()
103103
{
104104
$action = app($this->actionClass);
105+
$action->job = $this->job;
105106
$action->{$action->queueMethod()}(...$this->parameters);
106107
}
107108

tests/QueueableActionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Support\Facades\Schema;
1313
use Spatie\QueueableAction\ActionJob;
1414
use Spatie\QueueableAction\Exceptions\InvalidConfiguration;
15+
use Spatie\QueueableAction\Tests\TestClasses\ActionReturningJob;
1516
use Spatie\QueueableAction\Tests\TestClasses\ActionWithFailedMethod;
1617
use Spatie\QueueableAction\Tests\TestClasses\BackoffAction;
1718
use Spatie\QueueableAction\Tests\TestClasses\BackoffPropertyAction;
@@ -29,6 +30,8 @@
2930
use Spatie\QueueableAction\Tests\TestClasses\SimpleAction;
3031
use Spatie\QueueableAction\Tests\TestClasses\TaggedAction;
3132
use stdClass;
33+
use function PHPUnit\Framework\assertInstanceOf;
34+
use function PHPUnit\Framework\assertTrue;
3235

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

55+
test('an action can be queued and receives job property', function () {
56+
$action = new ActionReturningJob();
57+
$job = $action->onQueue()->execute();
58+
expect($job)->toBeInstanceOf(\Illuminate\Foundation\Bus\PendingDispatch::class);
59+
});
60+
5261
test('an action with dependencies and input can be executed on the queue', function () {
5362
/** @var \Spatie\QueueableAction\Tests\TestClasses\ComplexAction $action */
5463
$action = app(ComplexAction::class);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Spatie\QueueableAction\Tests\TestClasses;
4+
5+
use Spatie\QueueableAction\QueueableAction;
6+
7+
/**
8+
* @property $job
9+
*/
10+
class ActionReturningJob
11+
{
12+
use QueueableAction;
13+
14+
public function execute()
15+
{
16+
return $this->job;
17+
}
18+
}

0 commit comments

Comments
 (0)