小编use*_*273的帖子

phpspec,我想在调度程序上调用shouldBeCalled

我搜索关于调度程序symfony2的phpspec进行功能测试的可能性

我想这样做:

$dispatcher->dispatch('workflow.post_extract', $event)->shouldBeCalled();
Run Code Online (Sandbox Code Playgroud)

我的代码在这里:

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);
}
Run Code Online (Sandbox Code Playgroud)

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 …
Run Code Online (Sandbox Code Playgroud)

php phpspec

1
推荐指数
1
解决办法
630
查看次数

标签 统计

php ×1

phpspec ×1