10

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.

James May
  • 1,371
  • 3
  • 20
  • 37

0 Answers0