我尝试使用http://blog.a-way-out.net/blog/2015/06/12/codeigniter3-phpunit/将phpunit测试代码添加到我已构建的网站 但它的抛出错误:
1) Homemodel_test::test_When_you_get_all_news_Then_you_get_one_item
LogicException: CodeIgniter instance is not instantiated yet. You can't use `$th
is->simple_cache` at the moment. Please fix your test code.
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestNull
CodeIgniter.php:18
E:\xampp\htdocs\CodeIgniter\application\helpers\language_helper.php:10
E:\xampp\htdocs\CodeIgniter\application\core\ROCKERS_Controller.php:51
E:\xampp\htdocs\CodeIgniter\application\controllers\Home.php:51
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestRequ
est.php:292
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestRequ
est.php:215
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestRequ
est.php:126
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestCase
.php:106
E:\xampp\htdocs\CodeIgniter\application\tests\models\home_model_test.php:25
FAILURES!
答案 0 :(得分:0)
这是因为您使用的是HMVC https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc。
ci-phpunit-test现在不支持HMVC。 请参阅https://github.com/kenjis/ci-phpunit-test/issues/34以查看最新状态。
答案 1 :(得分:0)
我也遇到了这个问题,但是情况有点不同。我注意到在调用$ this-> request()
之后,上下文“丢失”了$CI =& get_instance();
$CI->load->model('Random_model');
$CI->Random_model->save($data);
$output = $this->request('POST', 'https://example.com/random', $data);
// Now if I want to load model I need to call get_instance() again
$CI =& get_instance();
$CI->load->model('Other_model');
如果我不再次调用get_instance()。我会收到错误消息:
[phpunit] LogicException:未实例化CodeIgniter实例 然而。您目前无法使用
$this->load
。请修正您的测试 代码。