Writing your own test doubles
– Edit
Adam Wathan posted another excellent article on testing on his blog. This time he talks about creating test doubles. Adam demonstrates that creating your own fake can result in a much more readable test than using mocks or spies.
You'll learn to create an InMemoryMailer like this:
public function test_new_users_are_sent_a_welcome_email()
{
$mailer = new InMemoryMailer;
Mail::swap($mailer);
$this->post('register', [
'name' => 'John Doe',
'email' => 'john@example.com',
'password' => 'secret',
]);
$this->assertTrue($mailer->hasMessageFor('john@example.com'));
$this->assertTrue($mailer->hasMessageWithSubject('Welcome to my app!'));
}
That seems like a pretty readable test to me. Read (or view) the whole tutorial here: http://adamwathan.me/2016/01/25/writing-your-own-test-doubles/