title: Laravel 5.4 Mail test
body: <p>Sounds simple enough but I cannot work out how to pass data to the below mailable for a test. It works fine for normal use.</p>
  
  <p><strong>Working, through controller</strong></p>
  
  <pre><code>Mail::to($user)-&gt;send(new C2cMail($this-&gt;commitment-&gt;data, \App\EModule::findOrFail($this-&gt;commitment-&gt;module_id), $user));
  </code></pre>
  
  <p><strong>Mailable</strong></p>
  
  <pre><code>    public function __construct($commitment, Module $module, User $user)
      {
          $this-&gt;commitment = unserialize($commitment);
          $this-&gt;module = $module;
          $this-&gt;user = $user;
          $this-&gt;title = $this-&gt;module-&gt;title;
      }
  
      /**
       * Build the message.
       *
       * @return $this
       */
      public function build()
      {
          try {
              if(empty(env('MAIL_FROM')) || !env('MAIL_FROM') || env('MAIL_FROM') == null){
                  throw new \Exception("You must set your MAIL_FROM environment variable", 406);
              }
              $this-&gt;from(env('MAIL_FROM'))-&gt;subject('First email test')-&gt;view('mail.c2c-1');
          } catch (\Exception $e) {
              \Log::error($e-&gt;getMessage());
          }
      }
  </code></pre>
  
  <p>So this all works fine but I cannot get a unit test to pass data to the mailable constructor.</p>
  
  <p><strong>Test case</strong></p>
  
  <pre><code>public function testC2cEmailSend()
      {
          Mail::fake();
  
          // Grab any old C2C entry
          $c2c = \App\Commitment::with(['module', 'user'])-&gt;first();
  
          $data = $c2c-&gt;data;
          $user = $c2c-&gt;user;
          $module = $c2c-&gt;module;
          $mailable_data = ['data' =&gt; $data, 'user' =&gt; $user, 'module' =&gt; $module];
  
          Mail::assertSent(C2cFirst::class, function($mail) use ($mailable_data) {
              return $mail-&gt;hasTo($mailable_data['user']-&gt;email);
          });
      }
  </code></pre>