Skip to content

Commit

Permalink
Test for #11819
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Jun 18, 2017
1 parent 6359777 commit a24990c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/_data/controllers/ExceptionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

class ExceptionController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
throw new \Exception('whups bad controller');
}

public function secondAction()
{
return 'I should be displayed';
}
}
3 changes: 3 additions & 0 deletions tests/_data/views/exception/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

echo "We are in index";
3 changes: 3 additions & 0 deletions tests/_data/views/exception/second.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

echo "We are in second";
68 changes: 68 additions & 0 deletions tests/integration/Mvc/Dispatcher/ForwardCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Phalcon\Test\Integration\Mvc\Dispatcher;

use Phalcon\Mvc\View;
use IntegrationTester;
use Phalcon\Events\Manager;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Application;
use Phalcon\Di\FactoryDefault;

/**
* \Phalcon\Test\Integration\Mvc\Dispatcher\ForwardCest
* Tests the Phalcon\Mvc\Dispatcher
*
* @copyright (c) 2011-2017 Phalcon Team
* @link http://www.phalconphp.com
* @author Serghei Iakovlev <serghei@phalconphp.com>
* @package Phalcon\Test\Integration\Mvc\Dispatcher
*
* The contents of this file are subject to the New BSD License that is
* bundled with this package in the file docs/LICENSE.txt
*
* If you did not receive a copy of the license and are unable to obtain it
* through the world-wide-web, please send an email to license@phalconphp.com
* so that we can send you a copy immediately.
*/
class ForwardCest
{
/**
* @issue 11819
* @param IntegrationTester $I
*/
public function handlingException(IntegrationTester $I)
{
$di = new FactoryDefault();
$di->set('view', function () {
$view = new View();
$view->setViewsDir(PATH_DATA . 'views/');

return $view;
}, true);

$eventsManager = new Manager();

$eventsManager->attach('dispatch:beforeException', function ($event, $dispatcher, $exception) {
$dispatcher->forward([
'controller' => 'exception',
'action' => 'second'
]);

// Prevent the exception from bubbling
return false;
});

$dispatcher = new Dispatcher();
$dispatcher->setEventsManager($eventsManager);

$di->setShared('dispatcher', $dispatcher);

$application = new Application();
$application->setEventsManager(new Manager());
$application->setDI($di);

$_GET['_url'] = '/exception';
$I->assertSame("I should be displayed", $application->handle()->getContent());
}
}

0 comments on commit a24990c

Please sign in to comment.