Testing | laravel-mailcoach-sdk-go | Spatie       

 SPATIE  

laravel-mailcoach-sdk-go
========================

spatie.be/open-source

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

 Version   v1      

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

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

 Testing
=======

###  On this page 

1. [ Plain Go ](#content-plain-go)
2. [ Laravel Go ](#content-laravel-go)

Run `go test -race ./...` to execute the tests and examples. Run `go vet ./...` for static checks and `go mod tidy -diff` to check dependency metadata. Format code with `gofmt -w .`.

The suite uses synthetic HTTP responses, never a production Mailcoach account. It covers endpoint methods and payloads, pagination, error responses, cancellation, timeouts, unsafe URLs, custom model attributes and subscription state transitions.

Plain Go
--------------------------------------------------------------------------------

Use `httptest.NewServer` for integration tests or inject an `http.Client` with a custom `http.RoundTripper` using `mailcoach.WithHTTPClient`. Include a positive timeout on a supplied client, or pass `WithTimeout` after it. No global fake is installed, so separate clients remain independent.

The executable example beside the package runs a complete subscriber creation against a local HTTP server.

Laravel Go
--------------------------------------------------------------------------------------

Create an isolated application with `laraveltest.New`, registering `mailcoachlaravel.New()` in its `Packages`. Keep Laravel's test defaults and use `laraveltest.Env` to add SDK credentials. Do not replace the entire testing environment.

```
fake := httpclienttest.New(app).PreventStrayRequests().Respond(
    "mailcoach.example/api/campaigns",
    httpclienttest.JSON(map[string]any{
        "data": map[string]any{"uuid": "campaign-uuid", "name": "My campaign"},
    }),
)

app.Get("/campaign").AssertOK().AssertSee("My campaign")
fake.AssertSentCount(1)
```

The host route retrieves `mailcoachlaravel.From(r)` and calls the SDK with `r` as context. A plain `context.Background()` does not carry the Laravel application. Install one HTTP fake per test application before making requests. Tests verify full client replacement through a routed request and reuse the same package registration across isolated apps.

 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)
