【发布时间】:2021-01-03 10:30:06
【问题描述】:
我使用的是 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 = []
如何解决这个问题?
感谢您的宝贵时间。
【问题讨论】:
-
请务必提及您确切的 CakePHP 版本(
lib/Cake/VERSION.txt或vendor/cakephp/cakephp/VERSION.txt中的最后一行) - 谢谢!
标签: php unit-testing phpunit cakephp-3.0