Replace Symfony service in tests for php 7.2

六月ゝ 毕业季﹏ 提交于 2019-12-13 14:07:42

问题


I'm trying to upgrade my application working on Symfony 3.3 and php 7.1 to php 7.2, but I encountered tons of DEPRECATED messages when I run phpunit. Most annoying is:

The "user.user_service" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0: 7x

This is because I have this lines at setUp method:

$this->userService = $this->getMockBuilder(UserService::class)
    ->setMethods(['update'])
    ->getMock();
$container->set('user.user_service', $this->userService);

7x is because I have 7 test cases at that class, and setUp is fired for each of them. How could I handle this issue? I can't remove this mock because it's important.

I can't understand why Symfony point exactly to this testcase, because I have lots of services replaced this way across all my tests. I don't replace this service anywhere before this setUp method, so it's strange.

来源:https://stackoverflow.com/questions/51026726/replace-symfony-service-in-tests-for-php-7-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!