我正在尝试将我在Symfony 3.3和php 7.1上运行的应用程序升级到php 7.2,但是当我运行phpunit时遇到了大量的DEPRECATED消息 . 最烦人的是:

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

这是因为我在setUp方法中有这些行:

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

7x是因为我在该类中有7个测试用例,并且为每个测试用例触发了setUp . 我怎么能处理这个问题?我不能删除这个模拟因为它很重要 .

我无法理解为什么Symfony完全指向这个测试用例,因为我在所有测试中都用这种方式替换了很多服务 . 我没有在这个setUp方法之前的任何地方替换这个服务,所以很奇怪 .