Namespace Kitab\Compiler\Target\DocTest\CodeBlockHandler
Kitab uses code blocks written in the documentation to generate tests
(written in CommonMark, as a reminder). A
code block can have a type, such as php
:
```php
// here is some PHP code
```
or http
:
```http
// here is some HTTP messages.
```
A code block handler is a class that is able to compile code blocks of a given type into test case bodies. Also as a reminder, Kitab relies on atoum for the test framework. Consequently, test cases must use the atoum API.
When compiling code blocks into test cases, the target will loop over all attached code block handlers. If one of them is able to handle a specific code block, then it is used. Many code block handlers can handle the same code block.
A code block handler must extend the
Kitab\Compiler\Target\DocTest\CodeBlockHandler\Definition
interface.
About code block types
A code block type can have 3Â forms:
- A single identifier, like
php
, - A list of identifiers separated by a comma, like
php,ignore
, - Or more sophisticated identifiers with arguments, like
php,must_throw(E)
.
The format is not strict, but it should match these previous examples
as most as possible for the sake of consistency. The main type (here
php
) should also be the former of the list, the other can sometimes
be refered as options.
Classes
-
IntoPHPTestCaseBody
A visitor to transform an Abstract Syntax Tree (AST) into a test case body candidate.
-
Php
A code block handler for the
php
type.
Interfaces
-
Definition
Define a code block handler.