spatie / laravel-newsletter

Manage Mailcoach and MailChimp newsletters in Laravel
https://freek.dev/440-easily-integrate-mailchimp-in-laravel-5
MIT License
1.61k stars 235 forks source link

No obvious way to fake / test Newsletter #271

Closed danielsetreus closed 2 years ago

danielsetreus commented 2 years ago

Let's say I have a service that among other things does

Newsletter::addTags(...)

How would I go about writing tests for that service? I can't find any obvious way of faking the facade, and it seems there are no methods for asserting the actions it does towards Mailchimp.

spatie-bot commented 2 years ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

clementmas commented 2 years ago

I'm also looking for a way to test that a user was subscribed to a list. Is that possible? I don't see any Newsletter::fake() method available.

At the moment I have to ignore that call by adding this to phpunit.xml:

<env name="MAILCHIMP_DRIVER" value="null"/>
javierpomachagua commented 1 year ago

@clementmas You can use the method 'shouldReceive' from the Facade.

Newsletter::shouldReceive('isSubscribed')
        ->with($subscriber->email)
        ->once()
        ->andReturn(false);

    Newsletter::shouldReceive('subscribe')
        ->with($subscriber->email)
        ->once()
        ->andReturnNull();