Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Add setter for value on the `ExceptionDataBag` (#1100)
- Add `Scope::removeTag` method (#1126)

## 3.0.4 (2020-11-6)

Expand Down
14 changes: 14 additions & 0 deletions src/State/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/State/ScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down