/** * @param User $user1 * @param User $user2 * @return Thread */ private function generateTwoUsersThread(User $user1, User $user2) { $thread = new Thread(); $thread->addUser($user1)->addUser($user2); $this->entityManager->persist($thread); $this->entityManager->flush($thread); return $thread; }
/** * @Route("/createRandomThread" , name="create thread") */ function createRandomThreadAction() { $doctrine = $this->getDoctrine(); $em = $doctrine->getEntityManager(); $thread = new Thread(); $generator = $this->get('app.data_generator'); $thread->setTitle($generator->generateRandomString()); $em->persist($thread); $em->flush(); return $this->redirect('/thread/' . $thread->getId()); }
public function testSetThread() { // new entity $post = new Post(); // dummy entity $thread = new Thread(); $thread->setSubject("hehe"); // Use the setThread method $post->setThread($thread); // Assert the result $this->assertEquals($thread, $post->getThread()); }
/** * @param Thread $thread * @return \Doctrine\Common\Collections\Collection * * @View(serializerGroups={"default", "withUser"}) * @ApiDoc( * section="Messages", * description="Returns messages by thread", * output={ * "class" = "AppBundle\Message", * "groups" = {"default", "withUser"} * } * ) */ public function getThreadMessagesAction(Thread $thread) { return $thread->getMessages(); }
public function testAddThread() { // new entity $subforum = new Subforum(); // New dummy entity $thread1 = new Thread(); $thread1->setSubject("thread1"); // Use the addThread method $subforum->addThread($thread1); // Threads is stored in an array $threads = $subforum->getThreads(); // Loop through the array and check for matches foreach ($threads as $thread) { if ($thread1 == $thread) { // Assert the result $this->assertEquals($thread1, $thread); } } }