Cakephp单元测试中不完整、跳过或有风险的测试
我使用的是CakePHP版本:3.7.7 我已经写了下面的测试用例Cakephp单元测试中不完整、跳过或有风险的测试,php,unit-testing,phpunit,cakephp-3.0,Php,Unit Testing,Phpunit,Cakephp 3.0,我使用的是CakePHP版本:3.7.7 我已经写了下面的测试用例 public function testDashboard() { $this->get( __('user/dashboard') ); $branches = $this->viewVariable('branches'); $this->assertEquals(1, !empty($branches)); } 对于此控制器代码 public function das
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
如果:
放在第一位()
而不是toArray()
$branchs=[]
感谢您的时间。例如,当评估模板时触发异常时,可能会发生这种情况,这将导致用于捕获模板输出的输出缓冲区未关闭,从而导致该错误。这在CAKEPHP中是固定的,因此您可能需要考虑升级。
也就是说,检查您的CakePHP调试/错误日志,您应该在其中找到触发此问题的潜在错误。您是否需要使用
first()
或toArray()
取决于处理该数据的代码的期望值。在我的例子中,分支中有100多个条目导致此错误,因此我将其减少到<10,这对我来说很好。请始终提及您的确切CakePHP版本(最后一行是lib/Cake/VERSION.txt
或vendor/cakephp/cakephp/VERSION.txt
)-谢谢!