# Development

Follow these steps to run tests, check documentation, verify conformance fixtures, and contribute changes to `friendsofmago/mago-symfony`.

## Install dependencies

Clone the repository and install Composer dependencies:

```
composer install
```

## Run the test suite

Run the full test suite, conformance catalog validation, and docs test:

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

If you have `just` installed, run all CI checks, including the Zensical docs build, with one command:

```
just check-ci
```

`composer test` runs `php tests/run.php`, which executes:

- `vendor/bin/mago extension validate`
- `tests/runtime.php`, covering Symfony runtime contract tests and worker checks
- `tests/docs-test.php`, covering diagnostic coverage, Zensical navigation and `llmstxt` parity, and internal Markdown links
- Exact diagnostic assertions across JSON map, compiled XML, Security user, plain console, lifecycle, `TreeBuilder`, and explicit configuration-error modes

Set `MAGO=/path/to/mago` with `just`, or `MAGO_BIN=/path/to/mago` with `php tests/run.php`, to test against another Mago binary.

## Run self-analysis

Analyze `src/`, `bin/`, and `resources/` against the committed self-analysis baseline:

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

## Run corpus checks, benchmarks, and spec harvesting

Run the pinned open-source corpus checks across `symfony-demo`, `symfony`, `shopware`, and `drupal`:

```
php tools/corpus-run.php --check
php tools/corpus-run.php --target=symfony-demo,symfony --check
php tools/corpus-run.php --update-baseline
```

Run local benchmarks and verify conformance hashes:

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

## Build and preview documentation

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

Preview locally with live reload on `http://127.0.0.1:8000`:

```
just docs
```

Build into `site/` and fail on any broken link or anchor:

```
just docs-build
```

Both recipes install Zensical `0.1.1` into `.venv/`.

## Repository layout

- `src/SymfonyExtension.php` defines the public `create()` and `plugins()` entry points.
- `src/Analyzer/SymfonyPlugin.php` registers the `symfony` analyzer plugin, its return-type providers, lifecycle initializers, entry points, and analysis hooks.
- `src/Analyzer/TreeBuilderRootTypePlugin.php` registers the `symfony-tree-builder-root` analyzer plugin so `SymfonyPlugin` keeps provider memoization enabled.
- `src/Analyzer/Providers/` contains every provider, hook, index, loader, and issue filter.
- `resources/worker.php` and `bin/mago-symfony-worker` implement the worker entry points.
- `tests/` contains runtime contract checks, fixture suites, and `tests/docs-test.php`.
- `spec/` contains the pinned conformance catalog verified by `tests/check-spec.php`.

## Keep documentation in sync

When you add or change a diagnostic code in `src/`:

1. Update the code's entry and summary row in [Diagnostics](<https://friendsofmago.github.io/mago-symfony/analyzer/diagnostics/index.md>).
2. Update the topic page under `docs/analyzer/`.
3. Run `php tests/docs-test.php` and `just docs-build`.

When you add a new Markdown page under `docs/`:

1. Add the page to `nav` in `zensical.toml`.
2. Add the same page in the exact same order under `[project.plugins.llmstxt.sections]` in `zensical.toml`.
3. Run `php tests/docs-test.php` and `just docs-build`.
