我上课主要是为了这个
$newItem = new SeriesDiscountDecorator($item);
$cart->remove($item);
$cart->add($newItem);
我的规格看起来像
$decoratedItem1->beConstructedWith([$item1]);
$cart->add($decoratedItem1)->shouldBeCalled();
但PHPSpec表示由于参数错误而无法进行$ cart->添加调用。实际上我的$ decoratedItem与Cart类所做的不同。如何写这样的规格吧?
PHPSpec返回:
method call:
- add(Domain\Discount\Decorator\SeriesDiscountDecorator:000000006b0917e60000000063743658 Object (
'decoratedItem' => Double\ItemInterface\P66:000000006b0917a60000000063743658 Object (
'objectProphecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)
)
))
on Double\Domain\Cart\Cart\P65 was not expected, expected calls were:
- add(exact(Double\Domain\Discount\Decorator\SeriesDiscountDecorator\P69:000000006b0917f90000000063743658 Object (
'objectProphecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)
'decoratedItem' => PhpSpec\Wrapper\Collaborator:000000006b0917b30000000063743658 Object (
'prophecy' => Prophecy\Prophecy\ObjectProphecy Object (*Prophecy*)
)
)))
答案 0 :(得分:0)
$cart->add(SeriesDiscountDecorator::class)->shouldBeCalled();
似乎是测试它的唯一方法,只要你在实例化你所指定的类中的对象并且你没有返回它。