mardi 26 janvier 2016

CakePHP 3 mocking methods in integration tests

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.

My test method is similar to the following:

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

    $this->assertRedirect([
        'controller' => 'Users',
        'action' => 'index'
    ]);
}

The UsersTable class is using a Mailer that listens to the afterSave 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.

Aucun commentaire:

Enregistrer un commentaire