首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHPspec赋值和测试更新

PHPspec赋值和测试更新
EN

Stack Overflow用户
提问于 2015-05-17 17:43:01
回答 1查看 60关注 0票数 0

我有以下课程

代码语言:javascript
复制
class Customer {}

它还具有Id、Name、City和Country等属性以及像findById和findByCity这样的方法。我想编写一个规范测试,测试我的客户::save()函数是否像这样工作

代码语言:javascript
复制
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不断地把这个错误扔给我。

代码语言:javascript
复制
! 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

我应该如何进行这种测试?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-20 09:06:30

在模型和数据库之间执行集成测试,这不是phpspec的目标。客户的储蓄响应性不应该在Customer类中,它应该在域服务中。findById应由存储库类执行,save由实体管理器类执行,注入两者,并模拟它们。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30290007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档