diff --git a/src/JobPayload.php b/src/JobPayload.php index 9948a569..8e41dd24 100644 --- a/src/JobPayload.php +++ b/src/JobPayload.php @@ -123,14 +123,10 @@ protected function determineType($job) */ protected function determineTags($job) { - switch (true) { - case is_string($job): - return []; - case array_key_exists('tags', $this->decoded): - return $this->decoded['tags']; - default: - return Tags::for($job); - } + return array_merge( + $this->decoded['tags'] ?? [], + is_string($job) ? [] : Tags::for($job) + ); } /** diff --git a/tests/Unit/RedisPayloadTest.php b/tests/Unit/RedisPayloadTest.php index 57095578..81f09fa3 100644 --- a/tests/Unit/RedisPayloadTest.php +++ b/tests/Unit/RedisPayloadTest.php @@ -134,6 +134,17 @@ public function test_listener_and_event_tags_can_merge_auto_tag_events() ], $JobPayload->decoded['tags']); } + public function test_tags_are_added_to_existing() + { + $JobPayload = new JobPayload(json_encode(['id' => 1, 'tags' => ['mytag']])); + + $job = new CallQueuedListener(FakeListenerWithProperties::class, 'handle', [new FakeEventWithModel(42)]); + + $JobPayload->prepare($job); + + $this->assertEquals(['mytag', FakeModel::class.':42'], $JobPayload->decoded['tags']); + } + public function test_jobs_can_have_tags_method_to_override_auto_tagging() { $JobPayload = new JobPayload(json_encode(['id' => 1]));