我有我的Laravel5應用程序的方法我想在PhpSpec測試,但它不斷拋出以下錯誤:PhpSpec預計致電確切
App/Helpers/RecurrRule
37 ! it should return a recurrence collection method call:
Double\ChurchRepositoryInterface\P6->getChurchTimezone(1) was not expected.
Expected calls are:
- getChurchTimeZone(exact(1))
的方法傳遞一個數組,我想嘲笑該模型的getChurchTimezone方法返回一個時區。
方法:
public function __construct(Rule $rule, ArrayTransformer $arrayTransformer, ChurchRepositoryInterface $church)
{
$this->rule = $rule;
$this->arrayTransformer = $arrayTransformer;
$this->church = $church;
}
public function getRecurrenceCollection($schedule)
{
$timezone = $this->church->getChurchTimezone($schedule['church_id']);
// more code
}
在我的其他規格,我經常做這樣的事情$double->method('someArgument')->willReturn('blah')
,但由於某種原因這個特定的情況下不工作,我百思不得其解,爲什麼。我試着給它一個數組的副本,我試着直接給它一個整數,我試着把$ this-> church-> getChurchTimezone放到它自己的方法中,並將它傳遞給一個數組或一個整型數組,但無論PhpSpec總是以預期的呼叫錯誤的「確切」返回。
規格:
class RecurrRuleSpec extends ObjectBehavior
{
protected $schedule = [
'church_id' => 1,
'start' => '2014-11-21 10:36:07',
'end' => '2014-11-21 11:36:07',
'recurr_rule' => 'FREQ=WEEKLY;BYDAY=SU;',
'recurr_until' => '2015-02-22 10:36:07',
];
function it_is_initializable()
{
$this->shouldHaveType('App\Helpers\RecurrRule');
}
/**
* Setup our mock, with doubles matching our constructor
*/
function let($rule, $arrayTransformer, $church)
{
$rule->beADoubleOf('\Recurr\Rule');
$arrayTransformer->beADoubleOf('\Recurr\Transformer\ArrayTransformer');
$church->beADoubleOf('\App\Repositories\ChurchRepositoryInterface');
$this->beConstructedWith($rule, $arrayTransformer, $church);
}
function it_should_return_a_recurrence_collection($rule, $arrayTransformer, $church)
{
$church->getChurchTimeZone(1)->willReturn('Europe/Dublin');
// $church->getChurchTimeZone($this->schedule['church_id'])->willReturn('Europe/Dublin');
// $church->getChurchTimeZone(Argument::any())->willReturn('Europe/Dublin');
$rule->createFromString()->willReturn([]);
$arrayTransformer->transform()->willReturn([]);
$this->getRecurrenceCollection($this->schedule)->shouldReturn([]);
}
下面是一個使用同樣的方法,並通過
function it_should_return_a_one_dimensional_numeric_array_of_servers($config)
{
$expectedResult = ['domain.com', 'domain2.com'];
$config->get('servers')->willReturn($this->configGetReturn);
$this->serverArray()->shouldBeArray();
$this->serverArray()->shouldEqual($expectedResult);
}