diff --git a/mailpoet/tests/DataFactories/Tag.php b/mailpoet/tests/DataFactories/Tag.php new file mode 100644 index 0000000000..5b708fa0ac --- /dev/null +++ b/mailpoet/tests/DataFactories/Tag.php @@ -0,0 +1,47 @@ +tagRepository = ContainerWrapper::getInstance()->get(TagRepository::class); + $this->data = [ + 'name' => 'Tag' . bin2hex(random_bytes(7)), + ]; + } + + /** + * @return $this + */ + public function withName(string $name) { + return $this->update('name', $name); + } + + public function create(): TagEntity { + $tag = new TagEntity($this->data['name']); + $this->tagRepository->persist($tag); + $this->tagRepository->flush(); + return $tag; + } + + /** + * @return $this + */ + private function update(string $item, $value) { + $data = $this->data; + $data[$item] = $value; + $new = clone $this; + $new->data = $data; + return $new; + } +}