【发布时间】:2015-05-17 17:43:01
【问题描述】:
我有以下课程
class Customer {}
它具有诸如 Id、Name、City 和 Country 之类的属性以及诸如 findById 和 findByCity 之类的方法。我想编写一个规范测试来测试我的 Customer::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
我应该如何进行这种测试?
【问题讨论】:
-
如果不是大量的代码,你能给我们足够的代码让我们自己重现错误吗? :)
-
$customer = $this->findById(1);返回 Customer() 的新实例。但是你将如何在 phpspec 中进行这种测试呢? 1) 找到一个现有的对象,2) 改变它的值,3) 保存它,4) 测试改变已经发生
-
@kristiannissen 我建议你先去阅读 phpspec 手册。您似乎缺少相当基本的概念:phpspec.net/en/latest/manual/introduction.html 另请阅读:techportal.inviqa.com/2013/07/23/…