Last active
February 28, 2021 15:02
-
-
Save rugbymauri/b838b4dd08df45f8dca64c31e23605e2 to your computer and use it in GitHub Desktop.
Symfony send Mail test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Socius\Tests\Todo; | |
use Socius\Notifier\TodoNotifier; | |
use Socius\Repository\Todo\CardRepository; | |
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\Mailer\DataCollector\MessageDataCollector; | |
class TodoTest extends KernelTestCase | |
{ | |
protected function setUp():void | |
{ | |
self::bootKernel(); | |
// returns the real and unchanged service container | |
$container = self::$kernel->getContainer(); | |
// gets the special container that allows fetching private services | |
$container = self::$container; | |
} | |
/** | |
* @dataProvider getMailData | |
*/ | |
public function testMail($now, $expected) | |
{ | |
$profiler = self::$container->get('profiler'); | |
$todoNotifier = $this->self::$container->get(TodoNotifier::class); | |
$todoNotifier->notitfy($now); | |
/** @var MessageDataCollector $mailerDataCollector */ | |
$mailerDataCollector = $profiler->get('mailer'); | |
$mailerDataCollector->collect(new Request(), new Response()); | |
$messageEvents = $mailerDataCollector->getEvents()->getEvents('[main]'); | |
$this->assertCount(count($expected), $messageEvents); | |
foreach ($expected as $index => $item) { | |
$this->assertEquals($item, $messageEvents[$index]->getMessage()->getHtmlTemplate() ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment