Laravel Mailer - PHPUnit Testing - Mocking not working
<p>I am trying to unit test some events that fire emails. In particular, I want to test the emails are being sent.</p>

<p>The error is that getTransport() doesn't exist on the mocked object.
I added shouldReceive('getTransport') but then I'd have to mock what it returns too and then the function that is called on the mock object that is returned... etc etc.</p>

<p>My code in my Event listener:</p>

<pre><code>    $data = compact('pusher', 'product', 'time', 'contact');
    Mail::send('emails.sms.oos', $data, function($message) {
        $message-&gt;to('ben@me.com')-&gt;subject('');
        $message-&gt;from('me@newaverfid.com');
    });
</code></pre>

<p>My Test:</p>

<pre><code>    // Set the expected calls
    $mock-&gt;shouldReceive('send')
        -&gt;once()
        -&gt;with(
            'emails.sms.oos',
            m::on(function ($data) {
                $this-&gt;assertArrayHasKey('pusher', $data);
                return true;
            }),
            m::on( function(\Closure $closure) use ($location, $client, $contact, $reader, $pusher){
                $message = m::mock('Illuminate\Mailer\Message');
                $message-&gt;shouldReceive('to')-&gt;once()-&gt;with($contact-&gt;cellEmail())
                    -&gt;andReturn($message);
                $message-&gt;shouldReceive('subject')-&gt;once()-&gt;with('');
                $message-&gt;shouldReceive('from')-&gt;once()-&gt;with('me@newaverfid.com');
                $closure($message);
                return true;
            })
        );
</code></pre>

<p>And... my error:</p>

<pre><code>1) InventoryEventsTest::it_only_emails_contacts_for_the_specific_location
BadMethodCallException: Method Mockery_1_Swift_Mailer::getTransport() does not exist on this mock object

C:\xampp\htdocs\dev\newdash\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php:315
C:\xampp\htdocs\dev\newdash\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php:159
C:\xampp\htdocs\dev\newdash\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:222
C:\xampp\htdocs\dev\newdash\app\Listeners\SMSInventoryOutOfStockNotification.php:47
C:\xampp\htdocs\dev\newdash\app\Listeners\SMSInventoryOutOfStockNotification.php:47
C:\xampp\htdocs\dev\newdash\tests\Integrated\InventoryEventsTest.php:157
C:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
C:\xampp\php\pear\PHPUnit\TextUI\Command.php:129
</code></pre>