16
16
/**
17
17
* Test class for Filesystem.
18
18
*/
19
- class FilesystemTest extends \PHPUnit_Framework_TestCase
19
+ class FilesystemTest extends FilesystemTestCase
20
20
{
21
- /**
22
- * @var string $workspace
23
- */
24
- private $ workspace = null ;
25
-
26
21
/**
27
22
* @var \Symfony\Component\Filesystem\Filesystem $filesystem
28
23
*/
29
24
private $ filesystem = null ;
30
25
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
-
48
26
public function setUp ()
49
27
{
28
+ parent ::setUp ();
50
29
$ 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
- }
76
30
}
77
31
78
32
public function testCopyCreatesNewFile ()
@@ -406,8 +360,8 @@ public function testChmodChangesFileMode()
406
360
$ this ->filesystem ->chmod ($ file , 0400 );
407
361
$ this ->filesystem ->chmod ($ dir , 0753 );
408
362
409
- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ dir) );
410
- $ this ->assertEquals (400 , $ this -> getFilePermissions ( $ file) );
363
+ $ this ->assertFilePermissions (753 , $ dir );
364
+ $ this ->assertFilePermissions (400 , $ file );
411
365
}
412
366
413
367
public function testChmodWrongMod ()
@@ -432,8 +386,8 @@ public function testChmodRecursive()
432
386
$ this ->filesystem ->chmod ($ file , 0400 , 0000 , true );
433
387
$ this ->filesystem ->chmod ($ dir , 0753 , 0000 , true );
434
388
435
- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ dir) );
436
- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ file) );
389
+ $ this ->assertFilePermissions (753 , $ dir );
390
+ $ this ->assertFilePermissions (753 , $ file );
437
391
}
438
392
439
393
public function testChmodAppliesUmask ()
@@ -444,7 +398,7 @@ public function testChmodAppliesUmask()
444
398
touch ($ file );
445
399
446
400
$ this ->filesystem ->chmod ($ file , 0770 , 0022 );
447
- $ this ->assertEquals (750 , $ this -> getFilePermissions ( $ file) );
401
+ $ this ->assertFilePermissions (750 , $ file );
448
402
}
449
403
450
404
public function testChmodChangesModeOfArrayOfFiles ()
@@ -460,8 +414,8 @@ public function testChmodChangesModeOfArrayOfFiles()
460
414
461
415
$ this ->filesystem ->chmod ($ files , 0753 );
462
416
463
- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ file) );
464
- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ directory) );
417
+ $ this ->assertFilePermissions (753 , $ file );
418
+ $ this ->assertFilePermissions (753 , $ directory );
465
419
}
466
420
467
421
public function testChmodChangesModeOfTraversableFileObject ()
@@ -477,8 +431,8 @@ public function testChmodChangesModeOfTraversableFileObject()
477
431
478
432
$ this ->filesystem ->chmod ($ files , 0753 );
479
433
480
- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ file) );
481
- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ directory) );
434
+ $ this ->assertFilePermissions (753 , $ file );
435
+ $ this ->assertFilePermissions (753 , $ directory );
482
436
}
483
437
484
438
public function testChown ()
@@ -908,7 +862,7 @@ public function testDumpFile()
908
862
909
863
// skip mode check on windows
910
864
if (!defined ('PHP_WINDOWS_VERSION_MAJOR ' )) {
911
- $ this ->assertEquals (753 , $ this -> getFilePermissions ( $ filename) );
865
+ $ this ->assertFilePermissions (753 , $ filename );
912
866
}
913
867
}
914
868
@@ -922,61 +876,4 @@ public function testDumpFileOverwritesAnExistingFile()
922
876
$ this ->assertFileExists ($ filename );
923
877
$ this ->assertSame ('bar ' , file_get_contents ($ filename ));
924
878
}
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
- }
982
879
}
0 commit comments