66use Laminas \Diagnostics \Result \Collection ;
77use Laminas \Diagnostics \Result \Failure ;
88use Liip \MonitorBundle \Helper \SymfonyMailerReporter ;
9+ use PHPUnit \Framework \MockObject \MockObject ;
910use PHPUnit \Framework \TestCase ;
10- use Prophecy \Argument ;
1111use Symfony \Component \Mailer \MailerInterface ;
1212use Symfony \Component \Mime \Address ;
1313use Symfony \Component \Mime \Email ;
1414
1515class SymfonyMailerReporterTest extends TestCase
1616{
1717 /**
18- * @var \Prophecy\Prophecy\ObjectProphecy |MailerInterface
18+ * @var MockObject |MailerInterface
1919 */
2020 private $ mailer ;
2121
@@ -25,31 +25,33 @@ protected function setUp(): void
2525 $ this ->markTestSkipped ('Symfony Mailer not available. ' );
2626 }
2727
28- $ this ->mailer = $ this ->prophesize (MailerInterface::class);
28+ $ this ->mailer = $ this ->createMock (MailerInterface::class);
2929 }
3030
3131 /**
3232 * @dataProvider getTestData
3333 */
3434 public function testSendMail (array $ recipients , string $ sender , string $ subject ): void
3535 {
36- $ reporter = new SymfonyMailerReporter ($ this ->mailer -> reveal () , $ recipients , $ sender , $ subject );
36+ $ reporter = new SymfonyMailerReporter ($ this ->mailer , $ recipients , $ sender , $ subject );
3737
3838 $ check = $ this ->prophesize (CheckInterface::class);
3939 $ check ->getLabel ()->willReturn ('Some Label ' );
4040
4141 $ checks = new Collection ();
4242 $ checks [$ check ->reveal ()] = new Failure ('Something goes wrong ' );
4343
44- $ this ->mailer ->send (Argument::that (function (Email $ message ) use ($ recipients , $ sender , $ subject ): bool {
45- $ this ->assertEquals (Address::createArray ($ recipients ), $ message ->getTo (), 'Check if Recipient is sent correctly. ' );
46- $ this ->assertEquals ([Address::create ($ sender )], $ message ->getFrom (), 'Check that the from header is set correctly. ' );
47- $ this ->assertSame ($ subject , $ message ->getSubject (), 'Check that the subject has been set. ' );
44+ $ this ->mailer
45+ ->expects (self ::once ())
46+ ->method ('send ' )
47+ ->with (self ::callback (function (?Email $ message ) use ($ recipients , $ sender , $ subject ): bool {
48+ self ::assertEquals (Address::createArray ($ recipients ), $ message ->getTo (), 'Check if Recipient is sent correctly. ' );
49+ self ::assertEquals ([Address::create ($ sender )], $ message ->getFrom (), 'Check that the from header is set correctly. ' );
50+ self ::assertSame ($ subject , $ message ->getSubject (), 'Check that the subject has been set. ' );
51+ self ::assertSame ('[Some Label] Something goes wrong ' , $ message ->getTextBody (), 'Check if the text body has been set. ' );
4852
49- $ this ->assertSame ('[Some Label] Something goes wrong ' , $ message ->getTextBody (), 'Check if the text body has been set. ' );
50-
51- return true ;
52- }))->shouldBeCalled ();
53+ return true ;
54+ }));
5355
5456 $ reporter ->onFinish ($ checks );
5557 }
0 commit comments