How to use Mockery for a class used in a controller?

Posted 5 months ago by shadrix

Let's say my controller looks like that.

public function store()

And Newsletter is a Class to use MailChimps Api easier.

Now how do I write a test for it?

I tried this, but it does not work. (I'm new to Mockery and it sends the data to mailchimp).

use Spatie\Newsletter\Newsletter;
class NewsletterTest extends TestCase {

    use RefreshDatabase;

    public function setUp()


    public function tearDown() {

    /** @test */
    public function a_guest_can_subscribe_to_newsletter() 
        $this->json('post', route(''), ['email' => '[email protected]'])

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.