1111
1212namespace Symfony \Component \Filesystem \Tests ;
1313
14+ use Symfony \Bridge \PhpUnit \ForwardCompatTestTrait ;
15+
1416/**
1517 * Test class for Filesystem.
1618 */
1719class FilesystemTest extends FilesystemTestCase
1820{
21+ use ForwardCompatTestTrait;
22+
1923 public function testCopyCreatesNewFile ()
2024 {
2125 $ sourceFilePath = $ this ->workspace .\DIRECTORY_SEPARATOR .'copy_source_file ' ;
@@ -29,22 +33,18 @@ public function testCopyCreatesNewFile()
2933 $ this ->assertStringEqualsFile ($ targetFilePath , 'SOURCE FILE ' );
3034 }
3135
32- /**
33- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
34- */
3536 public function testCopyFails ()
3637 {
38+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
3739 $ sourceFilePath = $ this ->workspace .\DIRECTORY_SEPARATOR .'copy_source_file ' ;
3840 $ targetFilePath = $ this ->workspace .\DIRECTORY_SEPARATOR .'copy_target_file ' ;
3941
4042 $ this ->filesystem ->copy ($ sourceFilePath , $ targetFilePath );
4143 }
4244
43- /**
44- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
45- */
4645 public function testCopyUnreadableFileFails ()
4746 {
47+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
4848 // skip test on Windows; PHP can't easily set file as unreadable on Windows
4949 if ('\\' === \DIRECTORY_SEPARATOR ) {
5050 $ this ->markTestSkipped ('This test cannot run on Windows. ' );
@@ -118,11 +118,9 @@ public function testCopyOverridesExistingFileIfForced()
118118 $ this ->assertStringEqualsFile ($ targetFilePath , 'SOURCE FILE ' );
119119 }
120120
121- /**
122- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
123- */
124121 public function testCopyWithOverrideWithReadOnlyTargetFails ()
125122 {
123+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
126124 // skip test on Windows; PHP can't easily set file as unwritable on Windows
127125 if ('\\' === \DIRECTORY_SEPARATOR ) {
128126 $ this ->markTestSkipped ('This test cannot run on Windows. ' );
@@ -222,11 +220,9 @@ public function testMkdirCreatesDirectoriesFromTraversableObject()
222220 $ this ->assertTrue (is_dir ($ basePath .'3 ' ));
223221 }
224222
225- /**
226- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
227- */
228223 public function testMkdirCreatesDirectoriesFails ()
229224 {
225+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
230226 $ basePath = $ this ->workspace .\DIRECTORY_SEPARATOR ;
231227 $ dir = $ basePath .'2 ' ;
232228
@@ -244,11 +240,9 @@ public function testTouchCreatesEmptyFile()
244240 $ this ->assertFileExists ($ file );
245241 }
246242
247- /**
248- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
249- */
250243 public function testTouchFails ()
251244 {
245+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
252246 $ file = $ this ->workspace .\DIRECTORY_SEPARATOR .'1 ' .\DIRECTORY_SEPARATOR .'2 ' ;
253247
254248 $ this ->filesystem ->touch ($ file );
@@ -380,11 +374,9 @@ public function testFilesExists()
380374 $ this ->assertTrue ($ this ->filesystem ->exists ($ basePath .'folder ' ));
381375 }
382376
383- /**
384- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
385- */
386377 public function testFilesExistsFails ()
387378 {
379+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
388380 if ('\\' !== \DIRECTORY_SEPARATOR ) {
389381 $ this ->markTestSkipped ('Long file names are an issue on Windows ' );
390382 }
@@ -609,11 +601,9 @@ public function testChownLink()
609601 $ this ->assertSame ($ owner , $ this ->getFileOwner ($ link ));
610602 }
611603
612- /**
613- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
614- */
615604 public function testChownSymlinkFails ()
616605 {
606+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
617607 $ this ->markAsSkippedIfSymlinkIsMissing ();
618608
619609 $ file = $ this ->workspace .\DIRECTORY_SEPARATOR .'file ' ;
@@ -626,11 +616,9 @@ public function testChownSymlinkFails()
626616 $ this ->filesystem ->chown ($ link , 'user ' .time ().mt_rand (1000 , 9999 ));
627617 }
628618
629- /**
630- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
631- */
632619 public function testChownLinkFails ()
633620 {
621+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
634622 $ this ->markAsSkippedIfLinkIsMissing ();
635623
636624 $ file = $ this ->workspace .\DIRECTORY_SEPARATOR .'file ' ;
@@ -643,11 +631,9 @@ public function testChownLinkFails()
643631 $ this ->filesystem ->chown ($ link , 'user ' .time ().mt_rand (1000 , 9999 ));
644632 }
645633
646- /**
647- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
648- */
649634 public function testChownFail ()
650635 {
636+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
651637 $ this ->markAsSkippedIfPosixIsMissing ();
652638
653639 $ dir = $ this ->workspace .\DIRECTORY_SEPARATOR .'dir ' ;
@@ -718,11 +704,9 @@ public function testChgrpLink()
718704 $ this ->assertSame ($ group , $ this ->getFileGroup ($ link ));
719705 }
720706
721- /**
722- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
723- */
724707 public function testChgrpSymlinkFails ()
725708 {
709+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
726710 $ this ->markAsSkippedIfSymlinkIsMissing ();
727711
728712 $ file = $ this ->workspace .\DIRECTORY_SEPARATOR .'file ' ;
@@ -735,11 +719,9 @@ public function testChgrpSymlinkFails()
735719 $ this ->filesystem ->chgrp ($ link , 'user ' .time ().mt_rand (1000 , 9999 ));
736720 }
737721
738- /**
739- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
740- */
741722 public function testChgrpLinkFails ()
742723 {
724+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
743725 $ this ->markAsSkippedIfLinkIsMissing ();
744726
745727 $ file = $ this ->workspace .\DIRECTORY_SEPARATOR .'file ' ;
@@ -752,11 +734,9 @@ public function testChgrpLinkFails()
752734 $ this ->filesystem ->chgrp ($ link , 'user ' .time ().mt_rand (1000 , 9999 ));
753735 }
754736
755- /**
756- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
757- */
758737 public function testChgrpFail ()
759738 {
739+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
760740 $ this ->markAsSkippedIfPosixIsMissing ();
761741
762742 $ dir = $ this ->workspace .\DIRECTORY_SEPARATOR .'dir ' ;
@@ -777,11 +757,9 @@ public function testRename()
777757 $ this ->assertFileExists ($ newPath );
778758 }
779759
780- /**
781- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
782- */
783760 public function testRenameThrowsExceptionIfTargetAlreadyExists ()
784761 {
762+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
785763 $ file = $ this ->workspace .\DIRECTORY_SEPARATOR .'file ' ;
786764 $ newPath = $ this ->workspace .\DIRECTORY_SEPARATOR .'new_file ' ;
787765
@@ -805,11 +783,9 @@ public function testRenameOverwritesTheTargetIfItAlreadyExists()
805783 $ this ->assertFileExists ($ newPath );
806784 }
807785
808- /**
809- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
810- */
811786 public function testRenameThrowsExceptionOnError ()
812787 {
788+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
813789 $ file = $ this ->workspace .\DIRECTORY_SEPARATOR .uniqid ('fs_test_ ' , true );
814790 $ newPath = $ this ->workspace .\DIRECTORY_SEPARATOR .'new_file ' ;
815791
@@ -1148,21 +1124,17 @@ public function providePathsForMakePathRelative()
11481124 return $ paths ;
11491125 }
11501126
1151- /**
1152- * @expectedException \Symfony\Component\Filesystem\Exception\InvalidArgumentException
1153- * @expectedExceptionMessage The start path "var/lib/symfony/src/Symfony/Component" is not absolute.
1154- */
11551127 public function testMakePathRelativeWithRelativeStartPath ()
11561128 {
1129+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\InvalidArgumentException ' );
1130+ $ this ->expectExceptionMessage ('The start path "var/lib/symfony/src/Symfony/Component" is not absolute. ' );
11571131 $ this ->assertSame ('../../../ ' , $ this ->filesystem ->makePathRelative ('/var/lib/symfony/ ' , 'var/lib/symfony/src/Symfony/Component ' ));
11581132 }
11591133
1160- /**
1161- * @expectedException \Symfony\Component\Filesystem\Exception\InvalidArgumentException
1162- * @expectedExceptionMessage The end path "var/lib/symfony/" is not absolute.
1163- */
11641134 public function testMakePathRelativeWithRelativeEndPath ()
11651135 {
1136+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\InvalidArgumentException ' );
1137+ $ this ->expectExceptionMessage ('The end path "var/lib/symfony/" is not absolute. ' );
11661138 $ this ->assertSame ('../../../ ' , $ this ->filesystem ->makePathRelative ('var/lib/symfony/ ' , '/var/lib/symfony/src/Symfony/Component ' ));
11671139 }
11681140
@@ -1434,11 +1406,9 @@ public function testTempnamWithMockScheme()
14341406 $ this ->assertFileExists ($ filename );
14351407 }
14361408
1437- /**
1438- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
1439- */
14401409 public function testTempnamWithZlibSchemeFails ()
14411410 {
1411+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
14421412 $ scheme = 'compress.zlib:// ' ;
14431413 $ dirname = $ scheme .$ this ->workspace ;
14441414
@@ -1459,11 +1429,9 @@ public function testTempnamWithPHPTempSchemeFails()
14591429 $ this ->assertFileNotExists ($ filename );
14601430 }
14611431
1462- /**
1463- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
1464- */
14651432 public function testTempnamWithPharSchemeFails ()
14661433 {
1434+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
14671435 // Skip test if Phar disabled phar.readonly must be 0 in php.ini
14681436 if (!\Phar::canWrite ()) {
14691437 $ this ->markTestSkipped ('This test cannot run when phar.readonly is 1. ' );
@@ -1478,11 +1446,9 @@ public function testTempnamWithPharSchemeFails()
14781446 $ this ->filesystem ->tempnam ($ dirname , $ pharname .'/bar ' );
14791447 }
14801448
1481- /**
1482- * @expectedException \Symfony\Component\Filesystem\Exception\IOException
1483- */
14841449 public function testTempnamWithHTTPSchemeFails ()
14851450 {
1451+ $ this ->expectException ('Symfony\Component\Filesystem\Exception\IOException ' );
14861452 $ scheme = 'http:// ' ;
14871453 $ dirname = $ scheme .$ this ->workspace ;
14881454
0 commit comments