我想用標量值使用let函數。 我的問題是,價格是一個雙,我預計一個int 5.phpspec標量值讓
function let(Buyable $buyable, $price, $discount)
{
$buyable->getPrice()->willReturn($price);
$this->beConstructedWith($buyable, $discount);
}
function it_returns_the_same_price_if_discount_is_zero($price = 5, $discount = 0) {
$this->getDiscountPrice()->shouldReturn(5);
}
錯誤:
✘ it returns the same price if discount is zero
expected [integer:5], but got [obj:Double\stdClass\P14]
有沒有辦法使用let函數注入5?
這會工作作比較,但我乘的返回值在getDiscountPrice函數中,所以它會在getDiscountPrice函數中失敗,而不是在測試中。在willReturn中投入雙倍也失敗。 – timg