1616/**
1717 * Test class for Filesystem.
1818 */
19- class FilesystemTest extends \PHPUnit_Framework_TestCase
19+ class FilesystemTest extends FilesystemTestCase
2020{
21- /**
22- * @var string $workspace
23- */
24- private $ workspace = null ;
25-
2621 /**
2722 * @var \Symfony\Component\Filesystem\Filesystem $filesystem
2823 */
2924 private $ filesystem = null ;
3025
31- private static $ symlinkOnWindows = null ;
32-
33- public static function setUpBeforeClass ()
34- {
35- if (defined ('PHP_WINDOWS_VERSION_MAJOR ' )) {
36- self ::$ symlinkOnWindows = true ;
37- $ originDir = tempnam (sys_get_temp_dir (), 'sl ' );
38- $ targetDir = tempnam (sys_get_temp_dir (), 'sl ' );
39- if (true !== @symlink ($ originDir , $ targetDir )) {
40- $ report = error_get_last ();
41- if (is_array ($ report ) && false !== strpos ($ report ['message ' ], 'error code(1314) ' )) {
42- self ::$ symlinkOnWindows = false ;
43- }
44- }
45- }
46- }
47-
4826 public function setUp ()
4927 {
28+ parent ::setUp ();
5029 $ this ->filesystem = new Filesystem ();
51- $ this ->workspace = rtrim (sys_get_temp_dir (), DIRECTORY_SEPARATOR ).DIRECTORY_SEPARATOR .time ().rand (0 , 1000 );
52- mkdir ($ this ->workspace , 0777 , true );
53- $ this ->workspace = realpath ($ this ->workspace );
54- }
55-
56- public function tearDown ()
57- {
58- $ this ->clean ($ this ->workspace );
59- }
60-
61- /**
62- * @param string $file
63- */
64- private function clean ($ file )
65- {
66- if (is_dir ($ file ) && !is_link ($ file )) {
67- $ dir = new \FilesystemIterator ($ file );
68- foreach ($ dir as $ childFile ) {
69- $ this ->clean ($ childFile );
70- }
71-
72- rmdir ($ file );
73- } else {
74- unlink ($ file );
75- }
7630 }
7731
7832 public function testCopyCreatesNewFile ()
@@ -406,8 +360,8 @@ public function testChmodChangesFileMode()
406360 $ this ->filesystem ->chmod ($ file , 0400 );
407361 $ this ->filesystem ->chmod ($ dir , 0753 );
408362
409- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ dir) );
410- $ this ->assertEquals (400 , $ this -> getFilePermissions ( $ file) );
363+ $ this ->assertFilePermissions (753 , $ dir );
364+ $ this ->assertFilePermissions (400 , $ file );
411365 }
412366
413367 public function testChmodWrongMod ()
@@ -432,8 +386,8 @@ public function testChmodRecursive()
432386 $ this ->filesystem ->chmod ($ file , 0400 , 0000 , true );
433387 $ this ->filesystem ->chmod ($ dir , 0753 , 0000 , true );
434388
435- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ dir) );
436- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ file) );
389+ $ this ->assertFilePermissions (753 , $ dir );
390+ $ this ->assertFilePermissions (753 , $ file );
437391 }
438392
439393 public function testChmodAppliesUmask ()
@@ -444,7 +398,7 @@ public function testChmodAppliesUmask()
444398 touch ($ file );
445399
446400 $ this ->filesystem ->chmod ($ file , 0770 , 0022 );
447- $ this ->assertEquals (750 , $ this -> getFilePermissions ( $ file) );
401+ $ this ->assertFilePermissions (750 , $ file );
448402 }
449403
450404 public function testChmodChangesModeOfArrayOfFiles ()
@@ -460,8 +414,8 @@ public function testChmodChangesModeOfArrayOfFiles()
460414
461415 $ this ->filesystem ->chmod ($ files , 0753 );
462416
463- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ file) );
464- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ directory) );
417+ $ this ->assertFilePermissions (753 , $ file );
418+ $ this ->assertFilePermissions (753 , $ directory );
465419 }
466420
467421 public function testChmodChangesModeOfTraversableFileObject ()
@@ -477,8 +431,8 @@ public function testChmodChangesModeOfTraversableFileObject()
477431
478432 $ this ->filesystem ->chmod ($ files , 0753 );
479433
480- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ file) );
481- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ directory) );
434+ $ this ->assertFilePermissions (753 , $ file );
435+ $ this ->assertFilePermissions (753 , $ directory );
482436 }
483437
484438 public function testChown ()
@@ -908,7 +862,7 @@ public function testDumpFile()
908862
909863 // skip mode check on windows
910864 if (!defined ('PHP_WINDOWS_VERSION_MAJOR ' )) {
911- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ filename) );
865+ $ this ->assertFilePermissions (753 , $ filename );
912866 }
913867 }
914868
@@ -922,61 +876,4 @@ public function testDumpFileOverwritesAnExistingFile()
922876 $ this ->assertFileExists ($ filename );
923877 $ this ->assertSame ('bar ' , file_get_contents ($ filename ));
924878 }
925-
926- /**
927- * Returns file permissions as three digits (i.e. 755)
928- *
929- * @param string $filePath
930- *
931- * @return integer
932- */
933- private function getFilePermissions ($ filePath )
934- {
935- return (int ) substr (sprintf ('%o ' , fileperms ($ filePath )), -3 );
936- }
937-
938- private function getFileOwner ($ filepath )
939- {
940- $ this ->markAsSkippedIfPosixIsMissing ();
941-
942- $ infos = stat ($ filepath );
943- if ($ datas = posix_getpwuid ($ infos ['uid ' ])) {
944- return $ datas ['name ' ];
945- }
946- }
947-
948- private function getFileGroup ($ filepath )
949- {
950- $ this ->markAsSkippedIfPosixIsMissing ();
951-
952- $ infos = stat ($ filepath );
953- if ($ datas = posix_getgrgid ($ infos ['gid ' ])) {
954- return $ datas ['name ' ];
955- }
956- }
957-
958- private function markAsSkippedIfSymlinkIsMissing ()
959- {
960- if (!function_exists ('symlink ' )) {
961- $ this ->markTestSkipped ('symlink is not supported ' );
962- }
963-
964- if (defined ('PHP_WINDOWS_VERSION_MAJOR ' ) && false === self ::$ symlinkOnWindows ) {
965- $ this ->markTestSkipped ('symlink requires "Create symbolic links" privilege on windows ' );
966- }
967- }
968-
969- private function markAsSkippedIfChmodIsMissing ()
970- {
971- if (defined ('PHP_WINDOWS_VERSION_MAJOR ' )) {
972- $ this ->markTestSkipped ('chmod is not supported on windows ' );
973- }
974- }
975-
976- private function markAsSkippedIfPosixIsMissing ()
977- {
978- if (defined ('PHP_WINDOWS_VERSION_MAJOR ' ) || !function_exists ('posix_isatty ' )) {
979- $ this ->markTestSkipped ('Posix is not supported ' );
980- }
981- }
982879}
0 commit comments