Skip to content

Commit

Permalink
Merge pull request #843 from themsaid/pr18619
Browse files Browse the repository at this point in the history
[5.x] Merge tags from payload
  • Loading branch information
taylorotwell authored May 26, 2020
2 parents b8f6390 + dcdd8f9 commit ab18093
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/JobPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/RedisPayloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down

0 comments on commit ab18093

Please sign in to comment.