示例#1
0
 /**
  * Updates a single resource entity.
  *
  * @param  \BedRest\Rest\Event\Event $event
  * @return object
  *
  * @BedRest\Listener(event="PUT")
  */
 public function restPut(Event $event)
 {
     $identifier = $event->getRequest()->getParameter('identifier');
     $requestData = (array) $event->getRequest()->getContent();
     $resource = $this->update($identifier, $requestData);
     $event->setData($this->dataMapper->reverse($resource, 1));
 }
示例#2
0
 /**
  * Tests reverse mapping single-valued associations with proxies in place to ensure the proxies are loaded.
  */
 public function testAssociationReverseSingleWithProxy()
 {
     // force-clear the result caches to ensure we get proxies back
     self::getEntityManager()->clear();
     // get the test resource and reverse it
     $resource = self::getMockEntity('Employee', 1);
     $reversed = $this->mapper->reverse($resource, 2);
     // check we get an array back, firstly
     $this->assertInternalType('array', $reversed);
     // check the item is equivalent to when it is reversed individually
     $reversedItem = $reversed['Department'];
     $this->assertInternalType('array', $reversedItem);
     $itemResource = self::getMockEntity('Department', $reversedItem['id']);
     $itemResourceReversed = $this->mapper->reverse($itemResource, 1);
     $this->assertEquals($itemResourceReversed, $reversedItem);
 }
示例#3
0
 public function testInvalidResourceCausesExceptionForUpdate()
 {
     $rmdFactory = $this->getResourceMetadataFactory();
     $resourceMetadata = $rmdFactory->getMetadataByResourceName('asset');
     $em = self::getEntityManager();
     $mapper = new Mapper();
     $mapper->setEntityManager($em);
     $service = $this->getMock('BedRest\\Model\\Doctrine\\Service', array('validate'), array($resourceMetadata, $mapper));
     $service->setEntityManager($em);
     $service->expects($this->once())->method('validate')->will($this->returnValue(false));
     $asset = new Asset();
     $asset->id = 1;
     $asset->name = 'test-asset';
     $this->setExpectedException('BedRest\\Model\\Doctrine\\Exception');
     $service->update($asset);
 }