/**
  * Construct new instance of ResourceAssociationSet
  * 
  * @param string                    $name Name of the association set
  * @param ResourceAssociationSetEnd $end1 First end set participating 
  *                                        in the association set
  * @param ResourceAssociationSetEnd $end2 Second end set participating 
  *                                        in the association set
  * 
  * @throws \InvalidArgumentException
  */
 public function __construct($name, ResourceAssociationSetEnd $end1, ResourceAssociationSetEnd $end2)
 {
     if (is_null($end1->getResourceProperty()) && is_null($end2->getResourceProperty())) {
         throw new \InvalidArgumentException(Messages::resourceAssociationSetResourcePropertyCannotBeBothNull());
     }
     if ($end1->getResourceType() == $end2->getResourceType() && $end1->getResourceProperty() == $end2->getResourceProperty()) {
         throw new \InvalidArgumentException(Messages::resourceAssociationSetSelfReferencingAssociationCannotBeBiDirectional());
     }
     $this->_name = $name;
     $this->_end1 = $end1;
     $this->_end2 = $end2;
 }
Esempio n. 2
0
 public function testGetResourceAssociationSetEndIsNotVisible()
 {
     $fakePropName = "Fake Prop";
     Phockito::when($this->mockResourceProperty->getName())->return($fakePropName);
     Phockito::when($this->mockResourceType->resolvePropertyDeclaredOnThisType($fakePropName))->return($this->mockResourceProperty);
     $fakeTypeName = "Fake Type";
     Phockito::when($this->mockResourceType->getName())->return($fakeTypeName);
     $fakeSetName = "Fake Set";
     Phockito::when($this->mockResourceSet->getName())->return($fakeSetName);
     Phockito::when($this->mockResourceSet->getResourceType())->return($this->mockResourceType);
     Phockito::when($this->mockResourceSet2->getResourceType())->return($this->mockResourceType2);
     //Indicate the resource set is visible
     Phockito::when($this->mockServiceConfig->getEntitySetAccessRule($this->mockResourceSet))->return(EntitySetRights::READ_SINGLE);
     //Indicate the resource set is visible
     Phockito::when($this->mockServiceConfig->getEntitySetAccessRule($this->mockResourceSet2))->return(EntitySetRights::NONE);
     Phockito::when($this->mockMetadataProvider->getResourceAssociationSet($this->mockResourceSet, $this->mockResourceType, $this->mockResourceProperty))->return($this->mockResourceAssociationSet);
     Phockito::when($this->mockResourceAssociationSet->getResourceAssociationSetEnd($this->mockResourceSet, $this->mockResourceType, $this->mockResourceProperty))->return($this->mockResourceAssociationSetEnd);
     Phockito::when($this->mockResourceAssociationSet->getRelatedResourceAssociationSetEnd($this->mockResourceSet, $this->mockResourceType, $this->mockResourceProperty))->return($this->mockResourceAssociationSetEnd);
     Phockito::when($this->mockResourceAssociationSetEnd->getResourceSet())->return($this->mockResourceSet2);
     Phockito::when($this->mockResourceAssociationSetEnd->getResourceType())->return($this->mockResourceType2);
     $wrapper = $this->getMockedWrapper();
     $actual = $wrapper->getResourceAssociationSet($this->mockResourceSet, $this->mockResourceType, $this->mockResourceProperty);
     $this->assertNull($actual);
 }
Esempio n. 3
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));
 }