public function testDispatcher()
 {
     Phalcon\DI::reset();
     $di = new Phalcon\DI();
     $di->set('response', new \Phalcon\Http\Response());
     $dispatcher = new Phalcon\Mvc\Dispatcher();
     $dispatcher->setDI($di);
     $this->assertInstanceOf('Phalcon\\DI', $dispatcher->getDI());
     $di->set('dispatcher', $dispatcher);
     $dispatcher->setControllerName('index');
     $dispatcher->setActionName('index');
     $dispatcher->setParams(array());
     try {
         $dispatcher->dispatch();
         $this->assertTrue(FALSE, 'oh, Why?');
     } catch (Phalcon\Exception $e) {
         $this->assertEquals($e->getMessage(), "IndexController handler class cannot be loaded");
         $this->assertInstanceOf('Phalcon\\Mvc\\Dispatcher\\Exception', $e);
     }
     $dispatcher->setControllerName('essai');
     $dispatcher->setActionName('index');
     $dispatcher->setParams(array());
     try {
         $dispatcher->dispatch();
         $this->assertTrue(FALSE, 'oh, Why?');
     } catch (Phalcon\Exception $e) {
         $this->assertEquals($e->getMessage(), "EssaiController handler class cannot be loaded");
         $this->assertInstanceOf('Phalcon\\Mvc\\Dispatcher\\Exception', $e);
     }
     $dispatcher->setControllerName('test0');
     $dispatcher->setActionName('index');
     $dispatcher->setParams(array());
     try {
         $dispatcher->dispatch();
         $this->assertTrue(FALSE, 'oh, Why?');
     } catch (Phalcon\Exception $e) {
         $this->assertEquals($e->getMessage(), "Test0Controller handler class cannot be loaded");
         $this->assertInstanceOf('Phalcon\\Mvc\\Dispatcher\\Exception', $e);
     }
     $dispatcher->setControllerName('test1');
     $dispatcher->setActionName('index');
     $dispatcher->setParams(array());
     try {
         $dispatcher->dispatch();
         $this->assertTrue(FALSE, 'oh, Why?');
     } catch (Phalcon\Exception $e) {
         $this->assertEquals($e->getMessage(), "Action 'index' was not found on handler 'test1'");
     }
     $dispatcher->setControllerName('test2');
     $dispatcher->setActionName('index');
     $dispatcher->setParams(array());
     $controller = $dispatcher->dispatch();
     $this->assertInstanceOf('Test2Controller', $controller);
     $dispatcher->setControllerName('test2');
     $dispatcher->setActionName('essai');
     $dispatcher->setParams(array());
     try {
         $dispatcher->dispatch();
         $this->assertTrue(FALSE, 'oh, Why?');
     } catch (Phalcon\Exception $e) {
         $this->assertEquals($e->getMessage(), "Action 'essai' was not found on handler 'test2'");
     }
     $dispatcher->setControllerName('test2');
     $dispatcher->setActionName('other');
     $dispatcher->setParams(array());
     $controller = $dispatcher->dispatch();
     $this->assertInstanceOf('Test2Controller', $controller);
     $dispatcher->setControllerName('test2');
     $dispatcher->setActionName('another');
     $dispatcher->setParams(array());
     $dispatcher->dispatch();
     $value = $dispatcher->getReturnedValue();
     $this->assertEquals($value, 100);
     $dispatcher->setControllerName('test2');
     $dispatcher->setActionName('anotherTwo');
     $dispatcher->setParams(array(2, "3"));
     $dispatcher->dispatch();
     $value = $dispatcher->getReturnedValue();
     $this->assertEquals($value, 5);
     $dispatcher->setControllerName('test2');
     $dispatcher->setActionName('anotherthree');
     $dispatcher->setParams(array());
     $dispatcher->dispatch();
     $value = $dispatcher->getActionName();
     $this->assertEquals($value, 'anotherfour');
     $value = $dispatcher->getReturnedValue();
     $this->assertEquals($value, 120);
     $dispatcher->setControllerName('test2');
     $dispatcher->setActionName('anotherFive');
     $dispatcher->setParams(array("param1" => 2, "param2" => 3));
     $dispatcher->dispatch();
     $value = $dispatcher->getReturnedValue();
     $this->assertEquals($value, 5);
     $dispatcher->setControllerName('test7');
     $dispatcher->setActionName('service');
     $dispatcher->setParams(array());
     $dispatcher->dispatch();
     $value = $dispatcher->getReturnedValue();
     $this->assertEquals($value, "hello");
     $dispatcher->setControllerName('nofound');
     $dispatcher->setActionName('index');
     $dispatcher->setParams(array());
     $dispatcher->setErrorHandler('Error::index', Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND);
     try {
         $dispatcher->dispatch();
     } catch (Phalcon\Exception $e) {
         $this->assertEquals($e->getMessage(), "ErrorController handler class cannot be loaded");
     }
 }