Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

receives job property #109

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ActionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,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 @@ -11,6 +11,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 @@ -27,6 +28,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 @@ -47,6 +50,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;
}
}
Loading