Testing | laravel-slack-alerts-rust | Spatie       

 SPATIE  

laravel-slack-alerts-rust
=========================

spatie.be/open-source

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

 Version   v1      

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

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

 Testing
=======

###  On this page 

1. [ Package tests ](#content-package-tests)

Use Laravel's native queue fake to test your code without sending messages to Slack. It round-trips jobs through serialization and supports counts, predicates and negative assertions:

```
use laravel::queue;
use spatie_slack_alerts::{SlackAlert, SendToSlackChannelJob};

#[laravel::test(app = create)]
async fn sends_an_alert(app: Application) {
    let queue = queue::fake();

    app.resolve::<SlackAlert>().await.message("New subscriber!").await.unwrap();

    queue.assert_pushed_times::<SendToSlackChannelJob>(1);
    queue.assert_pushed_where::<SendToSlackChannelJob>(|job| {
        job.text.as_deref().is_some_and(|text| text.contains("subscriber"))
            && job.queue() == "default"
    });
}
```

Other available assertions include `assert_nothing_pushed()`, `assert_not_pushed::<SendToSlackChannelJob>()`, and `queue.pushed::<SendToSlackChannelJob>()` to inspect all recorded alerts. Blocks are available as `job.blocks`, and optional properties are public fields. The queue fake also captures synchronous jobs; use `except::<SendToSlackChannelJob>()` or drop the queue fake when you want the job to execute.

To test actual delivery, fake Laravel's HTTP client and invoke a job directly or send synchronously:

```
use laravel::http::client;
use spatie_slack_alerts::SlackAlert;

let http = client::fake();
let alert = app.resolve::<SlackAlert>().await;

(*alert).clone().sync(true).message("Some message.").await?;

http.assert_sent_count(1);
http.assert_sent(|request| {
    request.url() == "https://example.com/webhook"
        && request.data()["text"] == "Some message."
});
```

Install fakes inside a Laravel test application context. If a test constructs its own application instead of using the test macro's `app` argument, use `app.scope(async || { /* test */ }).await`. Fakes are isolated per application; no real webhook credentials or network calls are needed.

Package tests
-----------------------------------------------------------------------------------------------

```
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
cargo publish --locked --dry-run
```

CI runs stable checks on Linux, macOS and Windows, Rust 1.99.0 checks on Linux, a security audit, and tests against the oldest supported Laravel Rust (0.1.0) and the newest available release. README and guide examples are compiled by rustdoc; self-contained delivery examples execute against Laravel HTTP fakes.

 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)
