问题描述
我正在使用CakePHP版本:3.7.7
我已经写了下面的测试用例。
public function testDashboard()
{
$this->get( __('user/dashboard') );
$branches = $this->viewVariable('branches');
$this->assertEquals(1,!empty($branches));
}
对于此控制器代码
public function dashboard()
{
$this->loadModel('Branches');
$this->loadModel('Zones');
$branches = $this->Branches->find()
->where( ['Branches.status' => 1] )
->contain(['Zones'])
->order(['Branches.id' => 'ASC','Branches.name' => 'ASC'])
->toArray();// If I put first() then it works
$this->set(compact('branches'));
}
当我运行测试用例时,我会遇到错误
测试代码或测试代码没有(仅)关闭自己的输出缓冲区 可以,但是测试不完整,已跳过或存在风险! 测试:1,断言:2,冒险:1。
我可以在以下情况下工作
- 如果我放
first()
代替toArray()
- 或者只需设置
$branches = []
如何解决此问题?
感谢您的时间。