问题
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