function it_should_throw_if_instance_not_found(DataSourceInterface $dataSource) { $data = ['name' => 'foo']; $request = Request::create('/user/1', 'PUT'); $request->attributes->set(AuthorizationListener::API_REQUEST_PAYLOAD, $data); $dataSource->update(1, $data)->willReturn(null); $this->shouldThrow('Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException')->during('execute', [$request, $dataSource, 1]); }
/** * @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)); }