Integration tests | laravel-permission-rust | Spatie       

 SPATIE  

laravel-permission-rust
=======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-permission-rust](https://spatie.be/docs/laravel-permission-rust/v1)  Integration tests

 Version   v1      

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

  Integration tests    
- [ Introduction ](https://spatie.be/docs/laravel-permission-rust/v1/introduction)
- [ Install and connect the application ](https://spatie.be/docs/laravel-permission-rust/v1/installation-laravel)
- [ Roles and permissions ](https://spatie.be/docs/laravel-permission-rust/v1/basic-usage)
- [ Authenticated routes and policies ](https://spatie.be/docs/laravel-permission-rust/v1/authorization)
- [ Querying users and bulk assignment ](https://spatie.be/docs/laravel-permission-rust/v1/querying-users)
- [ Console commands ](https://spatie.be/docs/laravel-permission-rust/v1/commands)
- [ Custom models and IDs ](https://spatie.be/docs/laravel-permission-rust/v1/models-and-ids)
- [ Cache and events ](https://spatie.be/docs/laravel-permission-rust/v1/cache-and-events)
- [ Integration tests ](https://spatie.be/docs/laravel-permission-rust/v1/testing)

 Integration tests
=================

Integration tests
===========================================================================================================

Run from the package root with Rust 1.99+, Cargo, a linker and the native dependencies needed to build SQLite. The lockfile is committed; CI must use `--locked`.

```
cargo fmt --all --check
cargo clippy --all-targets --all-features --locked -- -D warnings
cargo test --all-targets --all-features --locked
cargo test --doc --all-features --locked
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked
cargo audit --deny warnings
```

All integration tests use `#[laravel::test]` and the framework's test runtime. `tests/support/mod.rs` creates a fresh real framework application per test and a temporary file-backed SQLite database. `tests/migrations` registers the package migration plus a real authenticatable account table. The fixture executes the framework's `migrate` console command; it does not call a fake migration trait or hand-build substitute permission tables.

`tests/permissions.rs` checks inheritance, real inverse relations, duplicates, persistence after opening a second application, guard/team/morph isolation, atomic failed sync, outer rollback and nested savepoints, real cache invalidation, direct native ORM changes, backend errors, wildcards and cascading deletes. `tests/web.rs` submits real credentials to `Auth::attempt`, then carries the response's encrypted cookies into actual web requests. It checks guest rejection, invalid passwords, authorized and denied users, native policy methods and their `before` override, empty middleware, guard isolation, and grant/revoke changes within an existing session.

The same suite runs the native console parser/command runner, including idempotent creates, account lookup, invalid-input rollback, team arguments, help and cache reset. Query tests compose native builders with role/permission predicates, exclusions, filters, limits and eager loading. Bulk assignment tests cover multiple morph types and rollback when one subject is invalid.

`tests/custom_models.rs` repeats the integration for UUID and ULID application models: renamed tables and columns, custom primary-key names, extra fields, timestamps, scoped permission queries, native inverse relations, console assignment and password/session-authenticated HTTP. Both model sets use registered migrations against fresh file-backed SQLite databases.

`tests/features.rs` uses `#[laravel::test]`, native `refresh_database`, in-memory SQLite and `event::fake()`. PHP-derived cases cover unknown-role denials, direct-only checks, role checks, bulk permission sync, custom wildcards and deep matching boundaries, custom team-model queries, native account-deletion cleanup and rollback. Provider tests exercise environment defaults, application config/container overrides and named cache-store isolation. Custom-model tests also rename every pivot column and exercise provider-registered commands and deletion listeners.

The package does not write files or dispatch jobs, so storage and queue fakes are not needed. Assignment event tests use the framework fake; real listener and commit behavior remain covered by the file-backed integration suite. HTTP tests also verify default-hidden and opt-in error names.

The HTTP suite uses Laravel's in-process request testing API. It executes web middleware, routing, database-backed user loading, sessions and error handling without opening a TCP socket. It does not use `acting_as` or inject a principal into a substitute request type.

CI runs formatting, warning-free Clippy, tests and rustdoc on stable Linux/macOS/Windows, plus Rust 1.99 and dependency audit jobs on Linux. Other database backends are not tested.

- Missing public documentation and missing `Debug` implementations are warnings, denied in CI.
- Selected Clippy pedantic checks cover ownership, reference-counted clones and statement style. Scalar-key builders accept values intentionally so calls such as `.team(17)` stay concise.
- `cargo test --doc` discovers every Markdown guide recursively. Database examples use a temporary SQLite database and execute the package migrations and operations they demonstrate.
- `cargo package --list --locked` lists the included sources, guides and migration fixtures. Full `cargo package` verification is unavailable while package-tools is a Git-only dependency. Keep `publish = false`; use the Git installation shown in the README.

 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)
