示例#1
0
 /**
  * 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 Item not found for "/bal/milleneufcent".
  */
 public function testGetItemFromIriDataProviderReturnsNull()
 {
     $resource = $this->prophesize('Dunglas\\ApiBundle\\Api\\ResourceInterface')->reveal();
     $classMetadataFactory = $this->prophesize('Dunglas\\ApiBundle\\Mapping\\Factory\\ClassMetadataFactoryInterface')->reveal();
     $propertyAccessor = $this->prophesize('Symfony\\Component\\PropertyAccess\\PropertyAccessorInterface')->reveal();
     $resourceCollectionProphecy = $this->prophesize('Dunglas\\ApiBundle\\Api\\ResourceCollectionInterface');
     $resourceCollectionProphecy->getResourceForShortName('Bal')->willReturn($resource)->shouldBeCalled();
     $resourceCollection = $resourceCollectionProphecy->reveal();
     $dataProviderProphecy = $this->prophesize('Dunglas\\ApiBundle\\Model\\DataProviderInterface');
     $dataProviderProphecy->getItem($resource, 'milleneufcent', false)->willReturn(null)->shouldBeCalled();
     $dataProvider = $dataProviderProphecy->reveal();
     $routerProphecy = $this->prophesize('Symfony\\Component\\Routing\\RouterInterface');
     $routerProphecy->match('/bal/milleneufcent')->willReturn(['_resource' => 'Bal', 'id' => 'milleneufcent'])->shouldBeCalled();
     $router = $routerProphecy->reveal();
     $iriConverter = new IriConverter($resourceCollection, $dataProvider, $classMetadataFactory, $router, $propertyAccessor);
     $iriConverter->getItemFromIri('/bal/milleneufcent');
 }