Example #1
0
 /**
  * @param array    $data
  * @param          $className
  * @param callable $callable
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function get(array $data, $className, callable $callable)
 {
     try {
         DataObject::assertPost($data, $this->serializer, $className, $this->errorBag);
         $values = DataObject::getAttributes($data, $this->serializer);
         $model = $callable($data, $values, $this->errorBag);
         $response = $this->resourceCreated($this->serializer->serialize($model));
     } catch (Exception $e) {
         $response = $this->getErrorResponse($e, $this->errorBag);
     }
     return $response;
 }
Example #2
0
 public function testAssertPostWillReturnErrorsForRelationshipElementWithArray()
 {
     $errorBag = new ErrorBag();
     $data = ['type' => 'post', 'attributes' => ['content' => 'Ever heard of Lorem Ipsum?', 'author' => 1, 'comments' => []], 'relationships' => [['data' => [['type' => 'post', 'attributes' => ['content' => 'Ever heard of Lorem Ipsum?', 'author' => 1, 'comments' => [], 'this_does_not_exist' => null]]]]]];
     $hasErrors = false;
     try {
         DataObject::assertPost($data, $this->serializer, Post::class, $errorBag);
     } catch (DataException $e) {
         $hasErrors = true;
     }
     $this->assertTrue($hasErrors);
 }