Configuration

phpspec can be configured via a config file in the project root. The first file found wins.

Config file priority

  1. phpspec.yaml (highest)
  2. phpspec.yml
  3. phpspec.json
  4. phpspec.php (lowest)

Example: phpspec.yaml

spec_path: spec
src_path: src
format: pretty
bootstrap: bootstrap.php
stop_on_failure: false
autoload:
  App\: src/App
  Acme\: lib/Acme

Example: phpspec.json

{
    "spec_path": "spec",
    "src_path": "src",
    "format": "pretty",
    "bootstrap": "bootstrap.php",
    "stop_on_failure": false,
    "autoload": {
        "App\\": "src/App"
    }
}

Configuration keys

KeyDefaultDescription
spec_pathspecDirectory containing spec files
src_pathsrcSource directory for code generation and coverage
spec_suffix.spec.phpFile suffix for spec files
formatprettypretty, dot, tap, junit
bootstrapPHP file to require before running
stop_on_failurefalseStop on first failure or error
stop_on_errorfalseStop on first error
stop_on_warningfalseStop on first warning
stop_on_deprecationfalseStop on first deprecation
stop_on_noticefalseStop on first notice
stop_on_skippedfalseStop on first skip
autoloadPSR-4 namespace-to-directory mappings
base_urlBase URL for browser testing

PSR-4 autoloading

autoload:
  App\: src/App
  Domain\: src/Domain
  Infrastructure\: src/Infrastructure

Each key is a namespace prefix (with trailing \), each value is a directory path relative to the project root.

Named suites

Group specs into named suites, each with its own paths:

suites:
  unit:
    paths:
      - spec/Unit
    src: src
  integration:
    paths:
      - spec/Integration
    src: src

When no suites key is present, phpspec synthesises a default suite from spec_path and src_path.

CLI overrides

CLI flags take priority over config file values:

Config keyCLI flag
format--format / -f
bootstrap--bootstrap / -b
stop_on_failure--stop-on-failure
stop_on_error--stop-on-error

Auto-detection

phpspec automatically detects and requires vendor/autoload.php if it exists. Composer-managed projects work out of the box.

AI configuration

Enable AI-powered pair, next, and refactor commands:

ai:
  provider: anthropic
  api_key: YOUR_API_KEY
ProviderDefault Model
googlegemini-2.5-pro
anthropicclaude-sonnet-4-20250514
openaigpt-4o

See AI Pair Programming for full documentation.

Extensions

extensions:
  matchers:
    - App\ValidJsonMatcher
  formatters:
    - App\MinimalFormatter
  commands:
    - App\GreetCommand
  listeners:
    - App\SlowTestReporter

See Extensions for details.