Testing | laravel-newsletter-go | Spatie       

 SPATIE  

  Laravel Newsletter Go 
========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-newsletter-go](https://spatie.be/docs/laravel-newsletter-go/v1)  Testing

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-newsletter-go/v1) 

  Testing    
- [ Introduction ](https://spatie.be/docs/laravel-newsletter-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-newsletter-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-newsletter-go/v1/usage)
- [ Custom drivers ](https://spatie.be/docs/laravel-newsletter-go/v1/custom-drivers)
- [ Testing ](https://spatie.be/docs/laravel-newsletter-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-newsletter-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-newsletter-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-newsletter-go/v1/support-us)

 Testing
=======

Run the tests with:

```
go test -race ./...
```

The package tests fake HTTP with Laravel's `httpclienttest` and prevent stray requests. They cover all providers, named lists, payload options, missing members, failure handling, cancellation, concurrent use and custom drivers through a host route.

In a consuming application, install the package and fake its provider:

```
func TestSubscribes(t *testing.T) {
    client := laraveltest.New(t, laravel.Options{
        Packages: []laravel.Package{newsletter.New()},
    }, laraveltest.Env(map[string]string{
        "NEWSLETTER_DRIVER": "mailchimp",
        "NEWSLETTER_API_KEY": "test-us7",
        "NEWSLETTER_LIST_ID": "list-id",
    }))

    api := httpclienttest.New(client).
        Respond("us7.api.mailchimp.com/*", httpclienttest.JSON(map[string]any{
            "email_address": "rincewind@discworld.com",
            "status": "subscribed",
        })).
        PreventStrayRequests()

    member, err := newsletter.Subscribe(client.Context(), "rincewind@discworld.com")
    if err != nil || member == nil || !member.Subscribed {
        t.Fatalf("member=%v error=%v", member, err)
    }
    api.AssertSentCount(1)
}
```

Import `testing`, `github.com/spatie/laravel-newsletter-go`, `go.laravel.com`, `go.laravel.com/laraveltest` and `go.laravel.com/httpclienttest`.

Run `go vet ./...` for static checks and `go mod tidy -diff` to check dependency metadata. Format code with `gofmt -w .`.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
