给出以下PHPUnit代码,如何将其转换为phpspec测试?
$content = 'Hello world!';
ob_start();
$this->displayer->output($content);
$output = ob_get_clean();
$this->assertEquals($content, $output);
$this->displayer->output($content)
所做的只是echo
$content
:
class Displayer {
public function display(string $content) { echo $content; }
}
答案 0 :(得分:1)
我相信这是唯一的方法:
use PHPUnit\Framework\Assert;
public function it_outputs_a_string()
{
$content = 'Hello world!';
ob_start();
$this->display($content);
$output = ob_get_clean();
Assert::assertEquals($content, $output);
}