Removed non-used deprecated method and added missing tests

This commit is contained in:
Alejandro Celaya
2021-01-31 13:05:21 +01:00
parent 6b0f6e4541
commit ef12e90ae7
4 changed files with 60 additions and 12 deletions

View File

@@ -128,16 +128,6 @@ class ShortUrl extends AbstractEntity
return $this->tags;
}
/**
* @param Collection|Tag[] $tags
* @deprecated Use ShortUrl::update to set the tags on this ShortUrl
*/
public function setTags(Collection $tags): self
{
$this->tags = $tags;
return $this;
}
public function update(
ShortUrlEdit $shortUrlEdit,
?ShortUrlRelationResolverInterface $relationResolver = null

View File

@@ -38,8 +38,13 @@ class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInt
*/
public function resolveTags(array $tags): Collections\Collection
{
return new Collections\ArrayCollection(map($tags, function (string $tagName): Tag {
$tag = $this->em->getRepository(Tag::class)->findOneBy(['name' => $tagName]) ?? new Tag($tagName);
if (empty($tags)) {
return new Collections\ArrayCollection();
}
$repo = $this->em->getRepository(Tag::class);
return new Collections\ArrayCollection(map($tags, function (string $tagName) use ($repo): Tag {
$tag = $repo->findOneBy(['name' => $tagName]) ?? new Tag($tagName);
$this->em->persist($tag);
return $tag;