@@ -45,10 +45,6 @@ public function tearDown()
45
45
*/
46
46
private function clean ($ file )
47
47
{
48
- if (!file_exists ($ file )) {
49
- return ;
50
- }
51
-
52
48
if (is_dir ($ file ) && !is_link ($ file )) {
53
49
$ dir = new \FilesystemIterator ($ file );
54
50
foreach ($ dir as $ childFile ) {
@@ -305,4 +301,54 @@ public function testRemoveIgnoresNonExistingFiles()
305
301
306
302
$ this ->assertTrue (!is_dir ($ basePath .'dir ' ));
307
303
}
304
+
305
+ public function testChmodChangesFileMode ()
306
+ {
307
+ $ file = $ this ->workspace .DIRECTORY_SEPARATOR .'file ' ;
308
+ touch ($ file );
309
+
310
+ $ this ->filesystem ->chmod ($ file , 0753 );
311
+
312
+ $ this ->assertEquals (753 , $ this ->getFilePermisions ($ file ));
313
+ }
314
+
315
+ public function testChmodChangesModeOfArrayOfFiles ()
316
+ {
317
+ $ directory = $ this ->workspace .DIRECTORY_SEPARATOR .'directory ' ;
318
+ $ file = $ this ->workspace .DIRECTORY_SEPARATOR .'file ' ;
319
+ $ files = array ($ directory , $ file );
320
+
321
+ mkdir ($ directory );
322
+ touch ($ file );
323
+
324
+ $ this ->filesystem ->chmod ($ files , 0753 );
325
+
326
+ $ this ->assertEquals (753 , $ this ->getFilePermisions ($ file ));
327
+ $ this ->assertEquals (753 , $ this ->getFilePermisions ($ directory ));
328
+ }
329
+
330
+ public function testChmodChangesModeOfTraversableFileObject ()
331
+ {
332
+ $ directory = $ this ->workspace .DIRECTORY_SEPARATOR .'directory ' ;
333
+ $ file = $ this ->workspace .DIRECTORY_SEPARATOR .'file ' ;
334
+ $ files = new \ArrayObject (array ($ directory , $ file ));
335
+
336
+ mkdir ($ directory );
337
+ touch ($ file );
338
+
339
+ $ this ->filesystem ->chmod ($ files , 0753 );
340
+
341
+ $ this ->assertEquals (753 , $ this ->getFilePermisions ($ file ));
342
+ $ this ->assertEquals (753 , $ this ->getFilePermisions ($ directory ));
343
+ }
344
+
345
+ /**
346
+ * Returns file permissions as three digits (i.e. 755)
347
+ *
348
+ * @return integer
349
+ */
350
+ private function getFilePermisions ($ filePath )
351
+ {
352
+ return (int ) substr (sprintf ('%o ' , fileperms ($ filePath )), -3 );
353
+ }
308
354
}
0 commit comments