1919use function explode ;
2020use function file_get_contents ;
2121use function pack ;
22+ use function rtrim ;
2223use function sprintf ;
23- use function trim ;
2424
2525final 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