title: PhpUnit Test - Asserting variables and twig template content
body: <p>I've defined a simple email controller based on this tutorial:</p>
  
  <p><a href="https://symfony.com/doc/3.4/email.html" rel="nofollow noreferrer">https://symfony.com/doc/3.4/email.html</a></p>
  
  <p>So the php file code is:</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Controller;
  
  use Symfony\Component\HttpKernel\Tests\Controller;
  
  
  class SendEmailController extends Controller
  {
      public function indexAction($originlEmail, $destinationEmail1, $destinationEmail2, $name, \Swift_Mailer $mailer)
      {
          $message = (new \Swift_Message('Email Title'))
              -&gt;setFrom($originlEmail)
              -&gt;setTo($destinationEmail1, $destinationEmail2)
              -&gt;setBody(
                  $this-&gt;renderView(
                      'emails/send-email.html.twig',
                      array('name' =&gt; $name)
                  ),
                  'text/html'
              );
  
          $mailer-&gt;send($message);
  
          return $this-&gt;render(...);
      }
  }
  </code></pre>
  
  <p>And the .twig template code is:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h3&gt;This is an email!&lt;/h3&gt;
      &lt;p&gt;Hi {{ name }}, this is an email! &lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now, following this tutorial <a href="https://symfony.com/doc/3.4/email/testing.html" rel="nofollow noreferrer">https://symfony.com/doc/3.4/email/testing.html</a> I've created a PhpUnit testing class:</p>
  
  <pre><code>&lt;?php
  
  namespace tests\AppBundle\Controller;
  
  use AppBundle\Controller\SendMyEmailController;
  
  class SendCustomerEmailControllerTest extends PHPUnit_Framework_TestCase
  {
      public function testMailIsSentAndContentIsCorrect()
      {
          $client = static:: createClient();
  
          $client-&gt;enableProfiler();
  
          $crawler = $client-&gt;request('POST', 'path/to/above/action');
  
          $mailCollector = $client-&gt;getProfile()-&gt;getCollector('swiftmailer');
  
          $this-&gt;assertSame(1, $mailCollector-&gt;getMessageCount());
  
          $collectedMessages = $mailCollector-&gt;getMessages();
          $message = $collectedMessages[0];
  
          $this-&gt;assertInstanceOf('Swift_Message', $message);
          $this-&gt;assertSame('My Email Title', $message-&gt;getSubject());
          $this-&gt;assertSame($originEmail, key($message-&gt;getFrom()));
          $this-&gt;assertSame($destinationEmail1, $destinationEmail2, key($message-&gt;getTo()));
          ##Asserting template content???
          $this-&gt;assertSame(?????, $message-&gt;getBody()
          );
      }
  }
  </code></pre>
  
  <p>Then, the problems I have are:</p>
  
  <ol>
  <li><p>Where and how should I define (in the test) <strong>variables</strong> like $originEmail, given the fact that in the "assertSame..." line, I get the error "Undefined variable $originEmail".</p></li>
  <li><p>Is correct the syntax (considering they are <strong>more than one variable</strong>) of the line  <code>$this-&gt;assertSame($destinationEmail1, $destinationEmail2, key($message-&gt;getTo()));</code> ?</p></li>
  <li><p>How can I <strong>assert the body</strong> content, if instead of a defined text in the .php controller, it is showed in the <strong>.twig template</strong> (in addition, by using a variable like {{ name }}?</p></li>
  </ol>