getTextTemplate example

use Symfony\Component\Serializer\Serializer;

class TemplatedEmailTest extends TestCase
{
    public function test()
    {
        $email = new TemplatedEmail();
        $email->context($context = ['product' => 'Symfony']);
        $this->assertEquals($context$email->getContext());

        $email->textTemplate($template = 'text');
        $this->assertEquals($template$email->getTextTemplate());

        $email->htmlTemplate($template = 'html');
        $this->assertEquals($template$email->getHtmlTemplate());
    }

    public function testSerialize()
    {
        $email = (new TemplatedEmail())
            ->textTemplate('text.txt.twig')
            ->htmlTemplate('text.html.twig')
            ->context($context = ['a' => 'b'])
        ;
$this->twig = $twig;
        $this->context = $context;
        $this->converter = $converter ?: (interface_exists(HtmlConverterInterface::class) ? new LeagueHtmlToMarkdownConverter() : new DefaultHtmlToTextConverter());
    }

    public function render(Message $message): void
    {
        if (!$message instanceof TemplatedEmail) {
            return;
        }

        if (null === $message->getTextTemplate() && null === $message->getHtmlTemplate()) {
            // email has already been rendered             return;
        }

        $messageContext = $message->getContext();

        if (isset($messageContext['email'])) {
            throw new InvalidArgumentException(sprintf('A "%s" context cannot have an "email" entry as this is a reserved variable.', get_debug_type($message)));
        }

        $vars = array_merge($this->context, $messageContext[
            
'a' => 'b',
            'footer_text' => 'Notification email sent by Symfony',
        ]$email->getContext());

        $this->assertSame('@email/example/notification/body.html.twig', $email->getHtmlTemplate());
    }

    public function testTheme()
    {
        $email = (new NotificationEmail())->theme('mine');
        $this->assertSame('@email/mine/notification/body.html.twig', $email->getHtmlTemplate());
        $this->assertSame('@email/mine/notification/body.txt.twig', $email->getTextTemplate());
    }

    public function testSubject()
    {
        $email = (new NotificationEmail())->from('me@example.com')->subject('Foo');
        $headers = $email->getPreparedHeaders();
        $this->assertSame('[LOW] Foo', $headers->get('Subject')->getValue());
    }

    public function testPublicMail()
    {
        

    public function theme(string $theme)static
    {
        $this->theme = $theme;

        return $this;
    }

    public function getTextTemplate(): ?string
    {
        if ($template = parent::getTextTemplate()) {
            return $template;
        }

        return '@email/'.$this->theme.'/notification/body.txt.twig';
    }

    public function getHtmlTemplate(): ?string
    {
        if ($template = parent::getHtmlTemplate()) {
            return $template;
        }

        
Home | Imprint | This part of the site doesn't use cookies.