Hide output during PHPUnit test execution

僤鯓⒐⒋嵵緔 提交于 2019-12-23 07:13:09

问题


I have some var_dumps in my php code (i understand what there must be none in the end, but still), and while tests are running they outputs non necessary information to console, is there a method to ignore some code execution?

I've tried

/**
 * @codeCoverageIgnore
 */

and

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

But this just ignores coverage, and still executes the code.


回答1:


You can set the setOutputCallback to a do nothing function. The effect is to suppress any output printed in the test or in the tested class.

As Example:

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

}

You can find some reference in the doc

Hope this help




回答2:


I don't know is it a good style but i do so:

ob_start();
echo 200;
$output = ob_get_clean();


来源:https://stackoverflow.com/questions/31717740/hide-output-during-phpunit-test-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!