在PHPUnit测试执行期间隐藏输出


Hide output during PHPUnit test execution

我在我的php代码中有一些var_dumps(我明白最后必须没有,但仍然没有),而测试正在运行时,它们输出非必要的信息到控制台,是否有一种方法可以忽略一些代码执行?

I've try

/**
 * @codeCoverageIgnore
 */

// @codeCoverageIgnoreStart
print '*';
// @codeCoverageIgnoreEnd

但是这只是忽略了覆盖,仍然执行代码。

可以将setOutputCallback设置为不做任何事情的函数。其效果是抑制在测试或被测试类中打印的任何输出。

为例:

namespace Acme'DemoBundle'Tests;

class NoOutputTest extends 'PHPUnit_Framework_TestCase {
    public function testSuppressedOutput()
    {
        // Suppress  output to console
        $this->setOutputCallback(function() {});
        print '*';
        $this->assertFalse(false, "Don't see the *");
    }
}

你可以在文档

中找到一些参考。

希望对您有所帮助