Skip to content

Commit f72e1f8

Browse files
committed
Allow regenerating expected formatter outputs
1 parent 55e4406 commit f72e1f8

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

bin/regenerate-expected-output

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use Doctrine\SqlFormatter\CliHighlighter;
5+
use Doctrine\SqlFormatter\HtmlHighlighter;
6+
use Doctrine\SqlFormatter\NullHighlighter;
7+
use Doctrine\SqlFormatter\SqlFormatter;
8+
use Doctrine\SqlFormatter\Tests\SqlFormatterTest;
9+
10+
require __DIR__ . '/../vendor/autoload.php';
11+
12+
$formatter = new SqlFormatter(new HtmlHighlighter());
13+
14+
updateExpected('format-highlight.html', [$formatter, 'format']);
15+
updateExpected('format.txt', [new SqlFormatter(new NullHighlighter()), 'format']);
16+
updateExpected('highlight.html', [$formatter, 'highlight']);
17+
updateExpected('clihighlight.txt', [new SqlFormatter(new CliHighlighter()), 'format']);
18+
updateExpected('compress.txt', [$formatter, 'compress']);
19+
20+
function updateExpected(string $filename, callable $highlight): void
21+
{
22+
$data = [];
23+
24+
foreach (SqlFormatterTest::fileSqlData() as $sql) {
25+
$data[] = rtrim($highlight($sql), "\n");
26+
}
27+
28+
file_put_contents(__DIR__ . '/../tests/' . $filename, implode("\n---\n", $data) . "\n");
29+
}

tests/SqlFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testUsePre(): void
101101
}
102102

103103
/** @return string[] */
104-
private static function fileSqlData(): array
104+
public static function fileSqlData(): array
105105
{
106106
$contents = file_get_contents(__DIR__ . '/sql.sql');
107107
assert($contents !== false);

0 commit comments

Comments
 (0)