Attributes Overview
Attributes control how DocTest handles each code block. They are written in the fence info string after php.
Syntax
Attributes appear after the language identifier in the code fence:
markdown
```php ignore
// This block is skipped
```
```php throws(RuntimeException)
throw new RuntimeException('Error');
```
```php group="database" setup
$pdo = new PDO('sqlite::memory:');
```Available Attributes
| Attribute | Description | Example |
|---|---|---|
ignore | Skip the block entirely | php ignore |
no_run | Syntax check only, don't execute | php no_run |
throws | Expect an exception | php throws(RuntimeException) |
parse_error | Expect a parse error | php parse_error |
group | Group blocks sharing state | php group="name" |
setup | Setup code for a group | php setup group="name" |
teardown | Teardown code for a group | php teardown group="name" |
Combining Attributes
Some attributes can be combined:
markdown
```php setup group="database"
// Both setup and group
```
```php teardown group="database"
// Both teardown and group
```Processing Order
When a block has attributes, DocTest processes them in this order:
- ignore — Skip immediately, no further processing
- no_run — Syntax check only (
php -l) - parse_error — Execute and expect non-zero exit code
- throws — Execute with try/catch wrapper
- group/setup/teardown — Group execution with shared state