diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 5e54824a1a32..9d58c4f0f99f 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -326,6 +326,7 @@ public function run(RouteCollectionInterface $routes = null, bool $returnRespons $this->response->pretend($this->useSafeOutput)->send(); $this->callExit(EXIT_SUCCESS); + return; } try @@ -343,6 +344,7 @@ public function run(RouteCollectionInterface $routes = null, bool $returnRespons $this->sendResponse(); $this->callExit(EXIT_SUCCESS); + return; } catch (PageNotFoundException $e) { diff --git a/system/Test/CIUnitTestCase.php b/system/Test/CIUnitTestCase.php index c8d312b1c7f6..28418767082c 100644 --- a/system/Test/CIUnitTestCase.php +++ b/system/Test/CIUnitTestCase.php @@ -20,8 +20,12 @@ use CodeIgniter\Events\Events; use CodeIgniter\Session\Handlers\ArrayHandler; use CodeIgniter\Test\Mock\MockCache; +use CodeIgniter\Test\Mock\MockCodeIgniter; use CodeIgniter\Test\Mock\MockEmail; use CodeIgniter\Test\Mock\MockSession; +use Config\App; +use Config\Autoload; +use Config\Modules; use Config\Services; use Exception; use PHPUnit\Framework\TestCase; @@ -547,9 +551,13 @@ public function seeNumRecords(int $expected, string $table, array $where) */ protected function createApplication() { - $path = __DIR__ . '/../bootstrap.php'; - $path = realpath($path) ?: $path; - return require $path; + // Initialize the autoloader. + Services::autoloader()->initialize(new Autoload(), new Modules()); + + $app = new MockCodeIgniter(new App()); + $app->initialize(); + + return $app; } /** diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index 0fc476d3f731..9625506bc22f 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -9,6 +9,7 @@ * file that was distributed with this source code. */ +use CodeIgniter\Config\DotEnv; use CodeIgniter\Router\RouteCollection; use CodeIgniter\Services; use Config\Autoload; @@ -83,10 +84,33 @@ class_alias('Config\Services', 'CodeIgniter\Services'); } -// Launch the autoloader to gather namespaces (includes composer.json's "autoload-dev") -$loader = Services::autoloader(); -$loader->initialize(new Autoload(), new Modules()); -$loader->register(); // Register the loader with the SPL autoloader stack. +// Initialize and register the loader with the SPL autoloader stack. +Services::autoloader()->initialize(new Autoload(), new Modules())->register(); + +// Now load Composer's if it's available +if (is_file(COMPOSER_PATH)) +{ + /* + * The path to the vendor directory. + * + * We do not want to enforce this, so set the constant if Composer was used. + */ + if (! defined('VENDORPATH')) + { + define('VENDORPATH', realpath(ROOTPATH . 'vendor') . DIRECTORY_SEPARATOR); + } + + require_once COMPOSER_PATH; +} + +// Load environment settings from .env files into $_SERVER and $_ENV +require_once SYSTEMPATH . 'Config/DotEnv.php'; + +$env = new DotEnv(ROOTPATH); +$env->load(); + +// Always load the URL helper, it should be used in most of apps. +helper('url'); require_once APPPATH . 'Config/Routes.php';