Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp单元测试中不完整、跳过或有风险的测试_Php_Unit Testing_Phpunit_Cakephp 3.0 - Fatal编程技术网

Cakephp单元测试中不完整、跳过或有风险的测试

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

我使用的是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

如果:

  • 如果我把
    放在第一位()
    而不是
    toArray()
  • 或者只需设置
    $branchs=[]
  • 如何解决这个问题


    感谢您的时间。

    例如,当评估模板时触发异常时,可能会发生这种情况,这将导致用于捕获模板输出的输出缓冲区未关闭,从而导致该错误。这在CAKEPHP中是固定的,因此您可能需要考虑升级。


    也就是说,检查您的CakePHP调试/错误日志,您应该在其中找到触发此问题的潜在错误。您是否需要使用
    first()
    toArray()
    取决于处理该数据的代码的期望值。

    在我的例子中,
    分支中有100多个条目导致此错误,因此我将其减少到<10,这对我来说很好。

    请始终提及您的确切CakePHP版本(最后一行是
    lib/Cake/VERSION.txt
    vendor/cakephp/cakephp/VERSION.txt
    )-谢谢!