public function testGetResourceSetsDuplicateNames() { $fakeSets = array($this->mockResourceSet, $this->mockResourceSet); Phockito::when($this->mockMetadataProvider->getResourceSets())->return($fakeSets); Phockito::when($this->mockResourceSet->getResourceType())->return($this->mockResourceType); $fakeName = "Fake Set 1"; Phockito::when($this->mockResourceSet->getName())->return($fakeName); Phockito::when($this->mockServiceConfig->getEntitySetAccessRule($this->mockResourceSet))->return(EntitySetRights::READ_SINGLE); $wrapper = $this->getMockedWrapper(); try { $wrapper->getResourceSets(); $this->fail('An expected ODataException for entity set repetition has not been thrown'); } catch (ODataException $exception) { $this->assertEquals(Messages::providersWrapperEntitySetNameShouldBeUnique($fakeName), $exception->getMessage()); $this->assertEquals(500, $exception->getStatusCode()); } }
/** * To get all entity set information, * Note: Wrapper for IMetadataProvider::getResourceSets method implementation, * This method returns array of ResourceSetWrapper instances but the corresponding IDSMP method returns array of ResourceSet instances * * @return ResourceSetWrapper[] The ResourceSetWrappers for the visible ResourceSets * @throws ODataException when two resource sets with the same name are encountered * */ public function getResourceSets() { $resourceSets = $this->metaProvider->getResourceSets(); $resourceSetWrappers = array(); $resourceSetNames = array(); foreach ($resourceSets as $resourceSet) { $name = $resourceSet->getName(); if (in_array($name, $resourceSetNames)) { throw new ODataException(Messages::providersWrapperEntitySetNameShouldBeUnique($name), 500); } $resourceSetNames[] = $name; $resourceSetWrapper = $this->_validateResourceSetAndGetWrapper($resourceSet); if (!is_null($resourceSetWrapper)) { $resourceSetWrappers[] = $resourceSetWrapper; } } return $resourceSetWrappers; }