0
我搜索的可能性,以使有關調度的Symfony2 phpspec一個functionnal測試phpspec,我想呼籲shouldBeCalled在調度
我想做到這一點:
$dispatcher->dispatch('workflow.post_extract', $event)->shouldBeCalled();
我的代碼是在這裏:
function it_should_dispatch_post_extract(
EventDispatcher $dispatcher, GenericEvent $event,
TransformerInterface $transformer, ContextInterface $context, LoaderInterface $loader
)
{
$c = new \Pimple([
'etl' => new \Pimple([
'e' => function() {
return new ExtractorMock();
},
't' => function() {
return new Transformer();
},
'l' => function() {
return new Loader();
},
'c' => function() {
return new Context();
},
])
]);
$dispatcher->dispatch('workflow.post_extract', $event)->shouldBeCalled();
$this->process($c);
}
phpspec的答案是:
! should dispatch post extract
method call:
Double\Symfony\Component\EventDispatcher\EventDispatcher\P10->dispatch("workflow.post_extract", Symfony\Component\EventDispatcher\GenericEvent:0000000043279e10000000004637de0f)
was not expected.
Expected calls are:
- dispatch(exact("workflow.post_extract"), exact(Double\Symfony\Component\EventDispatcher\GenericEvent\P11:0000000043279dce000000004637de0f))
他對我說了同樣的錯誤: !應派遣提取 方法調用: Double \ Symfony \ Component \ EventDispatcher \ EventDispatcher \ P10-> dispatch(「workflow.post_transform」,Symfony \ Component \ EventDispatcher \ GenericEvent:0000000021772e420000000058f15b47) 不是預期的。 預期調用爲: - 調度(確切(「workflow.post_extract」),類型(Symfony \ Component \ EventDispatcher \ GenericEvent)) – user3393273
這不一樣。注意事件名稱的不同(「workflow.post_transform」與「workflow.post_extract」)。你似乎在派遣不止一個事件。另外請注意,它不再期望具體的對象,而是一個類型。 –
大分析,在進程函數調用中有效地有四個調度,在有調度事件post_extract後我必須添加其他調度post_transform並且它工作。 你認爲我可以在不同的功能測試中一對一地調用dispatch嗎? – user3393273