PHPUnit 测试用例感知 symfony2 依赖注入容器
我实际上正在测试我创建的 bundle。所有代码都经过完全单元测试,但现在,我想测试我的 symfony2 服务是否可以毫无问题地请求。
为此,我的测试用例中需要 symfony2 依赖注入容器。我怎样才能做到这一点?
I'm actually testing a bundle that I created. All the code is fully unit tested but now, I want to test if my symfony2 services can be request without any trouble.
For that, I need the symfony2 dependency injection container in my test case. How can I do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近问了一个与此类似的问题,因为我只需要验证器,但是首先回答我的问题的人有一个可以访问整个容器的解决方案。
基本上,您可以拆开
WebTestCase
来查看它如何构建 Symfony2 环境,并创建您自己的 Symfony 感知基类。这是答案,我希望它有所帮助: Symfony2:测试实体验证约束
I recently asked a question similar to this in that I needed just the validator, however the person who replied to my question first had a solution which gave access to the whole container.
Basically you can pick apart
WebTestCase
in order to see how it builds the Symfony2 environment and make your own base class which is Symfony aware as it were.Here is the answer, I hope it helps: Symfony2: Testing entity validation constraints