BDDとはBehavior-driven developmentの略で、プログラムに期待される振る舞いをテストするプログラム開発手法の一つ(だそうです。)。 See
テストコードの可読性が上げ、かつテストコード実装の負担をなるべく小さくする目的のもとで導入されます。
PHPではPHPUnitに加えて以下のパッケージを追加することでBDDっぽいテストの記述が可能です。
本記事ではまず一番上のSpecifyについて。 実装例は例えば以下の様な感じ
Specify
public function testValidation()
{
$this->describe("ユーザが", function() {
$this->it("ユーザ名を持たない場合", function() {
$this->user->username = null;
$this->assertFalse($this->user->validate(['username']));
});
});
}
これをSpecifyを使って実装するともう少し短くかけます。
public function testValidation()
{
$this->specify("ユーザ名がない場合", function() {
$this->user->username = null;
expect_not($this->user->validate(['username']));
});
}


