Allow regenerating expected formatter outputs

This commit is contained in:
Jakub Vrana
2025-09-26 11:08:56 +02:00
committed by Jakub Vrana
parent 55e4406237
commit a5aa636593
3 changed files with 34 additions and 1 deletions

View File

@@ -20,3 +20,7 @@ vendor/bin/phpunit --testdox
echo '' | vendor/bin/phpcs
vendor/bin/phpstan analyze
```
## Regenerating expected output
To regenerate expected tests output, run `bin/regenerate-expected-output`.

29
bin/regenerate-expected-output Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env php
<?php
use Doctrine\SqlFormatter\CliHighlighter;
use Doctrine\SqlFormatter\HtmlHighlighter;
use Doctrine\SqlFormatter\NullHighlighter;
use Doctrine\SqlFormatter\SqlFormatter;
use Doctrine\SqlFormatter\Tests\SqlFormatterTest;
require __DIR__ . '/../vendor/autoload.php';
$formatter = new SqlFormatter(new HtmlHighlighter());
updateExpected('format-highlight.html', [$formatter, 'format']);
updateExpected('format.txt', [new SqlFormatter(new NullHighlighter()), 'format']);
updateExpected('highlight.html', [$formatter, 'highlight']);
updateExpected('clihighlight.txt', [new SqlFormatter(new CliHighlighter()), 'format']);
updateExpected('compress.txt', [$formatter, 'compress']);
function updateExpected(string $filename, callable $highlight): void
{
$data = [];
foreach (SqlFormatterTest::fileSqlData() as $sql) {
$data[] = rtrim($highlight($sql), "\n");
}
file_put_contents(__DIR__ . '/../tests/' . $filename, implode("\n---\n", $data) . "\n");
}

View File

@@ -101,7 +101,7 @@ final class SqlFormatterTest extends TestCase
}
/** @return string[] */
private static function fileSqlData(): array
public static function fileSqlData(): array
{
$contents = file_get_contents(__DIR__ . '/sql.sql');
assert($contents !== false);