File tree 4 files changed +43
-34
lines changed
4 files changed +43
-34
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,14 @@ final class EOLType
8
8
const WINDOWS = "\r\n" ;
9
9
const UNIX = "\n" ;
10
10
11
+ public static function detect (string $ content , string $ default = EOLType::UNIX ): string
12
+ {
13
+ if (str_contains ($ content , EOLType::WINDOWS )) {
14
+ return EOLType::WINDOWS ;
15
+ } elseif (str_contains ($ content , EOLType::UNIX )) {
16
+ return EOLType::UNIX ;
17
+ }
18
+
19
+ return $ default ;
20
+ }
11
21
}
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public function parse(string $content): EnvFile
19
19
20
20
$ file = new EnvFile ();
21
21
22
- $ file ->EOL = $ this ->EOL ?? $ this -> detectEOLType ($ content );
22
+ $ file ->EOL = $ this ->EOL ?? EOLType:: detect ($ content );
23
23
24
24
$ blockStart = "^ " ;
25
25
$ blockEnd = "(?: {$ file ->EOL }|$) " ;
@@ -105,17 +105,4 @@ public function parse(string $content): EnvFile
105
105
106
106
}
107
107
108
- public function detectEOLType (string $ content , string $ default = EOLType::UNIX ): string
109
- {
110
-
111
- if (str_contains ($ content , EOLType::WINDOWS )) {
112
- return EOLType::WINDOWS ;
113
- } elseif (str_contains ($ content , EOLType::UNIX )) {
114
- return EOLType::UNIX ;
115
- }
116
-
117
- return $ default ;
118
-
119
- }
120
-
121
108
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Tests \Unit \EnvFile ;
4
+
5
+ use EnvEditor \EnvFile \EOLType ;
6
+ use Tests \TestCase ;
7
+
8
+ class EOLTypeTest extends TestCase
9
+ {
10
+
11
+ public function testDetectUnix (): void
12
+ {
13
+ $ unix = "#test \n#test " ;
14
+ $ this ->assertEquals (EOLType::UNIX , EOLType::detect ($ unix ));
15
+ }
16
+
17
+ public function testDetectWindows (): void
18
+ {
19
+ $ win = "#test \r\n#test " ;
20
+ $ this ->assertEquals (EOLType::WINDOWS , EOLType::detect ($ win ));
21
+ }
22
+
23
+ public function testDetectDefault (): void
24
+ {
25
+ $ empty = "" ;
26
+ $ this ->assertEquals (EOLType::UNIX , EOLType::detect ($ empty ));
27
+ $ this ->assertEquals (EOLType::UNIX , EOLType::detect ($ empty , EOLType::UNIX ));
28
+ $ this ->assertEquals (EOLType::WINDOWS , EOLType::detect ($ empty , EOLType::WINDOWS ));
29
+ }
30
+
31
+ }
Original file line number Diff line number Diff line change 8
8
9
9
class ParserTest extends TestCase
10
10
{
11
-
12
- public function testDetectEOLType (): void
13
- {
14
- $ parser = new Parser ();
15
-
16
- $ win = "#test \r\n#test " ;
17
- $ unix = "#test \n#test " ;
18
- $ empty = "" ;
19
-
20
- $ this ->assertEquals (EOLType::WINDOWS , $ parser ->detectEOLType ($ win ));
21
- $ this ->assertEquals (EOLType::UNIX , $ parser ->detectEOLType ($ unix ));
22
- $ this ->assertEquals (EOLType::UNIX , $ parser ->detectEOLType ($ empty ));
23
- $ this ->assertEquals (EOLType::UNIX , $ parser ->detectEOLType ($ empty , EOLType::UNIX ));
24
- $ this ->assertEquals (EOLType::WINDOWS , $ parser ->detectEOLType ($ empty , EOLType::WINDOWS ));
25
-
26
- }
27
-
28
- /**
29
- * @depends testDetectEOLType
30
- */
11
+
31
12
public function testFileEOLType (): void
32
13
{
33
14
You can’t perform that action at this time.
0 commit comments