You should rather mock $GLOBALS['dbi'] than changing random places in code.