I have the following PHPUnit testcase:
$mailer = $this->getMockBuilder(MailerInterface::class)->getMock();
$simpleMailer = new SimpleMailer($mailer);
$message = (new Message())
->setTo($user)
->setFrom($from)
->setSubject($subject)
->setTemplate(SimpleMailer::TEMPLATE)
->setContext(['message' => $body]);
if ($bcc) { $message->addBcc($bcc); }
$mailer
->expects($this->once())
->method('send')
->with($this->equalTo($message));
$simpleMailer->sendMessage($user, $subject, $body, $from, $bcc);
This was working fine until the Message class was changed. The Message class now sets a unique ID on construction, meaning that equalTo
now returns false with the following difference:
MailerBundle\Document\Message Object (
- 'id' => '5a372f3c-a8a9-4e1e-913f-d756244c8e52'
+ 'id' => '11176427-7d74-4a3c-8708-0026ae666f8b'
'type' => null
'user' => Tests\TestUser Object (...)
'toName' => ''
'toAddress' => null
'domain' => null
'fromName' => null
'fromAddress' => '[email protected]'
'bccAddresses' => Array (...)
'subject' => 'subject'
'textBody' => null
'htmlBody' => null
'template' => 'MailerBundle:MailTemplates:...l.twig'
'context' => Array (...)
)
Is there any way that I can exclude certain properties from the equality check?
id
for the test!? – Loinclothnew class extends Message { public function _construct(){ /*override here*/}}
, no need to override the original. And btw you canmock
the getter, maybe that helps – LoinclothMessage
I construct in the tests. But not the message constructed insimpleMailer->sendMessage
– Vetchling