3
3
namespace Safe ;
4
4
5
5
use PHPUnit \Framework \TestCase ;
6
+ use Safe \Exceptions \FilesystemException ;
6
7
use Safe \Exceptions \PcreException ;
7
8
8
9
class SpecialCasesTest extends TestCase
@@ -18,4 +19,55 @@ public function testPregReplace()
18
19
$ this ->expectExceptionMessage ('PREG_BAD_UTF8_ERROR: Invalid UTF8 character ' );
19
20
preg_replace ("/([\s,]+)/u " , "foo " , "\xc3\x28" );
20
21
}
22
+
23
+ public function testFgetcsvWithTrailingNewline ()
24
+ {
25
+ require_once __DIR__ .'/../../lib/special_cases.php ' ;
26
+ require_once __DIR__ .'/../../lib/Exceptions/SafeExceptionInterface.php ' ;
27
+ require_once __DIR__ .'/../../generated/Exceptions/FilesystemException.php ' ;
28
+
29
+
30
+ if (($ handle = \fopen (__DIR__ ."/csv/test.csv " , "r " )) === false ) {
31
+ throw new \RuntimeException ('Test file could not be opened. ' );
32
+ }
33
+
34
+ while (($ data = fgetcsv ($ handle , 1000 , ", " )) !== false ) {
35
+ $ this ->assertEquals (['test ' , 'test ' ], $ data );
36
+ }
37
+ \fclose ($ handle );
38
+ }
39
+
40
+ public function testFgetcsvReturnFalseonEndOfFile ()
41
+ {
42
+ require_once __DIR__ .'/../../lib/special_cases.php ' ;
43
+ require_once __DIR__ .'/../../lib/Exceptions/SafeExceptionInterface.php ' ;
44
+ require_once __DIR__ .'/../../generated/Exceptions/FilesystemException.php ' ;
45
+
46
+
47
+ if (($ handle = \fopen (__DIR__ ."/csv/test2.csv " , "r " )) === false ) {
48
+ throw new \RuntimeException ('Test file could not be opened. ' );
49
+ }
50
+
51
+ while (($ data = fgetcsv ($ handle , 1000 , ", " )) !== false ) {
52
+ $ this ->assertEquals (['test ' , 'test ' ], $ data );
53
+ }
54
+ $ this ->assertEquals (false , $ data );
55
+ \fclose ($ handle );
56
+ }
57
+
58
+ /*public function testFgetcsvThrowsOnError()
59
+ {
60
+ require_once __DIR__.'/../../lib/special_cases.php';
61
+ require_once __DIR__.'/../../lib/Exceptions/SafeExceptionInterface.php';
62
+ require_once __DIR__.'/../../generated/Exceptions/FilesystemException.php';
63
+
64
+ if (($handle = \fopen(__DIR__."/csv/test3.csv", "r")) === false) {
65
+ throw new \RuntimeException('Test file could not be opened.');
66
+ }
67
+
68
+ $this->expectException(FilesystemException::class);
69
+ while (($data = fgetcsv($handle, 1000, ",")) !== false) {
70
+ echo var_export($data, true);
71
+ }
72
+ }*/
21
73
}
0 commit comments