예제 #1
0
 /**
  * @Given there are following topics:
  *
  * @param TableNode $tableNode
  */
 public function thereAreFollowingTopics(TableNode $tableNode)
 {
     $em = $this->getEntityManager();
     foreach ($tableNode->getHash() as $topicHash) {
         $topic = new Topic();
         $topic->setName($topicHash['name']);
         $em->persist($topic);
     }
     $em->flush();
 }
 /**
  * Transforms a string to an ArrayCollection.
  *
  * @param string $value
  *
  * @return ArrayCollection
  */
 public function reverseTransform($value)
 {
     $topics = new ArrayCollection();
     if (null === $value) {
         return $topics;
     }
     $tokens = preg_split('/(\\s*,\\s*)+/', $value, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($tokens as $token) {
         if (null === ($topic = $this->om->getRepository('AppBundle:Topic')->findOneByName($token))) {
             $topic = new Topic();
             $topic->setName($token);
             $this->om->persist($topic);
         }
         $topics->add($topic);
     }
     $this->om->flush();
     return $topics;
 }