Skip to content

Commit 6eb85e0

Browse files
authored
Merge pull request #108 from mvorisek/fix_tests_for_win
Make sure all lines are terminated by LF
2 parents a98a55e + 6e6922b commit 6eb85e0

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/CliHighlighter.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use function sprintf;
88

9-
use const PHP_EOL;
10-
119
final class CliHighlighter implements Highlighter
1210
{
1311
public const HIGHLIGHT_FUNCTIONS = 'functions';
@@ -59,7 +57,7 @@ public function highlightError(string $value): string
5957
{
6058
return sprintf(
6159
'%s%s%s%s',
62-
PHP_EOL,
60+
"\n",
6361
$this->escapeSequences[self::HIGHLIGHT_ERROR],
6462
$value,
6563
"\x1b[0m",

src/HtmlHighlighter.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use const ENT_COMPAT;
1212
use const ENT_IGNORE;
13-
use const PHP_EOL;
1413

1514
final class HtmlHighlighter implements Highlighter
1615
{
@@ -70,7 +69,7 @@ public function highlightError(string $value): string
7069
{
7170
return sprintf(
7271
'%s<span %s>%s</span>',
73-
PHP_EOL,
72+
"\n",
7473
$this->htmlAttributes[self::HIGHLIGHT_ERROR],
7574
$value,
7675
);

tests/SqlFormatterTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use function explode;
2020
use function file_get_contents;
2121
use function pack;
22+
use function rtrim;
2223
use function sprintf;
23-
use function trim;
2424

2525
final class SqlFormatterTest extends TestCase
2626
{
@@ -37,20 +37,20 @@ protected function setUp(): void
3737
#[DataProvider('formatHighlightData')]
3838
public function testFormatHighlight(string $sql, string $html): void
3939
{
40-
$this->assertEquals(trim($html), trim($this->formatter->format($sql)));
40+
$this->assertSame($html, $this->formatter->format($sql));
4141
}
4242

4343
#[DataProvider('formatData')]
4444
public function testFormat(string $sql, string $html): void
4545
{
4646
$formatter = new SqlFormatter(new NullHighlighter());
47-
$this->assertEquals(trim($html), trim($formatter->format($sql)));
47+
$this->assertSame($html, $formatter->format($sql));
4848
}
4949

5050
#[DataProvider('highlightData')]
5151
public function testHighlight(string $sql, string $html): void
5252
{
53-
$this->assertEquals(trim($html), trim($this->formatter->highlight($sql)));
53+
$this->assertSame($html, $this->formatter->highlight($sql));
5454
}
5555

5656
public function testHighlightBinary(): void
@@ -69,42 +69,42 @@ public function testHighlightBinary(): void
6969
$binaryData .
7070
'</span> <span style="font-weight:bold;">AS</span> <span style="color: #333;">BINARY</span></pre>';
7171

72-
$this->assertEquals(trim($html), trim($this->formatter->highlight($sql)));
72+
$this->assertSame($html, $this->formatter->highlight($sql));
7373
}
7474

7575
#[DataProvider('highlightCliData')]
7676
public function testCliHighlight(string $sql, string $html): void
7777
{
7878
$formatter = new SqlFormatter(new CliHighlighter());
79-
$this->assertEquals(trim($html), trim($formatter->format($sql)));
79+
$this->assertSame($html . "\n", $formatter->format($sql));
8080
}
8181

8282
#[DataProvider('compressData')]
8383
public function testCompress(string $sql, string $html): void
8484
{
85-
$this->assertEquals(trim($html), trim($this->formatter->compress($sql)));
85+
$this->assertSame($html, $this->formatter->compress($sql));
8686
}
8787

8888
public function testUsePre(): void
8989
{
9090
$formatter = new SqlFormatter(new HtmlHighlighter([], false));
9191
$actual = $formatter->highlight('test');
9292
$expected = '<span style="color: #333;">test</span>';
93-
$this->assertEquals($actual, $expected);
93+
$this->assertSame($actual, $expected);
9494

9595
$formatter = new SqlFormatter(new HtmlHighlighter([], true));
9696
$actual = $formatter->highlight('test');
9797
$expected = '<pre style="color: black; background-color: white;">' .
9898
'<span style="color: #333;">test</span></pre>';
99-
$this->assertEquals($actual, $expected);
99+
$this->assertSame($actual, $expected);
100100
}
101101

102102
/** @return Generator<mixed[]> */
103103
private static function fileDataProvider(string $file): Generator
104104
{
105105
$contents = file_get_contents(__DIR__ . '/' . $file);
106106
assert($contents !== false);
107-
$formatHighlightData = explode("\n---\n", $contents);
107+
$formatHighlightData = explode("\n---\n", rtrim($contents, "\n"));
108108
$sqlData = self::sqlData();
109109
if (count($formatHighlightData) !== count($sqlData)) {
110110
throw new UnexpectedValueException(sprintf(
@@ -156,6 +156,6 @@ private static function sqlData(): array
156156
$contents = file_get_contents(__DIR__ . '/sql.sql');
157157
assert($contents !== false);
158158

159-
return explode("\n---\n", $contents);
159+
return explode("\n---\n", rtrim($contents, "\n"));
160160
}
161161
}

0 commit comments

Comments
 (0)