Interface Kitab\Compiler\Target\DocTest\CodeBlockHandler\Definition

interface Definition
{
    public function getDefinitionName(): string;
    public function mightHandleCodeBlock(string $codeBlockType): bool;
    public function 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

public function 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.

public function mightHandleCodeBlock(string $codeBlockType): bool

Check whether a code block might be compiled by this handler into a test case body based on its type.

public function 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.