使用 phpspec 测试输出缓冲

testing output buffering with phpspec

给定以下 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; }
}

我认为这是唯一的方法:

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