public function testIsSharedThrowsExceptionWhenPassedNameWhichDoesNotExistAnywhere()
 {
     $this->setExpectedException('Zend\\ServiceManager\\Exception\\ServiceNotFoundException');
     $this->serviceManager->isShared('foobarbazbat');
 }
Exemple #2
0
 /**
  *
  * Perform the matching of a route and return a set of routing parameters if a valid one is found.
  * Otherwise exceptions get thrown
  *
  * @param RequestInterface $request
  * @return array
  *
  * @throws \Exception
  */
 protected function handleRouting(RequestInterface $request)
 {
     $this->router = $this->serviceManager->get('Router');
     $this->router->warmUp($this->getCacheDir());
     try {
         // Lets load up our router and match the appropriate route
         $parameters = $this->router->matchRequest($request);
         if (!empty($parameters)) {
             if (null !== $this->logger) {
                 $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->router->parametersToString($parameters)));
             }
         }
     } catch (ResourceNotFoundException $e) {
         $routeUri = $this->router->generate('Framework_404');
         $parameters = $this->router->matchRequest($request::create($routeUri));
     } catch (\Exception $e) {
         throw $e;
     }
     $parameters['_route_params'] = $parameters;
     return $parameters;
 }
Exemple #3
0
 /**
  * Perform the matching of a route and return a set of routing parameters if a valid one is found.
  * Otherwise exceptions get thrown
  *
  * @return array
  *
  * @throws \Exception
  */
 protected function handleRouting()
 {
     $this->router = $this->serviceManager->get('Router');
     $this->router->warmUp($this->getCacheDir());
     try {
         // Lets load up our router and match the appropriate route
         $parameters = $this->router->matchRequest($this->getRequest());
         if (!empty($parameters)) {
             if (null !== $this->logger) {
                 $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->router->parametersToString($parameters)));
             }
             $parameters['_route_params'] = $parameters;
             $this->getRequest()->attributes->add($parameters);
             return $parameters;
         }
     } catch (ResourceNotFoundException $e) {
         // Lets grab the 'Framework 404' route and dispatch it.
         //            try {
         //                $baseUrl = $this->router->getContext()->getBaseUrl();
         //                $routeUri = $this->router->generate($this->options['404RouteName']);
         //
         //                // We need to strip /myapp/public/404 down to /404, so our matchRoute() to work.
         //                if (!empty($baseUrl) && ($pos = strpos($routeUri, $baseUrl)) !== false) {
         //                    $routeUri = substr_replace($routeUri, '', $pos, strlen($baseUrl));
         //                }
         //
         //                // @todo handle a 502 here
         //
         //            } catch (\Exception $e) {
         throw new \Exception('Unable to load 404 page. An internal error occurred');
         //            }
     } catch (\Exception $e) {
         throw $e;
     }
 }
 /**
  * @param array $config
  */
 public function __construct(array $config = array())
 {
     $this->config = $config;
     $smConfig = isset($this->config['service_manager']) ? $this->config['service_manager'] : array();
     parent::__construct(new Config\ServiceManagerConfig($smConfig));
 }
Exemple #5
0
 private function setupAppMocks($app, $mockRouter, $mockControllerResolver)
 {
     $sm = new ServiceManager();
     $sm->setAllowOverride(true);
     $sm->set('Router', $mockRouter);
     $sm->set('ControllerResolver', $mockControllerResolver);
     $app->setServiceManager($sm);
     return $app;
 }
 /**
  * @group router
  */
 public function testWillRethrowOnNonValidatedPlugin()
 {
     $sm = new ServiceManager();
     $sm->setInvokableClass('stdClass', 'stdClass');
     /** @var \Zend\ServiceManager\AbstractPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
     $pluginManager = $this->getMockForAbstractClass('Zend\\ServiceManager\\AbstractPluginManager');
     $pluginManager->expects($this->once())->method('validatePlugin')->with($this->isInstanceOf('stdClass'))->will($this->throwException(new RuntimeException()));
     $pluginManager->setServiceLocator($sm);
     $this->setExpectedException('Zend\\ServiceManager\\Exception\\ServiceLocatorUsageException');
     $pluginManager->get('stdClass');
 }
Exemple #7
0
 public function testDispatch()
 {
     $app = new AppForDispatchTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__));
     $mockRouter = $this->getMockBuilder('PPI\\Framework\\Router\\ChainRouter')->disableOriginalConstructor()->getMock();
     $mockRouter->expects($this->once())->method('warmUp');
     $mockRouter->expects($this->once())->method('matchRequest')->willReturn(array('_controller' => 'TestController'));
     $mockControllerResolver = $this->getMockBuilder('PPI\\Framework\\Module\\Controller\\ControllerResolver')->disableOriginalConstructor()->getMock();
     $mockControllerResolver->expects($this->once())->method('getController')->willReturnCallback(function () {
         return function () {
             return new Response('Working Response');
         };
     });
     $mockControllerResolver->expects($this->once())->method('getArguments')->willReturn(array());
     $sm = new ServiceManager();
     $sm->setAllowOverride(true);
     $sm->set('Router', $mockRouter);
     $sm->set('ControllerResolver', $mockControllerResolver);
     $app->setServiceManager($sm);
     $request = HttpRequest::createFromGlobals();
     $response = new HttpResponse();
     $response = $app->dispatch($request, $response);
     $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertEquals($response->getContent(), 'Working Response');
 }