/**
  * Retrieve the related end for the given resource set, type and property.
  * 
  * @param ResourceSet      $resourceSet      Resource set for the end
  * @param ResourceType     $resourceType     Resource type for the end
  * @param ResourceProperty $resourceProperty Resource property for the end
  * 
  * @return ResourceAssociationSetEnd Related resource association set end 
  *                                   for the given parameters
  */
 public function getRelatedResourceAssociationSetEnd(ResourceSet $resourceSet, ResourceType $resourceType, ResourceProperty $resourceProperty)
 {
     if ($this->_end1->isBelongsTo($resourceSet, $resourceType, $resourceProperty)) {
         return $this->_end2;
     }
     if ($this->_end2->isBelongsTo($resourceSet, $resourceType, $resourceProperty)) {
         return $this->_end1;
     }
     return null;
 }
示例#2
0
 /**
  * Test ResourceAssociationSetEnd class
  * Note: ResourceAssociationSetEnd is an internal class used for metadata generation, not suppose to used by the developers 
  */
 public function testResourceAssociationSetEnd()
 {
     $customerResType = $this->_getCustomerResourceType();
     $orderResType = $this->_getOrderResourceType();
     $ordersReferenceSetProperty = new ResourceProperty('Orders', null, ResourcePropertyKind::RESOURCESET_REFERENCE, $orderResType);
     $customerResType->addProperty($ordersReferenceSetProperty);
     $customerResourceSet = new ResourceSet('Customers', $customerResType);
     $customerIDPrimProperty = $customerResType->resolveProperty('CustomerID');
     try {
         $assoSetEnd = new ResourceAssociationSetEnd($customerResourceSet, $customerResType, $customerIDPrimProperty);
         $this->fail('An expected InvalidArgumentException for \'not valid navigation property\' has not been raised');
     } catch (\InvalidArgumentException $exception) {
         $this->assertEquals('The property CustomerID must be a navigation property of the resource type Northwind.Customer', $exception->getMessage());
     }
     try {
         $assoSetEnd = new ResourceAssociationSetEnd($customerResourceSet, $orderResType, $ordersReferenceSetProperty);
         $this->fail('An expected InvalidArgumentException for \'not valid navigation property\' has not been raised');
     } catch (\InvalidArgumentException $exception) {
         $this->assertEquals('The property Orders must be a navigation property of the resource type Northwind.Order', $exception->getMessage());
     }
     $assoSetEnd = new ResourceAssociationSetEnd($customerResourceSet, $customerResType, $ordersReferenceSetProperty);
     $this->assertEquals($assoSetEnd->getResourceSet()->getName(), 'Customers');
     $this->assertEquals($assoSetEnd->getResourceType()->getName(), 'Customer');
     $this->assertEquals($assoSetEnd->getResourceProperty()->getName(), 'Orders');
     $this->assertTrue($assoSetEnd->isBelongsTo($customerResourceSet, $customerResType, $ordersReferenceSetProperty));
 }