File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,11 @@ class TextDriver implements Driver
99{
1010 public function serialize ($ data ): string
1111 {
12+ // Normalize line endings for cross-platform tests.
13+ if (PHP_OS_FAMILY === 'Windows ' ) {
14+ $ data = implode ("\n" , explode ("\r\n" , $ data ));
15+ }
16+
1217 return $ data ;
1318 }
1419
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Spatie \Snapshots \Test \Unit \Drivers ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use Spatie \Snapshots \Drivers \TextDriver ;
7+ use Spatie \Snapshots \Exceptions \CantBeSerialized ;
8+
9+ class TextDriverTest extends TestCase
10+ {
11+ /** @test */
12+ public function it_can_serialize_laravel_route_list ()
13+ {
14+ $ driver = new TextDriver ();
15+
16+ $ expected = implode ("\n" , [
17+ '' ,
18+ ' GET|HEAD / ..................................................... index ' ,
19+ '' ,
20+ ' Showing [1] routes '
21+ ]);
22+
23+ $ this ->assertEquals ($ expected , $ driver ->serialize (<<<EOF
24+
25+ GET|HEAD / ..................................................... index
26+
27+ Showing [1] routes
28+ EOF ));
29+ }
30+
31+ /** @test */
32+ public function it_can_serialize_when_given_OS_dependant_line_endings ()
33+ {
34+ $ driver = new TextDriver ();
35+
36+ $ expected = implode ("\n" , [
37+ '' ,
38+ ' GET|HEAD / ..................................................... index ' ,
39+ '' ,
40+ ' Showing [1] routes '
41+ ]);
42+
43+ // Due to using PHP_EOL this should fail (conditionally) when run on windows
44+ $ actual = implode (PHP_EOL , [
45+ '' ,
46+ ' GET|HEAD / ..................................................... index ' ,
47+ '' ,
48+ ' Showing [1] routes '
49+ ]);
50+
51+ $ this ->assertEquals ($ expected , $ driver ->serialize ($ actual ));
52+ }
53+
54+ }
You can’t perform that action at this time.
0 commit comments