@@ -59,21 +59,28 @@ public function testLines()
59
59
{
60
60
$ path = self ::$ tempDir .'/file.txt ' ;
61
61
62
- $ contents = LazyCollection::times (3 )
63
- ->map (function ($ number ) {
64
- return "line- {$ number }" ;
65
- })
66
- ->join ("\n" );
67
-
62
+ $ contents = ' ' .PHP_EOL .' spaces around ' .PHP_EOL .PHP_EOL .'Line 2 ' .PHP_EOL .'1 trailing empty line -> ' .PHP_EOL .PHP_EOL ;
68
63
file_put_contents ($ path , $ contents );
69
64
70
65
$ files = new Filesystem ;
71
66
$ this ->assertInstanceOf (LazyCollection::class, $ files ->lines ($ path ));
72
67
73
68
$ this ->assertSame (
74
- ['line-1 ' , 'line- 2 ' , 'line-3 ' ],
69
+ [' ' , ' spaces around ' , '' , ' Line 2 ' , '1 trailing empty line -> ' , '' , ' ' ],
75
70
$ files ->lines ($ path )->all ()
76
71
);
72
+
73
+ // an empty file:
74
+ ftruncate (fopen ($ path , 'w ' ), 0 );
75
+ $ this ->assertSame (['' ], $ files ->lines ($ path )->all ());
76
+ }
77
+
78
+ public function testLinesThrowsExceptionNonexisitingFile ()
79
+ {
80
+ $ this ->expectException (FileNotFoundException::class);
81
+ $ this ->expectExceptionMessage ('File does not exist at path ' .__DIR__ .'/unknown-file.txt. ' );
82
+
83
+ (new Filesystem )->lines (__DIR__ .'/unknown-file.txt ' );
77
84
}
78
85
79
86
public function testReplaceCreatesFile ()
@@ -324,9 +331,9 @@ public function testMoveDirectoryReturnsFalseWhileOverwritingAndUnableToDeleteDe
324
331
public function testGetThrowsExceptionNonexisitingFile ()
325
332
{
326
333
$ this ->expectException (FileNotFoundException::class);
334
+ $ this ->expectExceptionMessage ('File does not exist at path ' .self ::$ tempDir .'/unknown-file.txt. ' );
327
335
328
- $ files = new Filesystem ;
329
- $ files ->get (self ::$ tempDir .'/unknown-file.txt ' );
336
+ (new Filesystem )->get (self ::$ tempDir .'/unknown-file.txt ' );
330
337
}
331
338
332
339
public function testGetRequireReturnsProperly ()
@@ -339,9 +346,9 @@ public function testGetRequireReturnsProperly()
339
346
public function testGetRequireThrowsExceptionNonExistingFile ()
340
347
{
341
348
$ this ->expectException (FileNotFoundException::class);
349
+ $ this ->expectExceptionMessage ('File does not exist at path ' .self ::$ tempDir .'/unknown-file.txt. ' );
342
350
343
- $ files = new Filesystem ;
344
- $ files ->getRequire (self ::$ tempDir .'/file.php ' );
351
+ (new Filesystem )->getRequire (self ::$ tempDir .'/unknown-file.txt ' );
345
352
}
346
353
347
354
public function testJsonReturnsDecodedJsonData ()
@@ -564,6 +571,14 @@ public function testRequireOnceRequiresFileProperly()
564
571
$ this ->assertFalse (function_exists ('random_function_xyz_changed ' ));
565
572
}
566
573
574
+ public function testRequireOnceThrowsExceptionNonexisitingFile ()
575
+ {
576
+ $ this ->expectException (FileNotFoundException::class);
577
+ $ this ->expectExceptionMessage ('File does not exist at path ' .__DIR__ .'/unknown-file.txt. ' );
578
+
579
+ (new Filesystem )->requireOnce (__DIR__ .'/unknown-file.txt ' );
580
+ }
581
+
567
582
public function testCopyCopiesFileProperly ()
568
583
{
569
584
$ filesystem = new Filesystem ;
0 commit comments