mirror of
https://github.com/doctrine/sql-formatter.git
synced 2026-03-23 22:42:14 +01:00
Allow regenerating expected formatter outputs
This commit is contained in:
@@ -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
29
bin/regenerate-expected-output
Executable 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");
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user