1 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
我還沒有找到令人滿意的方法來做到這一點(diǎn)。我最終創(chuàng)建了一個(gè)bootstrap.php包含在 phpunit.xml.dist 中的文件
它看起來像這樣:
<?php
require(__DIR__ . '/../vendor/autoload.php');
// this is a copy of the default index.php shipped with CodeIgnitor
// The system and application_folder variables are replaced
// Also, in this version we do not bootstrap the framework and rather include our own version below
require('loader.php');
// this is a modified version of system/core/CodeIgniter.php
// they do bootstrapping, routing, and dispatching in one place
// so we can't use the whole file because dispatching fails when running tests
require('framework.php');
// set up the test environment database connection
putenv('DATABASE_HOST=localhost');
putenv('DATABASE_USER=user');
putenv('DATABASE_PASSWORD=password');
putenv('DATABASE=control_panel');
// CI uses a singleton approach and creates an instance of a child of this class during dispatch
// We need to make sure that the singleton holder is populated
$controller = new CI_Controller();
這framework.php是該 CodeIgnitor 文件的精簡(jiǎn)版本,我在其中刪除了路由和調(diào)度邏輯。我已經(jīng)把這些文件作為要點(diǎn)
CI 中加載的癥結(jié)似乎存在于控制器中system/core/Controller.php,控制器旨在成為“讓 CI 可以作為一個(gè)大型超級(jí)對(duì)象運(yùn)行”的東西。該load_class函數(shù)(在 中聲明system/core/Common.php)負(fù)責(zé)查找和加載類文件。
我還應(yīng)該包括我的composer.json文件。我正在使用它進(jìn)行測(cè)試(CI 3.1.12 不使用作曲家)
{
"require": {
"guzzlehttp/guzzle": "^6.5"
},
"require-dev": {
"phpunit/phpunit": "^9.1"
},
"autoload": {
"psr-4": {
"Test\\": "tests/"
},
"classmap": ["application/", "system/"]
}
}
我真的很想避免加載所有東西,并希望能夠模擬出點(diǎn)點(diǎn)滴滴,但我對(duì) CodeIgnitor 適合這一點(diǎn)并不樂觀。
無論如何,這種方法至少可以讓我啟動(dòng)我的應(yīng)用程序。必須有更好的方法來做到這一點(diǎn),如果很難正確測(cè)試,我不敢相信該框架會(huì)如此受歡迎。
- 1 回答
- 0 關(guān)注
- 133 瀏覽
添加回答
舉報(bào)