/**
  * Returns ResourceMetadata for the specified resource.
  *
  * @param  string                                     $resourceName
  * @throws \BedRest\Resource\Mapping\Exception
  * @return \BedRest\Resource\Mapping\ResourceMetadata
  */
 public function getMetadataByResourceName($resourceName)
 {
     $this->getAllMetadata();
     if (!isset($this->resourceClassMap[$resourceName])) {
         throw Exception::resourceNotFound($resourceName);
     }
     return $this->loadedMetadata[$this->resourceClassMap[$resourceName]];
 }
Example #2
0
 /**
  * @dataProvider requests
  *
  * @param string $method
  */
 public function testDispatchToNonExistentResourceThrows404Exception($method)
 {
     $resourceName = 'nonExistentResource';
     $notFoundException = \BedRest\Resource\Mapping\Exception::resourceNotFound($resourceName);
     // configure the Dispatcher with the necessary dependencies
     $rmdFactory = $this->getMockResourceMetadataFactory();
     $rmdFactory->expects($this->any())->method('getMetadataByResourceName')->with($resourceName)->will($this->throwException($notFoundException));
     $rmdFactory->expects($this->any())->method('getMetadataFor')->with($resourceName)->will($this->throwException($notFoundException));
     $this->dispatcher->setResourceMetadataFactory($rmdFactory);
     $this->dispatcher->setServiceMetadataFactory($this->getMockServiceMetadataFactory($method));
     $this->dispatcher->setServiceLocator($this->getMockServiceLocator());
     $eventManager = $this->getMock('BedRest\\Events\\EventManager');
     $this->dispatcher->setEventManager($eventManager);
     // form a basic request
     $request = new Request();
     $request->setResource($resourceName);
     $request->setMethod($method);
     // test an exception is thrown
     $this->setExpectedException('BedRest\\Rest\\Exception', '', 404);
     $this->dispatcher->dispatch($request);
 }