19
19
use function explode ;
20
20
use function file_get_contents ;
21
21
use function pack ;
22
+ use function rtrim ;
22
23
use function sprintf ;
23
- use function trim ;
24
24
25
25
final class SqlFormatterTest extends TestCase
26
26
{
@@ -37,20 +37,20 @@ protected function setUp(): void
37
37
#[DataProvider('formatHighlightData ' )]
38
38
public function testFormatHighlight (string $ sql , string $ html ): void
39
39
{
40
- $ this ->assertEquals ( trim ( $ html), trim ( $ this ->formatter ->format ($ sql) ));
40
+ $ this ->assertSame ( $ html, $ this ->formatter ->format ($ sql ));
41
41
}
42
42
43
43
#[DataProvider('formatData ' )]
44
44
public function testFormat (string $ sql , string $ html ): void
45
45
{
46
46
$ formatter = new SqlFormatter (new NullHighlighter ());
47
- $ this ->assertEquals ( trim ( $ html), trim ( $ formatter ->format ($ sql) ));
47
+ $ this ->assertSame ( $ html, $ formatter ->format ($ sql ));
48
48
}
49
49
50
50
#[DataProvider('highlightData ' )]
51
51
public function testHighlight (string $ sql , string $ html ): void
52
52
{
53
- $ this ->assertEquals ( trim ( $ html), trim ( $ this ->formatter ->highlight ($ sql) ));
53
+ $ this ->assertSame ( $ html, $ this ->formatter ->highlight ($ sql ));
54
54
}
55
55
56
56
public function testHighlightBinary (): void
@@ -69,42 +69,42 @@ public function testHighlightBinary(): void
69
69
$ binaryData .
70
70
'</span> <span style="font-weight:bold;">AS</span> <span style="color: #333;">BINARY</span></pre> ' ;
71
71
72
- $ this ->assertEquals ( trim ( $ html), trim ( $ this ->formatter ->highlight ($ sql) ));
72
+ $ this ->assertSame ( $ html, $ this ->formatter ->highlight ($ sql ));
73
73
}
74
74
75
75
#[DataProvider('highlightCliData ' )]
76
76
public function testCliHighlight (string $ sql , string $ html ): void
77
77
{
78
78
$ formatter = new SqlFormatter (new CliHighlighter ());
79
- $ this ->assertEquals ( trim ( $ html), trim ( $ formatter ->format ($ sql) ));
79
+ $ this ->assertSame ( $ html . "\n" , $ formatter ->format ($ sql ));
80
80
}
81
81
82
82
#[DataProvider('compressData ' )]
83
83
public function testCompress (string $ sql , string $ html ): void
84
84
{
85
- $ this ->assertEquals ( trim ( $ html), trim ( $ this ->formatter ->compress ($ sql) ));
85
+ $ this ->assertSame ( $ html, $ this ->formatter ->compress ($ sql ));
86
86
}
87
87
88
88
public function testUsePre (): void
89
89
{
90
90
$ formatter = new SqlFormatter (new HtmlHighlighter ([], false ));
91
91
$ actual = $ formatter ->highlight ('test ' );
92
92
$ expected = '<span style="color: #333;">test</span> ' ;
93
- $ this ->assertEquals ($ actual , $ expected );
93
+ $ this ->assertSame ($ actual , $ expected );
94
94
95
95
$ formatter = new SqlFormatter (new HtmlHighlighter ([], true ));
96
96
$ actual = $ formatter ->highlight ('test ' );
97
97
$ expected = '<pre style="color: black; background-color: white;"> ' .
98
98
'<span style="color: #333;">test</span></pre> ' ;
99
- $ this ->assertEquals ($ actual , $ expected );
99
+ $ this ->assertSame ($ actual , $ expected );
100
100
}
101
101
102
102
/** @return Generator<mixed[]> */
103
103
private static function fileDataProvider (string $ file ): Generator
104
104
{
105
105
$ contents = file_get_contents (__DIR__ . '/ ' . $ file );
106
106
assert ($ contents !== false );
107
- $ formatHighlightData = explode ("\n--- \n" , $ contents );
107
+ $ formatHighlightData = explode ("\n--- \n" , rtrim ( $ contents, "\n" ) );
108
108
$ sqlData = self ::sqlData ();
109
109
if (count ($ formatHighlightData ) !== count ($ sqlData )) {
110
110
throw new UnexpectedValueException (sprintf (
@@ -156,6 +156,6 @@ private static function sqlData(): array
156
156
$ contents = file_get_contents (__DIR__ . '/sql.sql ' );
157
157
assert ($ contents !== false );
158
158
159
- return explode ("\n--- \n" , $ contents );
159
+ return explode ("\n--- \n" , rtrim ( $ contents, "\n" ) );
160
160
}
161
161
}
0 commit comments