title: How to fix deprecation notices in Symfony 5 when using PHPUnit with Phake?
body: <p>I develop my app with Symfony 5 and test it with PHPUnit, along with Phake to mock my classes. I've just updated Symfony from 5.2 to 5.3, including symfony/phpunit-bridge as well as the recipes. In <code>symfony.lock</code>, phpunit jumped from version 4.7 to 9.3 (in <code>composer.json</code> version is ^9.5).</p>
  <p>Now, I have the following messages when I run my tests (I didn't have them before):</p>
  <pre class="lang-sh prettyprint-override"><code>Remaining indirect deprecation notices (3)
  
    1x: The &quot;Symfony\Bridge\Twig\Mime\TemplatedEmail::__serialize()&quot; method is considered internal. It may change without further notice. You should not extend it from &quot;TemplatedEmail_PHAKEcbeb592e8143b41&quot;.
      1x in ContactMailerTest::testSendEmail from App\Tests\Mailer
  
    1x: The &quot;Symfony\Bridge\Twig\Mime\TemplatedEmail::__unserialize()&quot; method is considered internal. It may change without further notice. You should not extend it from &quot;TemplatedEmail_PHAKEcbeb592e8143b41&quot;.
      1x in ContactMailerTest::testSendEmail from App\Tests\Mailer
  
    1x: Class &quot;TranslatorInterface_PHAKEe9b1bfdc40995c1&quot; should implement method &quot;Symfony\Contracts\Translation\TranslatorInterface::getLocale()&quot;: Returns the default locale.
      1x in EmailFactoryTest::testCreateEmail from App\Tests\Mailer
  </code></pre>
  <p>It seems to me that the deprecation comes from the fact that Phake is mocking the classes and thus extending from the classes without implementing a method when it should, and implementing them when it shouldn't.</p>
  <p>So I'm guessing that it's not actually my code that is deprecated. Am I right?</p>
  <p>If so, how could I fix these deprecations without disabling them?
  Is that a symfony/phpunit-bridge problem, a PHPUnit problem, or a Phake problem?</p>
  <hr />
  <p><strong>Edit:</strong> Since I got a -1 without a comment to tell me what is wrong with my post, I'll try to add some precisions.</p>
  <p>I have made some research prior to posting this question: I haven't found anything related to this type of deprecation notices and Phake.</p>
  <p>I <em>know</em> that my code doesn't contain deprecations because I don't have any deprecation notices other than these.</p>
  <p>Here's my code from ContactMailerTest if that can help:</p>
  <pre class="lang-php prettyprint-override"><code>final class ContactMailerTest extends TestCase
  {
      private MailerInterface $mailer;
      private EmailFactory $factory;
      private LoggerInterface $logger;
      private ContactMailer $contactMailer;
      private Contact $contact;
      private TemplatedEmail $email;
  
      protected function setUp(): void
      {
          $this-&gt;mailer = Phake::mock(MailerInterface::class);
          $this-&gt;factory = Phake::mock(EmailFactory::class);
          $this-&gt;logger = Phake::mock(LoggerInterface::class);
          $this-&gt;contact = Phake::mock(Contact::class);
          $this-&gt;contact-&gt;name = 'Jane';
          $this-&gt;contact-&gt;emailAddress = 'jane@example.com';
          $this-&gt;contact-&gt;message = 'Cat ipsum dolor sit amet !';
          $this-&gt;email = Phake::mock(TemplatedEmail::class);
  
          Phake::when($this-&gt;factory)-&gt;createEmail($this-&gt;contact-&gt;name, $this-&gt;contact-&gt;emailAddress, $this-&gt;contact-&gt;message)-&gt;thenReturn($this-&gt;email);
  
          $this-&gt;contactMailer = new ContactMailer($this-&gt;mailer, $this-&gt;factory, $this-&gt;logger);
      }
  
      public function testSendEmail(): void
      {
          $this-&gt;contactMailer-&gt;sendEmail($this-&gt;contact);
  
          Phake::verify($this-&gt;factory)-&gt;createEmail('Jane', 'jane@example.com', 'Cat ipsum dolor sit amet !');
          Phake::verify($this-&gt;mailer)-&gt;send($this-&gt;email);
          $this-&gt;assertTrue($this-&gt;contactMailer-&gt;hadSuccess);
      }
  }
  </code></pre>
  <p>and from EmailFactoryTest:</p>
  <pre class="lang-php prettyprint-override"><code>final class EmailFactoryTest extends TestCase
  {
      public function testCreateEmail(): void
      {
          $translator = Phake::mock(TranslatorInterface::class);
          $name = 'Jane';
          $emailAddress = 'jane@example.com';
          $message = 'Cat ipsum dolor sit amet !';
  
          Phake::when($translator)-&gt;trans('email.contact.address')-&gt;thenReturn('contact@example.com');
          Phake::when($translator)-&gt;trans('email.contact.name')-&gt;thenReturn('Contact');
          Phake::when($translator)-&gt;trans('email.chloe.address')-&gt;thenReturn('chloe@example.com');
          Phake::when($translator)-&gt;trans('email.chloe.name')-&gt;thenReturn('Chloé');
          Phake::when($translator)-&gt;trans('email.contact.subject', ['name' =&gt; $name])-&gt;thenReturn('Message de la part de '.$name);
  
          $factory = new EmailFactory($translator);
          $email = $factory-&gt;createEmail($name, $emailAddress, $message);
  
          $from = $email-&gt;getFrom()[0];
          $this-&gt;assertEquals('contact@example.com', $from-&gt;getAddress());
          $this-&gt;assertEquals('Contact', $from-&gt;getName());
  
          $to = $email-&gt;getTo()[0];
          $this-&gt;assertEquals('chloe@example.com', $to-&gt;getAddress());
          $this-&gt;assertEquals('Chloé', $to-&gt;getName());
  
          $replyTo = $email-&gt;getReplyTo()[0];
          $this-&gt;assertEquals('jane@example.com', $replyTo-&gt;getAddress());
          $this-&gt;assertEquals('Jane', $replyTo-&gt;getName());
  
          $this-&gt;assertEquals('Message de la part de Jane', $email-&gt;getSubject());
          $this-&gt;assertEquals(['message' =&gt; 'Cat ipsum dolor sit amet !'], $email-&gt;getContext());
          $this-&gt;assertNotNull($email-&gt;getHtmlTemplate());
      }
  }
  </code></pre>
  <hr />
  <p><strong>Edit 2:</strong> I have symfony/phpunit-bridge package installed.</p>
  <hr />
  <p><strong>Edit 3:</strong> I've posted an issue on phake/phake repository right there: <a href="https://github.com/phake/phake/issues/300" rel="nofollow noreferrer">https://github.com/phake/phake/issues/300</a></p>