【问题标题】:PHPUnit test shows error with Global while running test in --order-by=reversePHPUnit 测试在 --order-by=reverse 中运行测试时显示全局错误
【发布时间】:2018-08-27 09:36:35
【问题描述】:

我们正在尝试修复我们现有的测试用例,同时以相反的顺序运行。我们最近将 PHPUnit 更新为 PHPUnit 7.3(参考:https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-7.3.md

错误:

未定义索引:日志

当我在--order-by=reverse 中运行测试时,以下行显示错误。

 $GLOBALS['log']->error(__METHOD__ . ": Not found");

我尝试通过添加具有以下内容的 setUp() 函数来解决此问题:

    protected function setUp()
    {
        $GLOBALS['log'] = '';
    }

Error: Call to a member function error() on string

我不确定如何编写此错误,因为每个函数都会有不同的错误日志消息。

类似的功能:

$GLOBALS['log']->debug(__METHOD__ . $message);

任何建议将不胜感激。谢谢。

【问题讨论】:

    标签: php phpunit


    【解决方案1】:

    找到答案

    protected function setUp()
    {
        $GLOBALS['log'] = $this
            ->getMockBuilder('LoggerTemplate')
            ->setMethods(array('log', 'debug'))
            ->getMock();
    }
    
    protected function tearDown()
    {
        unset($GLOBALS['log']);
    }
    

    希望这对某人有帮助!!!!

    【讨论】:

      猜你喜欢
      • 2020-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      • 2014-05-08
      • 1970-01-01
      相关资源
      最近更新 更多