From 277d90122dad6469b1ecfc07111e8d40f1854c25 Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Tue, 30 Mar 2021 18:56:39 +0100 Subject: [PATCH] Add test for prepended UniqueJobDecorator --- tests/AsJobWithJobDecoratorTest.php | 1 + tests/AsJobWithUniqueJobDecoratorTest.php | 47 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/AsJobWithUniqueJobDecoratorTest.php diff --git a/tests/AsJobWithJobDecoratorTest.php b/tests/AsJobWithJobDecoratorTest.php index 5c616be..95fce03 100644 --- a/tests/AsJobWithJobDecoratorTest.php +++ b/tests/AsJobWithJobDecoratorTest.php @@ -36,6 +36,7 @@ public function asJob(JobDecorator $job, int $left, int $right) // Then it received the JobDecorator as its first argument. $job = AsJobWithJobDecoratorTest::$latestJobDecorator; + expect($job)->toBeInstanceOf(JobDecorator::class); expect($job->getParameters())->toBe([1, 2]); expect(get_class($job->getAction()))->toBe(AsJobWithJobDecoratorTest::class); diff --git a/tests/AsJobWithUniqueJobDecoratorTest.php b/tests/AsJobWithUniqueJobDecoratorTest.php new file mode 100644 index 0000000..869543a --- /dev/null +++ b/tests/AsJobWithUniqueJobDecoratorTest.php @@ -0,0 +1,47 @@ +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); +});