CakePHP 3 mocking methods in integration tests
<p>I'm currently using integration test cases to test responses on certain endpoints but cannot work out how to use mock methods to stop the tests also doing things like sending emails.</p>

<p>My test method is similar to the following:</p>

<pre><code>public function testInviteUser() {
    $this-&gt;post('/invite-user', [
        'name' =&gt; 'Joe Bloggs',
        'email' =&gt; 'joe@bloggs.com'
    ]);

    $this-&gt;assertRedirect([
        'controller' =&gt; 'Users',
        'action' =&gt; 'index'
    ]);
}
</code></pre>

<p>The <code>UsersTable</code> class is using a <code>Mailer</code> that listens to the <code>afterSave</code> event and sends an email. Is it possible to use mock objects to solve this issue? I understand how I can use them when unit testing else where but can't see how the examples in the documentation fit in with integration tests.</p>