Download the PHP package hotmeteor/spectator without Composer

On this page you can find all versions of the php package hotmeteor/spectator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package spectator

Spectator

Spectator provides light-weight OpenAPI contract testing tools that work within your existing Laravel test suite.

Write tests that guarantee your API spec never drifts from your implementation.

Tests Latest Version on Packagist PHP from Packagist


What's New in v3


Requirements


Installation

Publish the config file:


Configuration

The published config lives at config/spectator.php. The most important setting is the spec source, which tells Spectator where to find your OpenAPI spec files.

Local

Specs are read from the local filesystem.

Remote

Specs are fetched over HTTP. Useful for remote-hosted specs or raw GitHub file URLs.

GitHub

Specs are fetched from a private GitHub repository using a Personal Access Token.

Path Prefix

If your API is mounted under a prefix (e.g. /v1), configure it here so Spectator strips it before matching spec paths.

Or set it at runtime:

Error Format

By default, validation errors are rendered as human-readable, coloured terminal output. For CI pipelines and LLM toolchains that parse test output programmatically, switch to JSON:

Or toggle it per test:


Writing Contract Tests

What contract testing is

Functional tests verify that your application behaves correctly — validation passes, controllers respond, events fire.

Contract tests verify that your requests and responses conform to your OpenAPI spec. The data doesn't have to be real; the shape does.

The two test types complement each other. Keep them in separate test classes.

Pointing to a spec

Call Spectator::using() with the spec filename before making any requests. You can call it once in setUp() or per test.

Making assertions

Spectator adds these methods to Laravel's TestResponse:

Method Description
assertValidRequest() Assert the request matches the spec.
assertInvalidRequest() Assert the request does not match the spec.
assertValidResponse(?int $status) Assert the response matches the spec (optionally at a specific status code).
assertInvalidResponse(?int $status) Assert the response does not match the spec.
assertValidationMessage(string $message) Assert the validation error message contains the given string.
assertErrorsContain(string\|array $errors) Assert one or more strings appear in the validation errors.
assertPathExists() Assert the requested path exists in the spec.
dumpSpecErrors() Dump current spec errors without failing (useful for debugging).

A typical contract test

Mixing with functional tests

You can chain Spectator assertions with Laravel's built-in assertions, but keeping concerns separate is cleaner:

Deactivating Spectator for a test

Debugging errors

When a validation fails, Spectator renders the schema with errors annotated inline:

Symbol legend:

Use dumpSpecErrors() to inspect errors without failing the test:


Artisan Commands

spectator:validate

Validate that a spec file parses without errors. Useful as a pre-test lint gate in CI.

Text output:

JSON output (--format=json):

Returns exit code 0 on success, 1 on failure.

spectator:coverage

List every operation defined in the spec. Useful for auditing coverage gaps.

Text output:

JSON output (--format=json):

spectator:routes

Cross-references spec operations against registered Laravel routes. Surfaces which operations are matched, which are missing from the app, and which routes have no spec entry.

Text output:

Scoping the comparison

If your spec only documents a subset of the app's routes (e.g. the public /api/v2/* surface), every internal admin/web/webhook route otherwise shows up as undocumented and drowns the signal. Two flags narrow the Laravel side of the comparison:

Both can be combined (AND) and only affect the Laravel-routes side — spec operations are still listed as you wrote them. If neither is set, behavior is unchanged.

spectator:stubs

Generates skeleton test classes from a spec. Groups operations by tag (fallback: first path segment) and creates one class per group with one test_ method per operation. Each method body calls $this->markTestIncomplete(...) so the generated file is immediately runnable.

Option Default Description
--spec Spec filename (required).
--output tests/Contract Directory to write generated classes to.
--namespace Tests\Contract PHP namespace for generated classes.
--base-class Tests\TestCase Parent class for generated test classes.
--force false Overwrite existing files.

Example generated class:


CI & AI Integration

Validating specs in CI

Add spectator:validate as an early CI step to catch malformed specs before tests run:

Machine-readable error output

Set SPECTATOR_ERROR_FORMAT=json in your CI environment to make validation errors parseable by log aggregators and LLM agents:

With this setting, a failed assertion produces a JSON error body instead of ANSI-coloured text:

Feeding errors to an LLM

The JSON error format is designed for toolchains that analyse test output programmatically. Parse {"errors": [...]} from test output and pass it directly to your LLM workflow for root-cause analysis or spec repair suggestions.

Contract coverage tracking

SpectatorExtension is a PHPUnit 11 extension that tracks which spec operations are exercised during a test run and prints a coverage summary when the suite finishes.

Enable it in phpunit.xml:

Example output at suite end:

When min_coverage is set and not met, the extension causes PHPUnit to exit with code 1, failing the CI job.


Upgrading

Please read UPGRADE.md for a full list of breaking changes between versions.


Core Concepts

Spectator registers a middleware that intercepts every test request, matches it against the loaded spec's PathItem, and validates both the request and the response. Captured exceptions are stored on the RequestFactory singleton so assertions can read them after the response is returned.

Key dependencies


Sponsors

A huge thanks to all our sponsors who help push Spectator development forward!

If you'd like to become a sponsor, please see here for more information. 💪

Credits

Made with contributors-img.

License

The MIT License (MIT). Please see License File for more information.


All versions of spectator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-json Version *
cebe/php-openapi Version ^1.8
laravel/framework Version >=12.0
opis/json-schema Version ^2.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hotmeteor/spectator contains the following files

Loading the files please wait ...