From fc64639cded24447c9b6d40a87db0de80b69320c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lys=C3=BD?= Date: Fri, 24 Jun 2022 10:39:32 +0200 Subject: [PATCH] Add tag factory into tests [MAILPOET-4440] --- mailpoet/tests/DataFactories/Tag.php | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 mailpoet/tests/DataFactories/Tag.php 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; + } +}