如何避免在 PHP 单元测试的特定时刻显示输出?
How to avoid output display at a specific moment of a PHP Unit test?
在PHP单元测试中,例如:
class AgentBoardTest extends CommonTestCase
{
/**
* @test
*/
public function display()
{
$very_long_string = "..................";
echo $very_long_string;
}
}
我不希望 $very_long_string 被打印到标准输出,尤其是当 echo 在多种功能。怎么做?
基本上,我找到的最佳解决方案是使用 PHP 的本机输出缓冲:
class AgentBoardTest extends CommonTestCase
{
/**
* @test
*/
public function display()
{
ob_start();
$very_long_string = "..................";
echo $very_long_string;
ob_end_clean();
}
}
在PHP单元测试中,例如:
class AgentBoardTest extends CommonTestCase
{
/**
* @test
*/
public function display()
{
$very_long_string = "..................";
echo $very_long_string;
}
}
我不希望 $very_long_string 被打印到标准输出,尤其是当 echo 在多种功能。怎么做?
基本上,我找到的最佳解决方案是使用 PHP 的本机输出缓冲:
class AgentBoardTest extends CommonTestCase
{
/**
* @test
*/
public function display()
{
ob_start();
$very_long_string = "..................";
echo $very_long_string;
ob_end_clean();
}
}