Skip to content

Commit 7276c75

Browse files
committed
Do not add the same tag multiple times
1 parent 4c5e60c commit 7276c75

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ResponseTagger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function addTags(array $tags)
123123
throw new InvalidTagException('Empty tags are not allowed');
124124
}
125125

126-
$this->tags = array_merge($this->tags, $filtered);
126+
$this->tags = array_unique(array_merge($this->tags, $filtered));
127127

128128
return $this;
129129
}

tests/Unit/ResponseTaggerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,15 @@ public function testNonStrictEmptyTag()
132132
$this->assertTrue($tagHandler->hasTags());
133133
$this->assertEquals('post-1', $tagHandler->getTagsHeaderValue());
134134
}
135+
136+
public function testUniqueTags()
137+
{
138+
$headerFormatter = new CommaSeparatedTagHeaderFormatter('FOS-Tags');
139+
140+
$tagHandler = new ResponseTagger(['header_formatter' => $headerFormatter, 'strict' => true]);
141+
$tagHandler->addTags(['post-1', 'post-2', 'post-1']);
142+
$this->assertTrue($tagHandler->hasTags());
143+
144+
$this->assertEquals('post-1,post-2', $tagHandler->getTagsHeaderValue());
145+
}
135146
}

0 commit comments

Comments
 (0)