Skip to content

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

AttributeDescriptionExample
ignoreSkip the block entirelyphp ignore
no_runSyntax check only, don't executephp no_run
throwsExpect an exceptionphp throws(RuntimeException)
parse_errorExpect a parse errorphp parse_error
groupGroup blocks sharing statephp group="name"
setupSetup code for a groupphp setup group="name"
teardownTeardown code for a groupphp 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:

  1. ignore — Skip immediately, no further processing
  2. no_run — Syntax check only (php -l)
  3. parse_error — Execute and expect non-zero exit code
  4. throws — Execute with try/catch wrapper
  5. group/setup/teardown — Group execution with shared state

Released under the MIT License.