-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for prepended UniqueJobDecorator
- Loading branch information
1 parent
52c3371
commit 277d901
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Lorisleiva\Actions\Tests; | ||
|
||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Lorisleiva\Actions\Concerns\AsJob; | ||
use Lorisleiva\Actions\Decorators\JobDecorator; | ||
use Lorisleiva\Actions\Decorators\UniqueJobDecorator; | ||
|
||
class AsJobWithUniqueJobDecoratorTest implements ShouldBeUnique | ||
{ | ||
use AsJob; | ||
|
||
public static ?int $latestResult; | ||
public static ?JobDecorator $latestJobDecorator; | ||
|
||
public function handle(int $left, int $right) | ||
{ | ||
static::$latestResult = $left + $right; | ||
} | ||
|
||
public function asJob(UniqueJobDecorator $job, int $left, int $right) | ||
{ | ||
static::$latestJobDecorator = $job; | ||
$this->handle($left, $right); | ||
} | ||
} | ||
|
||
beforeEach(function () { | ||
// Given we reset the static variables. | ||
AsJobWithUniqueJobDecoratorTest::$latestResult = null; | ||
AsJobWithUniqueJobDecoratorTest::$latestJobDecorator = null; | ||
}); | ||
|
||
it('can access the UniqueJobDecorator instance from the asJob method', function () { | ||
// When we dispatch a job that expects a UniqueJobDecorator as a first argument. | ||
AsJobWithUniqueJobDecoratorTest::dispatch(1, 2); | ||
|
||
// Then it received the UniqueJobDecorator as its first argument. | ||
$job = AsJobWithUniqueJobDecoratorTest::$latestJobDecorator; | ||
expect($job)->toBeInstanceOf(UniqueJobDecorator::class); | ||
expect($job->getParameters())->toBe([1, 2]); | ||
expect(get_class($job->getAction()))->toBe(AsJobWithUniqueJobDecoratorTest::class); | ||
|
||
// And the received the expected result. | ||
expect(AsJobWithUniqueJobDecoratorTest::$latestResult)->toBe(3); | ||
}); |