在测试执行期间隐藏输出

MyM*_*ial 11 php testing phpunit

我的php代码中有一些var_dump(我知道最后一定没有,但仍然是),并且在测试运行时它们向控制台输出非必要的信息,有没有一种方法可以忽略一些代码执行?

我试过了

/**
 * @codeCoverageIgnore
 */
Run Code Online (Sandbox Code Playgroud)

// @codeCoverageIgnoreStart
print '*';
// @codeCoverageIgnoreEnd
Run Code Online (Sandbox Code Playgroud)

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

Mat*_*teo 17

您可以将setOutputCallback设置为do do function.其效果是抑制测试或测试类中打印的任何输出.

例如:

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 *");
    }

}
Run Code Online (Sandbox Code Playgroud)

您可以在doc中找到一些参考

希望这有帮助