getMockForAbstractClass(LoggerInterface::class); /** @var SimpleMessage|MockObject $message */ $message = $this->createMock(SimpleMessage::class); $message->expects($this->once()) ->method('getSubject') ->willReturn('Some subject'); $message->expects($this->once()) ->method('toString') ->willReturn("Head: er\n\nMessage body"); $logger->expects($this->once()) ->method('debug') ->willReturnCallback(function ($message, $context = []) { foreach (array_keys($context) as $key) { $this->assertStringContainsString(sprintf('{%s}', $key), $message); } $this->assertEquals('Some subject', $context['title']); $this->assertEquals('foo@bar.batz,Lorem Ipsum ', $context['recipients']); $this->assertStringContainsString('Head: er', $context['content']); $this->assertStringContainsString('Message body', $context['content']); }); /** @var LogTransport|MockObject $transport */ $transport = $this->getMockBuilder(LogTransport::class) ->setConstructorArgs(['logger' => $logger]) ->onlyMethods(['allRecipients']) ->getMock(); $transport->expects($this->exactly(2)) ->method('allRecipients') ->with($message) ->willReturn(['foo@bar.batz' => null, 'lor@em.ips' => 'Lorem Ipsum']); $return = $transport->send($message); $this->assertEquals(2, $return); } }