Getting Started
DocTest is a PHP documentation testing tool that validates code examples in your markdown files. Write documentation with confidence — if it compiles and runs, it stays correct.
Why DocTest?
Code examples in documentation rot. APIs change, methods get renamed, return types evolve — but the docs stay frozen. DocTest solves this by:
- Extracting PHP code blocks from your markdown files
- Executing them in isolated processes
- Verifying their output matches expected values
If an example breaks, you'll know immediately.
Quick Start
1. Install
bash
composer require --dev testflowlabs/doctest2. Add an Assertion
Write a PHP code block in any markdown file with an assertion in an HTML comment:
markdown
```php
echo 'Hello, World!';
```
<!-- doctest: Hello, World! -->3. Run
bash
vendor/bin/doctestDocTest scans docs/ and README.md by default. That's it.
What Happens
- DocTest finds all
.mdfiles in the configured paths - It extracts PHP code blocks (fenced with
```php) - Each block is executed in an isolated PHP process
- Output is compared against the assertion
- Results are reported to the console