protected function setUp() { parent::setUp(); $this->dispatcher = new Dispatcher(); $this->testResourceMeta = new ResourceMetadata('testResource'); $this->testResourceMeta->setName('testResource'); $this->testResourceMeta->setService('testService'); $this->testResourceMeta->setSubResources(array('sub' => array('fieldName' => 'sub', 'service' => 'testSubService'))); $this->testService = $this->getMock('BedRest\\TestFixtures\\Services\\Company\\Generic', array('getListener'), array(), 'testService'); $this->testServiceMeta = new ServiceMetadata('testService'); $this->testSubService = $this->getMock('BedRest\\TestFixtures\\Services\\Company\\Generic', array('getListener'), array(), 'testSubService'); $this->testSubServiceMeta = new ServiceMetadata('testSubService'); }
/** * {@inheritDoc} */ public function loadMetadataForClass($className, ResourceMetadata $resourceMetadata) { // get all class annotations $reflClass = new \ReflectionClass($className); $classAnnotations = $this->reader->getClassAnnotations($reflClass); $classAnnotations = $this->indexAnnotationsByType($classAnnotations); $resourceAnnotation = $this->getAnnotation($classAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\Resource'); if ($resourceAnnotation !== false) { if (!empty($resourceAnnotation->name)) { $resourceMetadata->setName($resourceAnnotation->name); } else { $resourceName = Inflector::tableize(substr($className, strrpos($className, '\\') + 1)); $resourceMetadata->setName($resourceName); } } $handlerAnnotation = $this->getAnnotation($classAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\Handler'); if ($handlerAnnotation !== false) { if (!empty($handlerAnnotation->service)) { $resourceMetadata->setService($handlerAnnotation->service); } } // properties $subResources = array(); foreach ($reflClass->getProperties() as $reflProp) { $propAnnotations = $this->reader->getPropertyAnnotations($reflProp); $propAnnotations = $this->indexAnnotationsByType($propAnnotations); $subResourceAnnotation = $this->getAnnotation($propAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\SubResource'); if ($subResourceAnnotation !== false) { $subResources[$subResourceAnnotation->name] = array('fieldName' => $reflProp->name, 'service' => $subResourceAnnotation->service); } } $resourceMetadata->setSubResources($subResources); }
public function testSubResourceWithoutFieldNameThrowsException() { $subResources = array('sub1' => array('fieldName' => 'assoc1', 'service' => 'sub1Service'), 'sub2' => array('service' => 'sub2Service')); $meta = new ResourceMetadata('Resource\\Test'); $this->setExpectedException('BedRest\\Resource\\Mapping\\Exception'); $meta->setSubResources($subResources); }