SqlParser\Tools\TestGenerator::build PHP Method

build() public static method

Reads the input file, generates the data and writes it back.
public static build ( string $type, string $input, string $output, string $debug = null ) : void
$type string The type of this test.
$input string The input file.
$output string The output file.
$debug string The debug file.
return void
    public static function build($type, $input, $output, $debug = null)
    {
        // Support query types: `lexer` / `parser`.
        if (!in_array($type, array('lexer', 'parser'))) {
            throw new \Exception('Unknown test type (expected `lexer` or `parser`).');
        }
        /**
         * The query that is used to generate the test.
         *
         * @var string $query
         */
        $query = file_get_contents($input);
        // There is no point in generating a test without a query.
        if (empty($query)) {
            throw new \Exception('No input query specified.');
        }
        $test = static::generate($query, $type);
        // Writing test's data.
        file_put_contents($output, serialize($test));
        // Dumping test's data in human readable format too (if required).
        if (!empty($debug)) {
            file_put_contents($debug, print_r($test, true));
        }
    }