/**
  * @inheritdoc
  */
 public function execute(Request $request, DataSourceInterface $resource, $identifier)
 {
     $instance = $resource->update($identifier, $request->attributes->get(AuthorizationListener::API_REQUEST_PAYLOAD));
     if (is_null($instance)) {
         throw new NotFoundHttpException();
     }
     return ActionResult::instance(200, $resource->read($identifier));
 }
示例#2
0
 /**
  * @inheritdoc
  */
 public function execute(Request $request, DataSourceInterface $resource, $identifier)
 {
     $instance = $resource->read($identifier);
     if (is_null($instance)) {
         throw new NotFoundHttpException();
     }
     return ActionResult::instance(200, $instance);
 }
 function it_should_update_via_dataSource(DataSourceInterface $dataSource)
 {
     $full = ['id' => 1];
     $data = ['name' => 'foo'];
     $request = Request::create('/user/1', 'PUT');
     $request->attributes->set(AuthorizationListener::API_REQUEST_PAYLOAD, $data);
     $dataSource->update(1, $data)->willReturn(true);
     $dataSource->read(1)->willReturn(array_merge($full, $data));
     $result = $this->execute($request, $dataSource, 1);
     $result->shouldHaveType('Im0rtality\\ApiBundle\\Actions\\ActionResult');
     $result->getStatusCode()->shouldBe(200);
     $result->getResult()->shouldBe(array_merge($full, $data));
     $result->getType()->shouldBe(ActionResult::INSTANCE);
 }
 function it_should_throw_if_instance_not_found(DataSourceInterface $dataSource)
 {
     $request = Request::create('/user/1', 'GET');
     $dataSource->read(1)->willReturn(null);
     $this->shouldThrow('Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException')->during('execute', [$request, $dataSource, 1]);
 }