Appearance
HTML comments are the primary way to add assertions in DocTest. They're invisible in rendered documentation, keeping your examples clean.
HTML comment assertions are placed immediately after the code block:
```php echo 'Hello'; ``` <!-- doctest: Hello -->
<!-- doctest: value -->
<!-- doctest-contains: value -->
<!-- doctest-matches: /pattern/ -->
<!-- doctest-json: {...} -->
<!-- doctest-expect: expr -->
<!--
-->
doctest
doctest-contains
For multi-line expected output, the value spans across lines within the HTML comment:
```php echo "line 1\nline 2\nline 3"; ``` <!-- doctest: line 1 line 2 line 3 -->
HTML comment assertions support wildcards:
```php echo 'Generated ID: ' . uniqid(); ``` <!-- doctest: Generated ID: {{any}} -->
echo 'DocTest makes documentation testing easy';
HTML Comment Assertions
HTML comments are the primary way to add assertions in DocTest. They're invisible in rendered documentation, keeping your examples clean.
Syntax
HTML comment assertions are placed immediately after the code block:
Available Types
<!-- doctest: value --><!-- doctest-contains: value --><!-- doctest-matches: /pattern/ --><!-- doctest-json: {...} --><!-- doctest-expect: expr -->Parsing Rules
<!--and end with-->doctest,doctest-contains, etc.) is case-sensitiveMulti-line Values
For multi-line expected output, the value spans across lines within the HTML comment:
Wildcards
HTML comment assertions support wildcards:
Example
Why HTML Comments?