<?php

declare(strict_types=1);

$source = file_get_contents(__DIR__ . '/gift_fixture.php');
if (!is_string($source)) throw new RuntimeException('Gift fixture source unavailable');
$checks = 0;
$hasOne = static function (string $needle) use ($source, &$checks): void {
    $checks++;
    if (substr_count($source, $needle) !== 1) {
        throw new RuntimeException('Gift SQL fragment missing/duplicated');
    }
};
$hasOne(<<<'PHP'
$describeColumn = $dialect === 'dm' ? '"DESCRIBE"' : '`describe`';
PHP
);
$hasOne(<<<'PHP'
. ' BIZ_ORDER_ID,BIZ_ORDER_NO,IDEMPOTENCY_KEY,' . $describeColumn . ',REMARK,'
PHP
);
$hasOne(' VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,10001,?)');
$checks++;
if (substr_count($source, 'IDEMPOTENCY_KEY,DESCRIBE,REMARK') !== 0) {
    throw new RuntimeException('Unquoted DESCRIBE returned to Gift INSERT');
}
$checks++;
if ('IDEMPOTENCY_KEY,`describe`,REMARK' !== 'IDEMPOTENCY_KEY,'
    . '`describe`' . ',REMARK') throw new RuntimeException('MySQL quote fragment drift');
$checks++;
if ('IDEMPOTENCY_KEY,"DESCRIBE",REMARK' !== 'IDEMPOTENCY_KEY,'
    . '"DESCRIBE"' . ',REMARK') throw new RuntimeException('DM quote fragment drift');
echo 'GiftFixtureSqlFragmentTest pass assertions=' . $checks . PHP_EOL;
