33namespace Safe ;
44
55use PHPUnit \Framework \TestCase ;
6+ use Safe \Exceptions \FilesystemException ;
67use Safe \Exceptions \PcreException ;
78
89class SpecialCasesTest extends TestCase
@@ -18,4 +19,55 @@ public function testPregReplace()
1819 $ this ->expectExceptionMessage ('PREG_BAD_UTF8_ERROR: Invalid UTF8 character ' );
1920 preg_replace ("/([\s,]+)/u " , "foo " , "\xc3\x28" );
2021 }
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+ }*/
2173}
0 commit comments