Interface Kitab\Compiler\Target\DocTest\CodeBlockHandler\Definition
interface Definition
{
pub fn getDefinitionName(): string;
pub fn mightHandleCodeBlock(string $codeBlockType): bool;
pub fn compileToTestCaseBody(string $codeBlockType, string $codeBlockContent): string;
}
Define a code block handler.
A code handler has a name, matches only some specific types, and is able to compile a code block content into a test case body.
For a concrete implementation example, see the
Kitab\Compiler\Target\DocTest\CodeBlockHandler\Php
.
Methods
-
pub fn getDefinitionName(): string
-
The name of a handler is used to differentiate test cases generated by different handlers.
Be careful that these names can be used as PHP identifiers.
-
pub fn mightHandleCodeBlock(string $codeBlockType): bool
-
Check whether a code block might be compiled by this handler into a test case body based on its type.
-
pub fn compileToTestCaseBody(string $codeBlockType, string $codeBlockContent): string
-
The core of a handler: Compile a code block content into a test case body.
The test case body must not include the test case “definition” (like
public function …
), nor its name, only the body.The code block type can be a single identifier, a list of identifiers with or without arguments. This is the raw code block type. It is up to the handler to parse it. The code block content is also the raw value from the documentation. No transformation is applied.