예제 #1
0
 public function testIfSluggableExtensionIsWorking()
 {
     $article = new Article();
     $article->setTitle('Article title');
     $article->setBody('Article body');
     $em = $this->container->get('doctrine')->getManager();
     $em->persist($article);
     $em->flush();
     $this->assertEquals('article-title', $article->getSlug());
 }
예제 #2
0
파일: LoadData.php 프로젝트: pferre/playapi
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $faker = Factory::create();
     for ($i = 1; $i <= 10; $i++) {
         $article = new Article();
         $article->setTitle($faker->sentence());
         $article->setBody($faker->paragraph(2));
         $manager->persist($article);
         $manager->flush();
     }
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $article = new Article();
     $article->setHeadline('Backend Symfony Blog Tutorial');
     $article->setByline('Oliver Forral');
     $article->setLeadParagraph('Write a backend blog server using Symfony!');
     $article->setBody('Step 1: Write a backend blog server using Symfony.  Step 2: ???  Step 3: Profit!!!');
     $manager->persist($article);
     $manager->flush($article);
     $this->addReference('article-backend_symfony_blog_tutorial', $article);
     $article = new Article();
     $article->setHeadline('Frontend ReactJS Blog Tutorial');
     $article->setByline('Oliver Forral');
     $article->setLeadParagraph('Write a frontend blog client using ReactJS!');
     $article->setBody('Step 1: Write a frontend blog client using ReactJS.  Step 2: ???  Step 3: Profit!!!');
     $manager->persist($article);
     $manager->flush($article);
     $this->addReference('article-frontend_reactjs_blog_tutorial', $article);
 }
 /**
  * @Route("/{article}", name="articles_patch_existing")
  * @Method({"PATCH"})
  */
 public function patchExistingAction(Request $request, Article $article)
 {
     $this->initializeJsonResponse();
     if (!$this->checkValidJsonApi($request)) {
         return $this->jsonResponse;
     }
     $content = json_decode($request->getContent(), true);
     if (array_key_exists('headline', $content['data']['attributes'])) {
         $article->setHeadline($content['data']['attributes']['headline']);
     }
     if (array_key_exists('byline', $content['data']['attributes'])) {
         $article->setByline($content['data']['attributes']['byline']);
     }
     if (array_key_exists('leadParagraph', $content['data']['attributes'])) {
         $article->setLeadParagraph($content['data']['attributes']['leadParagraph']);
     }
     if (array_key_exists('body', $content['data']['attributes'])) {
         $article->setBody($content['data']['attributes']['body']);
     }
     $this->getDoctrine()->getManager()->persist($article);
     $this->getDoctrine()->getManager()->flush($article);
     $this->jsonResponse->setData(array('data' => array('type' => 'articles', 'id' => $article->getId(), 'attributes' => array('headline' => $article->getHeadline(), 'byline' => $article->getByline(), 'leadParagraph' => $article->getLeadParagraph(), 'body' => $article->getBody()))));
     return $this->jsonResponse;
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testSetAndGetBodyBreaksWithInteger()
 {
     // Arrange
     $article = new Article();
     $bodyBefore = 4;
     // Act
     $article->setBody($bodyBefore);
     $bodyAfter = $article->getBody();
     // Assert
     $this->assertEquals($bodyBefore, $bodyAfter);
 }