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

Spectator Laravel Package

hotmeteor/spectator

Spectator brings lightweight OpenAPI contract testing to your Laravel test suite. Write tests that guarantee your API spec never drifts from your implementation, with artisan validation commands, operation coverage tracking, and JSON error output for CI.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

  • Spectator is a test-time-only dev dependency: it does not sit in the request path, add middleware, or change production runtime behavior. That makes it a low-blast-radius addition to an existing Laravel application and easy to justify as a quality tool rather than a platform commitment.
  • It fits a spec-driven contract-testing model: the OpenAPI document becomes an executable artifact, and Laravel HTTP/feature tests assert that responses conform. This complements existing feature tests rather than replacing them.
  • The fit is strongest when the OpenAPI spec is an intentional, reviewed source of truth. If the spec is generated from code annotations, contract testing becomes partially circular — still useful for catching regeneration drift, but weaker as an independent contract.
  • The spectator:routes command is particularly valuable architecturally: it produces a spec-to-route cross-reference, which doubles as an inventory of undocumented endpoints and spec entries with no implementation. As of v3.0.4 this output shows the fully resolved path including route prefixes, which materially improves the artifact for versioned/prefixed API groups (/api/v1/...) where route registration and public paths diverge.

Integration feasibility

  • Installation is conventional: Composer dev dependency, published config, PHPUnit extension registration, and test-suite usage. No database, queue, or infrastructure changes are required.
  • v3.0.4 is a patch release with no breaking changes, no deprecations, and no new platform requirements — it drops onto the same PHP 8.3+/Laravel 12+ baseline. Note that it does change validation behavior on a specific input class (empty application/x-www-form-urlencoded request bodies against object schemas), so it is a behavior-affecting patch rather than a no-op.
  • CI integration is feasible at multiple depths: spectator:validate as a spec linter, spectator:routes as a coverage/gap report, assertion helpers in tests, and SpectatorExtension as a coverage gate. All commands support --format=json, which makes CI dashboards and threshold enforcement tractable.
  • The hard requirements — PHP 8.3+ and Laravel 12+ — are the primary feasibility gate. Applications on older Laravel or PHP versions cannot adopt v3 without an upgrade, and should not assume v2 remains a supported long-term path.

Technical risk

  • Adoption/bus-factor risk: 306 stars and zero Packagist dependents indicate a small ecosystem. The project is actively released, but it is a single-maintainer-class dependency with community-only support. Mitigation: pin versions and treat the package as replaceable — the tests are ordinary PHP and can be rewritten if the package is abandoned.
  • Maturity/edge-case risk: the v3.0.4 fix for a 500 error on empty form-urlencoded bodies against object schemas is a useful signal — core response validation is stable, but peripheral input paths (non-JSON request bodies, empty payloads, content-type edge cases) still have rough edges. Budget verification effort for any endpoint outside the JSON-body happy path.
  • Coverage-confidence risk: the coverage extension tracks which spec operations are exercised, not whether assertions are meaningful. Teams can hit a coverage threshold while asserting little beyond status codes.
  • Spec-quality risk: Spectator validates implementation against the spec; a permissive spec (loose additionalProperties, unconstrained fields) produces green tests that miss real contract breaks.
  • Upgrade risk: v3 is a major version with raised platform minimums and internals replaced by enums. Patch releases within v3 should still be treated as testable changes, not silent bumps, given they can alter validation semantics.
  • CI fragility risk: an invalid or partially migrated spec can fail pipelines broadly; JSON error output helps, but the spec itself becomes a build-critical artifact.

Key questions

  • Is the OpenAPI spec hand-authored and authoritative, or generated from code?
  • Which OpenAPI version and features are in use (3.0 vs 3.1, discriminators, oneOf/anyOf)?
  • What is the current PHP/Laravel version, and is a Laravel 12 / PHP 8.3 upgrade already on the roadmap?
  • Does the API accept non-JSON request bodies (form-urlencoded, multipart), and are those endpoints in the pilot scope? Request-body validation is in scope for the tool, but this is the least-proven surface.
  • Which CI system, and does it consume JSON output natively?
  • Who owns the spec, and what is the review process for spec changes?
  • Are there non-Laravel services in scope that would need a different contract-testing tool?

Integration Approach

Stack fit

  • Native fit for a Laravel monolith or Laravel-based API service running PHPUnit or Pest. No new runtime services, no sidecars, no gateway changes.
  • Fits existing CI pipelines and test-reporting tooling through JSON output. The PHPUnit extension means coverage enforcement can live alongside existing quality gates rather than in a separate toolchain.
  • Poor fit for polyglot estates that need one contract-testing approach across Laravel, Node, and Go services. In that case, Spectator should be positioned as the Laravel-specific layer under a broader contract-testing strategy.

Migration path

  • Adopt in read-only mode first: run spectator:validate and spectator:routes in CI without failing builds. This establishes a baseline of spec validity and route coverage with zero test-writing effort and negligible risk.
  • Pilot on one bounded domain — ideally a recently changed JSON API surface with an accurate spec — using spectator:stubs to generate skeleton tests, then hand-tightening assertions. Defer form-encoded/upload endpoints until the JSON pilot is stable.
  • Coexist with existing feature tests; do not mandate rewrites. Contract tests are additive and can be introduced per endpoint.
  • Promote to enforced gates domain by domain, starting with spec validation, then per-domain coverage thresholds.

Compatibility

  • Gate adoption on PHP 8.3+ and Laravel 12+. Confirm PHPUnit version compatibility and Pest support through the PHPUnit extension path.
  • Verify OpenAPI version support against the actual spec before committing; complex schema constructs are where tooling gaps surface.
  • Pin the package to an exact patch version in composer.json (currently v3.0.4) and include it in the Laravel-major upgrade checklist. Given patch releases can change validation behavior, run the contract suite on any bump rather than relying on semver alone.

Sequencing

  1. Confirm platform versions and spec ownership; decide spec-first vs generated-spec posture.
  2. Add the dev dependency (pinned) and run spectator:validate + spectator:routes non-blocking in CI.
  3. Publish the gap report; prioritize undocumented routes and orphaned spec entries. Use prefixed route output to reconcile route groups against spec paths.
  4. Pilot one domain with generated stubs and hand-written assertions.
  5. Enable SpectatorExtension in report-only mode to measure real operation coverage.
  6. Set thresholds per domain, ratcheting upward; only then make failures blocking.
  7. Expand to additional domains and add spec review to the change-management process.

Operational Impact

Maintenance

  • Low code footprint, but two ongoing obligations: dependency upkeep tied to Laravel/PHP majors, and first-class ownership of the OpenAPI spec. The second is the larger and more persistent cost.
  • Pin exact versions and schedule review at each Laravel upgrade. Patch releases are small in number but can change validation outcomes, so treat bumps as tested changes rather than automatic.

Support

  • MIT, community-supported, no vendor SLA. Requires an internal owner or champion who can debug failures and decide when to patch, fork, or remove. The v3.0.4 fixes were contributed by external contributors, which is a positive signal for responsiveness but not a support guarantee.
  • Exit cost is low: contract tests are plain PHPUnit tests, and the spec is a portable asset. This materially reduces the strategic risk of depending on a small project.

Scaling

  • The operational scaling concern is test-suite duration, not runtime capacity. Assertion overhead grows with the number of covered operations; plan for parallel test execution as coverage expands.
  • In multi-service or monorepo setups, each service needs its own spec and its own CI invocation; there is no cross-service contract orchestration.
  • Coverage thresholds should scale by domain rather than as a single global number, to avoid penalizing newly onboarded modules.

Failure modes

  • Spec/implementation mismatch — the intended failure; produces actionable failures, especially with JSON error output.
  • False green — permissive schemas or status-code-only assertions let real breaks through. Mitigate with schema review and assertion standards.
  • False red — fixture data or environment-specific responses violate the spec for legitimate reasons; requires clear triage guidance.
  • Package-internal error surfacing as a server error — the v3.0.4 regression class, where a validation edge case (empty form body vs object schema) produced a 500 rather than a clean assertion failure. This looks like an application bug in CI output and can burn triage time. Mitigate by pinning, staying current on patches, and treating unexpected 5xx in contract runs as a tooling signal first.
  • Invalid spec blocks CI — a malformed spec fails broadly; keep spec validation as an early, fast, clearly labeled job.
  • Package abandonment or breaking major — mitigated by pinning, low exit cost, and an internal owner.
  • Coverage gaming — teams add shallow tests to clear thresholds; pair coverage gates with review of assertion depth.

Ramp-up

  • Low for Laravel developers already comfortable with PHPUnit/Pest: roughly one to two days to a working pilot.
  • The real learning curve is OpenAPI schema authoring and understanding what the assertions do and do not verify. Budget a sprint for a team to reach fluency and to establish spec-review conventions.
  • Generated stubs substantially lower the barrier to the first test; use them as onboarding scaffolding, not as the final assertion quality bar.
  • Recommended adoption posture: treat Spectator as a cheap, reversible quality layer that makes the spec enforceable — approve for a time-boxed pilot with explicit success criteria (spec validity, route coverage baseline, one domain under contract tests), and revisit for broader rollout after the pilot. v3.0.4 does not change that posture; it narrows, but does not eliminate, the known edge-case risk.
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.
dakiquang/laravel-oauth-refresh-lock
woda/laravel-worktrees
dalefranks/ramasite
faghy/laracashbook
roundly-consulting/google-places-for-laravel
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
adachsoft/changelog-linter