@@ -45,10 +45,6 @@ public function tearDown()
4545 */
4646 private function clean ($ file )
4747 {
48- if (!file_exists ($ file )) {
49- return ;
50- }
51-
5248 if (is_dir ($ file ) && !is_link ($ file )) {
5349 $ dir = new \FilesystemIterator ($ file );
5450 foreach ($ dir as $ childFile ) {
@@ -305,4 +301,54 @@ public function testRemoveIgnoresNonExistingFiles()
305301
306302 $ this ->assertTrue (!is_dir ($ basePath .'dir ' ));
307303 }
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+ }
308354}
0 commit comments