Skip to content

Commit

Permalink
Merge pull request #4315 from kenjis/fix-4288-FeatureTest-dies
Browse files Browse the repository at this point in the history
Fix #4288 FeatureTest dies when throws RedirectException/cached page
  • Loading branch information
MGatner authored Feb 26, 2021
2 parents ecb2507 + 7409c99 commit 4cbfe2c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
2 changes: 2 additions & 0 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ public function run(RouteCollectionInterface $routes = null, bool $returnRespons

$this->response->pretend($this->useSafeOutput)->send();
$this->callExit(EXIT_SUCCESS);
return;
}

try
Expand All @@ -343,6 +344,7 @@ public function run(RouteCollectionInterface $routes = null, bool $returnRespons
$this->sendResponse();

$this->callExit(EXIT_SUCCESS);
return;
}
catch (PageNotFoundException $e)
{
Expand Down
14 changes: 11 additions & 3 deletions system/Test/CIUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
32 changes: 28 additions & 4 deletions system/Test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';

Expand Down

0 comments on commit 4cbfe2c

Please sign in to comment.