我有以下课程
class Customer {}它还具有Id、Name、City和Country等属性以及像findById和findByCity这样的方法。我想编写一个规范测试,测试我的客户::save()函数是否像这样工作
function it_should_update_customer_name_on_save()
{
$customer = $this->findById(1);
$customer->Name = 'Compu-Global-Hyper-Mega-Net';
$customer->save();
$this->findById(1)->shouldReturn('Compu-Global-Hyper-Mega-Net');
}但是phpspec不断地把这个错误扔给我。
! it should update name on save (111ms)
error: Argument 1 passed to PHPSpec2\Wrapper\ArgumentsUnwrapper::unwrapAll() must be of the type array, string given,
called in /Users/kristiannissen/Documents/php/phpecosrv/vendor/phpspec/phpspec2/src/PHPSpec2/Prophet/ObjectProphet.php
on line 126 and defined in
/Users/kristiannissen/Documents/php/phpecosrv/vendor/phpspec/phpspec2/src/PHPSpec2/Wrapper/ArgumentsUnwrapper.php line
10我应该如何进行这种测试?
发布于 2015-06-20 09:06:30
在模型和数据库之间执行集成测试,这不是phpspec的目标。客户的储蓄响应性不应该在Customer类中,它应该在域服务中。findById应由存储库类执行,save由实体管理器类执行,注入两者,并模拟它们。
https://stackoverflow.com/questions/30290007
复制相似问题