From 1b43cea130c78531db2189ce99da974634206873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Dobe=C5=A1?= Date: Wed, 4 Nov 2020 12:40:58 +0100 Subject: [PATCH] Add Scope::removeTag() method --- CHANGELOG.md | 1 + src/State/Scope.php | 14 ++++++++++++++ tests/State/ScopeTest.php | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de77facb6e..5493544d04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Add setter for value on the `ExceptionDataBag` (#1100) +- Add `Scope::removeTag` method (#1126) ## 3.0.4 (2020-11-6) diff --git a/src/State/Scope.php b/src/State/Scope.php index c70c777229..78cd452a40 100644 --- a/src/State/Scope.php +++ b/src/State/Scope.php @@ -103,6 +103,20 @@ public function setTags(array $tags): self return $this; } + /** + * Removes a given tag from the tags context. + * + * @param string $key The key that uniquely identifies the tag + * + * @return $this + */ + public function removeTag(string $key): self + { + unset($this->tags[$key]); + + return $this; + } + /** * Sets context data with the given name. * diff --git a/tests/State/ScopeTest.php b/tests/State/ScopeTest.php index f723e52524..a5c5618a1d 100644 --- a/tests/State/ScopeTest.php +++ b/tests/State/ScopeTest.php @@ -49,6 +49,27 @@ public function testSetTags(): void $this->assertSame(['foo' => 'bar', 'bar' => 'baz'], $event->getTags()); } + public function testRemoveTag(): void + { + $scope = new Scope(); + $event = $scope->applyToEvent(Event::createEvent()); + + $scope->setTag('foo', 'bar'); + $scope->setTag('bar', 'baz'); + + $event = $scope->applyToEvent(Event::createEvent()); + + $this->assertNotNull($event); + $this->assertSame(['foo' => 'bar', 'bar' => 'baz'], $event->getTags()); + + $scope->removeTag('foo'); + + $event = $scope->applyToEvent(Event::createEvent()); + + $this->assertNotNull($event); + $this->assertSame(['bar' => 'baz'], $event->getTags()); + } + public function testSetAndRemoveContext(): void { $scope = new Scope();