【发布时间】:2017-12-08 08:29:13
【问题描述】:
我有以下名为 Item_service 的库:
class Item_Service {
private $items;
function __construct(Items $items)
{
$this->items = $items;
}
其中Items 是controllers/Items.php 的一个实例。
在名为Items_test.php 的测试类中,我尝试使用以下行加载Item_service 库:
$items = $this->CI->load->library('items/Item_service');
然后我收到错误提示
TypeError: Argument 1 passed to Item_Service::__construct() must be an instance of Items, null given
我的测试类是基于kenjis/ci-phpunit-test编写的。
我应该如何将控制器注入这个库以便能够测试这个库?另外,我可以测试控制器本身吗?控制器内部有很多辅助方法。
【问题讨论】:
-
@NikuNj Rathod - 为什么您在编辑中为 OP 的问题添加了额外的代码?
-
是的@MagnusEriksson。我刚刚拒绝了该编辑,因为它显然与 OP 的意图相冲突
标签: php codeigniter unit-testing testing phpunit