Codeigniter 3.0 phpunit测试不工作


Codeigniter 3.0 phpunit testing not working

我尝试使用http://blog.a-way-out.net/blog/2015/06/12/codeigniter3-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!

这是因为您使用的是HMVChttps://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc.

ci phpunit测试现在不支持HMVC。看见https://github.com/kenjis/ci-phpunit-test/issues/34以检查最新状态。

我也遇到了这个问题,但情况有所不同。我注意到调用$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。请修正你的测试密码

相关文章: