kenjis / ci-phpunit-test

An easier way to use PHPUnit with CodeIgniter 3.x.
http://kenjis.github.io/ci-phpunit-test/
MIT License
587 stars 195 forks source link

fix: pre_controller can't modify $class / $method #394

Closed dezsi-istvan closed 1 year ago

dezsi-istvan commented 2 years ago

in codeigniter pre_controller methods modifying global $class $method variables can modify the route

code in codeigniter\framework\system\core\CodeIgniter.php

$EXT->call_hook('pre_controller');
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
$CI = new $class();

with this fix, this behavior will work in testing also

kenjis commented 2 years ago

Can you show a minimum sample code to modify $class $method variables ? Or please send a PR to https://github.com/kenjis/ci-app-for-ci-phpunit-test

dezsi-istvan commented 2 years ago
function pre_controller_hook_verify_permissions() {
  if( not_have_permission() ){
    $GLOBALS['class'] = 'MY_auth_access_denied'; //new controller
    $GLOBALS['method'] = 'index'; //new method
  }
}
kenjis commented 1 year ago

Thank you for sending this PR. I released as v3.0.4.