# Testing (laravel-rust-captcha)

> Each test app has its own captcha service and store, so these helpers are safe in parallel tests.

- Package: laravel-rust-captcha (Laravel for Rust, alpha), crates: `laravel-rust-captcha`
- Maintenance: active; Latest release: 0.1.0 (2026-12-04); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-captcha), [crates.io](https://crates.io/crates/laravel-rust-captcha/0.1.0), [docs.rs](https://docs.rs/laravel-rust-captcha/0.1.0), [Changelog](https://oss.bowerbird.si/captcha/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-captcha/blob/57c677c77d6c928790e0acaf24e0b3f0ff06f29c/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-captcha/blob/57c677c77d6c928790e0acaf24e0b3f0ff06f29c/SECURITY.md)
- Based on: [mews/captcha](https://github.com/mewebstudio/captcha): The captcha package this ports: profiles, config keys, routes and validation, following version 3.5.1. Its backgrounds and fonts ship with their own licences.
- PHP parity: full (54 covered, 33 diverged, 0 planned of 87 abilities; 44 fixtures; follows mews/captcha 3.5.1; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/captcha/docs/testing/
- Source: https://github.com/bowerbird-si/laravel-rust-captcha/blob/57c677c77d6c928790e0acaf24e0b3f0ff06f29c/docs/testing.md

Each test app has its own captcha service and store, so these helpers are safe in parallel tests.

## Through the real image route

```rust
use laravel::testing::prelude::*;
use laravel_rust_captcha::testing;
use serde_json::json;

#[laravel::test(app = create)]
async fn the_contact_form_accepts_the_captcha(app: Application) {
    app.scope(async || testing::fix_answers("abcde").await.unwrap()).await;

    let image = app.get("/captcha/contact").await;
    image.assert_ok();

    app.post("/contact")
        .with_cookies_from(&image)
        .form(json!({ "name": "Ada", "captcha": "ABCDE" }))
        .await
        .assert_redirect_to("/thanks");
}
```

`fix_answers` makes every image the app issues use that answer, until `clear_fixed_answer`.

## Seeding a challenge

`testing::seed(&session, "contact", "abcde")` creates a session challenge with a known answer without
drawing it. `testing::seed_keyed("math", "12")` returns the key of a keyed challenge. PHP tests did this
by writing the session and cache entries by hand.

## Turning the captcha off

Set `CAPTCHA_DISABLE=true` (for example with `.with_envs([("CAPTCHA_DISABLE", "true")])`). The rules
pass and the routes are gone, as in PHP.
