Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Eloquent Scope Assertion Laravel Package

tkaratug/eloquent-scope-assertion

A lightweight Laravel testing helper for asserting that Eloquent model scopes apply the expected query constraints. Write expressive, readable tests for your local scopes without brittle SQL comparisons, and keep your query logic verified and maintainable.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy for engineering enablement. This is not a customer-facing capability — it's a dev-dependency that changes how cheaply you can prove that business rules encoded in Eloquent scopes still work. The decision is "adopt a ~free convenience layer" versus "write 20–50 lines of in-house assertion helper," not "buy a platform."
  • Protecting product rules that live in query scopes. Scopes are where teams quietly encode customer-visible behavior: tenant isolation, soft-delete/visibility rules, entitlement and plan gating, "active/published/available" state machines, pricing eligibility, feature-flag filtering. A PM should care about these because a silent scope regression is a data-leak or a wrong-price bug, not a cosmetic defect — and these rules are typically the least directly tested part of a Laravel codebase.
  • Roadmap: refactoring and consolidation confidence. When engineering wants to merge overlapping scopes, rename them, or push filtering down into query objects/repositories, an assertion library turns "we think this is equivalent" into a test that fails loudly. That directly affects how much roadmap capacity gets consumed by regression firefighting after a query-layer refactor.
  • Test-suite economics. Two common alternatives are both expensive: asserting on raw SQL strings (brittle, unreadable, breaks on unrelated formatting changes) or building fixtures and asserting on result sets (slow, indirect — a passing test doesn't tell you which scope did the filtering). Asserting that a scope was applied is faster to write, faster to run, and produces failure messages that point at the actual rule.
  • Use cases worth piloting first: the highest-value targets are scopes guarding access (tenant/owner), money (pricing, discount eligibility), and inventory/availability. These are the scopes where "we have no direct test" is an uncomfortable sentence in a review.
  • What it does not decide: it doesn't affect runtime performance (dev-only), doesn't change your public API, and doesn't substitute for integration tests that verify the composed query actually returns correct rows.

When to Consider This Package

Reasonable to adopt when:

  • You have a non-trivial number of model scopes (roughly: more than a handful, or any scopes guarding access, tenancy, or pricing) that encode product rules rather than trivial ordering.
  • Your current coverage of those scopes is thin, or is held up by SQL-string assertions and fixture-heavy result tests you'd like to retire.
  • You're already on PHPUnit/Pest with a per-model unit test layer where a scope assertion fits naturally.
  • You have verified Laravel compatibility against your target version. Last release was 2023-02-19, which predates several Laravel majors; confirm the illuminate/* constraint in composer.json resolves against your installed version before you commit.
  • The blast radius is small: dev dependency only, not shipped to production, easy to remove.

Look elsewhere when:

  • You only have a few scopes — a hand-rolled helper or a DB::listen / QueryExecuted assertion covers it with zero dependency risk.
  • You need the package to work on a Laravel version it doesn't declare support for. Patching a third-party testing package's internals is a bad trade; write the helper yourself.
  • You require maintenance guarantees, an SLA, or a vendor relationship. 18 stars and a single maintainer with a 2023 last release means "no support" — plan for that explicitly.
  • Your architecture deliberately keeps business rules out of scopes (query objects, repositories, dedicated filter classes). Assert on those abstractions instead; the package solves a problem you've already designed away.
  • Your team's testing philosophy is integration-first and you'd rather assert on real returned rows through the full stack — legitimate, and this package adds little there.

Verdict framing: treat this as an evaluate-and-wrap candidate, not an adopt-and-depend. Timebox a pilot on two or three high-risk scopes, put the assertions behind an internal test helper, and keep the swap-out cost near zero.

How to Pitch It (Stakeholders)

For executives (one paragraph): We can close a real test-coverage gap on the query rules that decide who sees what and what things cost — tenant isolation, visibility, eligibility, pricing — for the cost of a dev-only dependency and roughly an afternoon of engineering time. It has zero production footprint and zero runtime cost. The caveat is maintenance: it's a small open-source utility with a single maintainer and a 2023 last release, so we'd use it behind our own thin wrapper and can replace it with in-house code in under a day if it's abandoned. Recommendation: low-cost pilot on our highest-risk scopes, no commitment to broad rollout until we've confirmed it works on our current Laravel version.

For engineering: Small MIT-licensed testing helper that lets you assert a scope was applied instead of parsing generated SQL or standing up fixtures to infer it from results. That means clearer failure messages, faster tests, and safe refactors when we consolidate scopes. The trade-offs are honest: ~18 stars, one maintainer, last tagged release Feb 2023 — verify the illuminate/* constraint against our Laravel version first. Adopt it the way we'd adopt any single-maintainer utility: wrap the public assertions in our own test helper so the dependency is swappable, keep it in require-dev, and don't let it creep into application code. If compatibility or maintenance becomes a problem, the fallback is a DB::listen/QueryExecuted assertion of about thirty lines.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus