dongqie7806 2013-04-17 08:33
浏览 32
已采纳

从水貂访问Symfony 2的DI容器

I'm using behat with the mink extension to run fonctionnal tests. I've got a FeatureContext, extending the MinkContext.

I'm trying to pass custom parameters to my context, but I'm not really sure how. My idea was to put them in the behat.yml and then access them using Symfony's container, but I don't know how to access it from my FeatureContext.

Thanks

  • 写回答

1条回答 默认 最新

  • duanhui9840 2013-04-17 08:48
    关注

    As docs say:

    parameters is a simple array that will be passed into the constructor of your context class when instantiated, which happens before each scenario.

    That means that parameters defined in your behat.yml:

    default:
        context:
            parameters:
                my_parameter: my_value
    

    are passed to your context via a constructor:

    class FeatureContext extends RawMinkContext
    {
        private $parameters = array();
    
        public function __construct(array $parameters)
        {
            $this->parameters = $parameters;
        }
    }
    

    If your intention was to alter parameters from the Symfony container, you should rather do it in one of the Symfony configuration files (you should be running behat agains test environment, this way configuration is separate from dev and prod).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置