/** * Tests that an exception is thrown if a handler class does not exist. * @expectedException Exception * @expectedExceptionMessage Cannot instantiate instance of Vectorface\SnappyRouter\Handler\NonexistantHandler */ public function testInvalidHandlerClass() { $config = $this->getStandardConfig(); $config[Config::KEY_HANDLERS]['InvalidHandler'] = array('class' => 'Vectorface\\SnappyRouter\\Handler\\NonexistantHandler'); $router = new SnappyRouter(new Config($config)); // an example MVC request $path = '/Test/test'; $query = array('jsoncall' => 'testMethod'); $response = $router->handleHttpRoute($path, $query, array(), 'get'); $expectedResponse = 'No handler responded to request.'; $this->assertEquals($expectedResponse, $response); }
/** * Tests that the default action of a controller is to render a default * view from the view engine. */ public function testRenderDefaultView() { $routerOptions = array(Config::KEY_DI => 'Vectorface\\SnappyRouter\\Di\\Di', Config::KEY_HANDLERS => array('ControllerHandler' => array(Config::KEY_CLASS => 'Vectorface\\SnappyRouter\\Handler\\ControllerHandler', Config::KEY_OPTIONS => array(Config::KEY_CONTROLLERS => array('TestController' => 'Vectorface\\SnappyRouterTests\\Controller\\TestDummyController'), ControllerHandler::KEY_VIEWS => array(ControllerHandler::KEY_VIEWS_PATH => __DIR__ . '/../Controller/Views'))))); $router = new SnappyRouter(new Config($routerOptions)); $path = '/test/default'; $response = $router->handleHttpRoute($path, array(), array(), 'GET'); $expected = file_get_contents(__DIR__ . '/../Controller/Views/test/default.twig'); $this->assertEquals($expected, $response); }