@@ -42,7 +42,7 @@ class LocalFilesystemTest extends TestCase
42
42
43
43
protected function setUp (): void
44
44
{
45
- $ this ->filesystem = new LocalFilesystem (__DIR__ . ' /tmp/ ' . ( string ) microtime ( true ));
45
+ $ this ->filesystem = new LocalFilesystem ($ this -> getLocation ( ));
46
46
47
47
// Fix test on differrent platforms
48
48
umask (0 );
@@ -116,13 +116,45 @@ public function testGetNotExistingFilePermissions(): void
116
116
$ this ->filesystem ->getPermissions (self ::NOT_EXISTING_FILE_NAME );
117
117
}
118
118
119
- public function testWritingToFileAndDeletingFile (): void
119
+ public function testWritingToFile (): void
120
120
{
121
121
$ this ->filesystem ->writeToFile (self ::FILE_NAME , self ::FILE_CONTENT );
122
122
$ this ->assertTrue ($ this ->filesystem ->fileExists (self ::FILE_NAME ));
123
123
124
+ $ filePath = self ::DIRECTORY_NAME . '/ ' . self ::FILE_NAME ;
125
+ $ this ->filesystem ->writeToFile ($ filePath , self ::FILE_CONTENT );
126
+ $ this ->assertTrue ($ this ->filesystem ->fileExists ($ filePath ));
127
+ }
128
+
129
+ public function testWritingToFileWheDirectoryExists (): void
130
+ {
124
131
$ this ->filesystem ->createDirectory (self ::DIRECTORY_NAME );
125
- $ this ->filesystem ->writeToFile (self ::DIRECTORY_NAME . '/ ' . self ::FILE_NAME , self ::FILE_CONTENT );
132
+
133
+ $ filePath = self ::DIRECTORY_NAME . '/ ' . self ::FILE_NAME ;
134
+ $ this ->filesystem ->writeToFile ($ filePath , self ::FILE_CONTENT );
135
+ $ this ->assertTrue ($ this ->filesystem ->fileExists ($ filePath ));
136
+ }
137
+
138
+ public function testWritingToFileByFilesystemWithCustomPermissions (): void
139
+ {
140
+ $ filesystem = new LocalFilesystem ($ this ->getLocation (), [
141
+ 'defaultPermissions ' => [
142
+ 'directory ' => 0777 ,
143
+ 'file ' => 0666 ,
144
+ ],
145
+ ]);
146
+
147
+ $ filePath = self ::DIRECTORY_NAME . '/ ' . self ::FILE_NAME ;
148
+ $ filesystem ->writeToFile ($ filePath , self ::FILE_CONTENT );
149
+ $ this ->assertTrue ($ filesystem ->fileExists ($ filePath ));
150
+
151
+ $ this ->assertEquals ('0777 ' , LocalFilesystemHelper::filepermsToOctatValue (
152
+ $ filesystem ->getPermissions (self ::DIRECTORY_NAME )
153
+ ));
154
+
155
+ $ this ->assertEquals ('0666 ' , LocalFilesystemHelper::filepermsToOctatValue (
156
+ $ filesystem ->getPermissions (self ::DIRECTORY_NAME . '/ ' . self ::FILE_NAME )
157
+ ));
126
158
}
127
159
128
160
public function testWritingToFileWithPermissions (): void
@@ -326,4 +358,9 @@ public function testDeletingNotExistingDirectoryByFullPath(): void
326
358
$ this ->expectException (LocalFilesystemException::class);
327
359
$ method ->invokeArgs ($ this ->filesystem , [self ::NOT_EXISTING_DIRECTORY_NAME ]);
328
360
}
361
+
362
+ private function getLocation (): string
363
+ {
364
+ return __DIR__ . '/tmp/ ' . (string ) microtime (true );
365
+ }
329
366
}
0 commit comments