public function testDuplicatedUrlThrowsError() { $urlText = 'page-test-meta-url'; $this->setExpectedException('LogicException', 'Given URL already exists'); // Create Page 1 $page1 = new Page(); $page1->setLocale('en'); $page1->setContent('...'); $page1->setName('...'); $page1->setStatus(true); $page1->setMetaUrl($urlText); $page1->setMetaTitle('...'); $page1->setCommentStatus(true); $this->em->persist($page1); $this->em->flush(); $this->em->clear(); // Create Page 2 $page2 = new Page(); $page2->setLocale('en'); $page2->setContent('...'); $page2->setName('...'); $page2->setStatus(true); $page2->setMetaUrl($urlText); $page2->setMetaTitle('...'); $page2->setCommentStatus(true); $this->em->persist($page2); $this->em->flush(); // Delete Page 1 $page1 = $this->em->getRepository('Aisel\\PageBundle\\Entity\\Page')->findOneBy(['metaUrl' => $urlText]); $this->em->remove($page1); $this->em->flush(); $this->em->clear(); }