Testing | laravel-newsletter-rust | Spatie       

 SPATIE  

  Laravel Newsletter 
=====================

spatie.be/open-source

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

 Version   v1      

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

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

 Testing
=======

Every built-in driver uses Laravel's HTTP client, so tests can fake responses without contacting an email service. Keep the fake handle alive and reject stray requests:

```
use laravel::{http::client, testing::prelude::*};
use serde_json::json;
use spatie_newsletter::Newsletter;

#[laravel::test]
async fn subscribes_a_reader(app: Application) {
    let http = client::fake()
        .with("your-mailcoach.app/api/email-lists/*/subscribers", json!({
            "data": {
                "uuid": "subscriber-uuid",
                "email_list_uuid": "list-uuid",
                "email": "reader@example.com",
            }
        }))
        .prevent_stray_requests();

    let newsletter = app.resolve::<Newsletter>().await;
    newsletter.subscribe("reader@example.com", json!({})).await.unwrap();

    http.assert_sent(|request| request.data()["email"] == "reader@example.com");
}
```

Register the provider and use test credentials and list IDs in your application's testing configuration. Fakes are isolated per application and also intercept the SDK's Laravel transport. No real API keys are needed.

To disable subscription operations altogether, replace the container service with `Newsletter::new(NullDriver::default())` through `with_services` or `app.swap`.

Run the package checks:

```
cargo fmt --all -- --check
cargo clippy --locked --all-targets --all-features -- -D warnings
cargo test --locked --all-targets --all-features
cargo test --locked --doc --all-features
cargo doc --locked --no-deps --all-features
cargo package --locked --features laravel/database-sqlite
cargo audit
```

Set `RUSTFLAGS=-D warnings` and `RUSTDOCFLAGS=-D warnings` in CI. The SQLite feature is only needed to verify Laravel in the package archive; the library performs no database queries. Development tests enable SQLite without forcing it on consumers.

CI covers stable Rust on Linux, macOS, and Windows, Rust 1.99.0, and Laravel Rust 0.1.0 and the newest release. The suite fakes every driver, successful and failed mutations, missing members, subscription states, option precedence, named lists, custom drivers, provider overrides, and URL encoding. Service credentials are never used.

README and guide Rust examples are compiled by rustdoc. Self-contained configuration examples execute. Examples requiring a configured application or remote service use `no_run`; their HTTP behavior is covered by the integration suite.

 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)
