/** * Retrieves a collection of resources. * * @param Request $request * * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable * * @throws RuntimeException|RootNodeNotFoundException|RootMayNotBeMovedException|MissingParentCategoryException */ public function __invoke(Request $request, $id) { list($resourceType) = $this->extractAttributes($request); $entity = $this->getItem($this->dataProvider, $resourceType, $id); $parentId = $request->request->get("parent"); $parentEntity = $this->iriConverter->getItemFromIri($parentId); if ($parentEntity === null) { throw new MissingParentCategoryException($parentId); } if ($entity->getLevel() === 0) { throw new RootMayNotBeMovedException(); } $entity->setParent($parentEntity); $this->registry->getManager()->flush(); return new Response($request->request->get("parent")); }
/** * @expectedException \Dunglas\ApiBundle\Exception\InvalidArgumentException * @expectedExceptionMessage Unable to generate an IRI for "Foo". */ public function testGetIriFromResourceRouteNotFound() { $resourceCollection = $this->prophesize('Dunglas\\ApiBundle\\Api\\ResourceCollectionInterface')->reveal(); $classMetadataFactory = $this->prophesize('Dunglas\\ApiBundle\\Mapping\\Factory\\ClassMetadataFactoryInterface')->reveal(); $propertyAccessor = $this->prophesize('Symfony\\Component\\PropertyAccess\\PropertyAccessorInterface')->reveal(); $dataProvider = $this->prophesize('Dunglas\\ApiBundle\\Model\\DataProviderInterface')->reveal(); $routerProphecy = $this->prophesize('Symfony\\Component\\Routing\\RouterInterface'); $routerProphecy->generate(null, [], RouterInterface::ABSOLUTE_PATH)->willThrow('Symfony\\Component\\Routing\\Exception\\RouteNotFoundException')->shouldBeCalled(); $router = $routerProphecy->reveal(); $iriConverter = new IriConverter($resourceCollection, $dataProvider, $classMetadataFactory, $router, $propertyAccessor); $resourceProphecy = $this->prophesize('Dunglas\\ApiBundle\\Api\\ResourceInterface'); $resourceProphecy->getShortName()->willReturn('Foo')->shouldBeCalled(); $resourceProphecy->getCollectionOperations()->willReturn([])->shouldBeCalled(); $resource = $resourceProphecy->reveal(); $iriConverter->getIriFromResource($resource); }