/**
  * {@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;
 }
Ejemplo n.º 3
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testSetAndGetLeadParagraphBreaksWithInteger()
 {
     // Arrange
     $article = new Article();
     $leadParagraphBefore = 4;
     // Act
     $article->setLeadParagraph($leadParagraphBefore);
     $leadParagraphAfter = $article->getLeadParagraph();
     // Assert
     $this->assertEquals($leadParagraphBefore, $leadParagraphAfter);
 }