# Development

This guide explains how to run the test suite, build the documentation, and navigate `friendsofmago/mago-mockery`.

## Run the test suite

Install development dependencies and run all checks:

```
composer install
php tests/check-spec.php
composer test
```

`composer test` runs two suites in order:

- `php tests/run.php` runs `tests/check-providers.php`, `tests/check-docs.php`, `mago extension validate`, and fixture analysis in default, `--no-extensions`, and `MAGO_MOCKERY_STRICT_METHODS=1` modes.
- `vendor/bin/phpunit tests/runtime` runs PHPUnit runtime contract tests against real Mockery 1.6 behavior and `DocsTest`.

If you use `just`, run `just check-ci` to run Composer validation, PHP syntax checks, spec checks, both test suites, and a strict docs build. Set `MAGO_BIN=/path/to/mago` to test against a different Mago binary.

## Run self-analysis and corpus checks

Run Mago's analyzer against `src/`, `bin/`, and `resources/` and compare against the committed baseline:

```
vendor/bin/mago --config mago-self.toml analyze --reporting-format=json > .mago-self-report.json || true
php tools/self-analyze-gate.php .mago-self-report.json
```

Run pinned open-source corpus checks against Mockery and Laravel test suites:

```
php tools/corpus-run.php --check
php tools/corpus-run.php --strict-methods
php tools/corpus-run.php --update-baseline
```

Run local benchmarks and refresh spec source hashes:

```
php bench/run-local.php --iterations=10000 --runs=5
php spec/harvest.php
```

## Build and preview the docs

The documentation lives in `docs/` and builds with [Zensical](<https://zensical.org/>) from `zensical.toml`.

Serve the site locally with live reload on `http://127.0.0.1:8000`:

```
just docs
```

Build the site into `site/` and fail on broken links or anchors:

```
just docs-build
```

Both commands install the Zensical version pinned in `Justfile` into `.venv/`.

`tests/DocsCheck.php` runs through both `tests/check-docs.php` and `tests/runtime/DocsTest.php` and checks three invariants in CI:

1. Every diagnostic code in `src/` has a heading in `docs/analyzer/diagnostics.md`, and `docs/analyzer/diagnostics.md` lists no stale plugin diagnostic codes.
2. Every `.md` file under `docs/` appears in `zensical.toml` `nav` and in `[project.plugins.llmstxt.sections]` in the same order.
3. Every internal Markdown link and heading anchor inside `docs/` resolves to an existing file and heading.

## Source layout

- `src/MockeryExtension.php` exposes the public entry points `MockeryExtension::create()` and `MockeryExtension::plugins()`.
- `src/Analyzer/MockeryPlugin.php` registers the main `mockery` plugin, its providers, PHPUnit initializers, entry points, trait constant issue filter, and opt-in strict hooks.
- `src/Analyzer/NamedFetchMockPlugin.php` registers the `mockery-named-fetch` plugin for span-dependent `fetchMock()` resolution.
- `src/Analyzer/Providers/` holds all return type providers, callable signature overrides, strict-mode hooks, named-mock indexing, and trait constant flow analysis classes.
- `resources/worker.php` and `bin/mago-mockery-worker` implement the bundled extension host worker.
- `tests/fixtures/`, `tests/phpunit-fixtures/`, `tests/mockery-1612-fixtures/`, and `tests/strict-fixtures/` contain analyzer fixtures that `tests/run.php` verifies.
- `tests/runtime/` contains PHPUnit tests that verify Mockery 1.6 runtime contracts and documentation invariants.
