Exemple #1
0
 /**
  * Pushes a segment for the current navigation property being written out.
  * Note: Refer 'ObjectModelSerializerNotes.txt' for more details about
  * 'Segment Stack' and this method.
  * Note: Calls to this method should be balanced with calls to popSegment.
  *
  * @param ResourceProperty &$resourceProperty Current navigation property 
  *                                            being written out
  *
  * @return bool true if a segment was pushed, false otherwise
  *
  * @throws InvalidOperationException If this function invoked with non-navigation
  *                                   property instance.
  */
 private function _pushSegmentForNavigationProperty(ResourceProperty &$resourceProperty)
 {
     if ($resourceProperty->getTypeKind() == ResourceTypeKind::ENTITY) {
         $this->assert(!empty($this->_segmentNames), '!is_empty($this->_segmentNames');
         $currentResourceSetWrapper = $this->_getCurrentResourceSetWrapper();
         $currentResourceType = $currentResourceSetWrapper->getResourceType();
         $currentResourceSetWrapper = $this->service->getProvidersWrapper()->getResourceSetWrapperForNavigationProperty($currentResourceSetWrapper, $currentResourceType, $resourceProperty);
         $this->assert(!is_null($currentResourceSetWrapper), '!null($currentResourceSetWrapper)');
         return $this->_pushSegment($resourceProperty->getName(), $currentResourceSetWrapper);
     } else {
         throw new InvalidOperationException('pushSegmentForNavigationProperty should not be called with non-entity type');
     }
 }
 public function testResourceProperty()
 {
     $addressResType = new ResourceType(new \ReflectionClass('UnitTests\\POData\\Facets\\NorthWind1\\Address2'), ResourceTypeKind::COMPLEX, 'Address', 'Northwind');
     $booleanResourcetype = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::BOOLEAN);
     $isPrimaryPrimProperty = new ResourceProperty('IsPrimary', null, ResourcePropertyKind::PRIMITIVE, $booleanResourcetype);
     $addressResType->addProperty($isPrimaryPrimProperty);
     try {
         $addressComplexProperty = new ResourceProperty('Address', null, ResourcePropertyKind::COMPLEX_TYPE | ResourcePropertyKind::KEY, $addressResType);
         $this->fail('An expected InvalidArgumentException for \'invalid ResourcePropertyKind\' has not been raised');
     } catch (\InvalidArgumentException $exception) {
         $this->assertStringEndsWith('not a valid ResourcePropertyKind enum value or valid combination of ResourcePropertyKind enum values', $exception->getMessage());
     }
     $stringResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::STRING);
     try {
         $addressComplexProperty = new ResourceProperty('Address', null, ResourcePropertyKind::COMPLEX_TYPE, $stringResourceType);
         $this->fail('An expected InvalidArgumentException for \'Property and ResourceType kind mismatch\' has not been raised');
     } catch (\InvalidArgumentException $exception) {
         $this->assertStringStartsWith('The \'$kind\' parameter does not match with the type of the resource type', $exception->getMessage());
     }
     $customerResType = new ResourceType(new \ReflectionClass('UnitTests\\POData\\Facets\\NorthWind1\\Customer2'), ResourceTypeKind::ENTITY, 'Customer', 'Northwind');
     $stringResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::STRING);
     $customerIDPrimProperty = new ResourceProperty('CustomerID', null, ResourcePropertyKind::PRIMITIVE | ResourcePropertyKind::KEY, $stringResourceType);
     $customerNamePrimProperty = new ResourceProperty('CustomerName', null, ResourcePropertyKind::PRIMITIVE, $stringResourceType);
     $intResourceType = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::INT32);
     $ratingPrimProperty = new ResourceProperty('Rating', null, ResourcePropertyKind::PRIMITIVE, $intResourceType);
     $customerResType->addProperty($customerIDPrimProperty);
     $customerResType->addProperty($customerNamePrimProperty);
     $customerResType->addProperty($ratingPrimProperty);
     $this->assertTrue($customerIDPrimProperty->isKindOf(ResourcePropertyKind::KEY));
     $this->assertTrue($customerIDPrimProperty->isKindOf(ResourcePropertyKind::PRIMITIVE));
     $customerReferenceSetProperty = new ResourceProperty('Customers', null, ResourcePropertyKind::RESOURCESET_REFERENCE, $customerResType);
     $this->assertEquals($customerReferenceSetProperty->getName(), 'Customers');
     $this->assertEquals($customerReferenceSetProperty->getKind(), ResourcePropertyKind::RESOURCESET_REFERENCE);
     $this->assertEquals($customerReferenceSetProperty->getInstanceType() instanceof \ReflectionClass, true);
     $this->assertEquals($customerReferenceSetProperty->getResourceType()->getName(), 'Customer');
     $this->assertEquals($customerReferenceSetProperty->getTypeKind(), ResourceTypeKind::ENTITY);
     $this->assertFalse($customerReferenceSetProperty->isKindOf(ResourcePropertyKind::RESOURCE_REFERENCE));
 }