11
11
12
12
namespace Symfony \Component \Filesystem \Tests ;
13
13
14
- use Phar ;
15
14
/**
16
15
* Test class for Filesystem.
17
16
*/
@@ -953,7 +952,6 @@ public function testTempnam()
953
952
954
953
$ filename = $ this ->filesystem ->tempnam ($ dirname , 'foo ' );
955
954
956
- $ this ->assertNotFalse ($ filename );
957
955
$ this ->assertFileExists ($ filename );
958
956
}
959
957
@@ -964,39 +962,34 @@ public function testTempnamWithFileScheme()
964
962
965
963
$ filename = $ this ->filesystem ->tempnam ($ dirname , 'foo ' );
966
964
967
- $ this ->assertNotFalse ($ filename );
968
965
$ this ->assertStringStartsWith ($ scheme , $ filename );
969
966
$ this ->assertFileExists ($ filename );
970
967
}
971
968
972
969
public function testTempnamWithMockScheme ()
973
970
{
974
- // We avoid autoloading via ClassLoader as stream_wrapper_register creates the object
975
- if (!@include __DIR__ .DIRECTORY_SEPARATOR .'Fixtures ' .DIRECTORY_SEPARATOR .'MockStream ' .DIRECTORY_SEPARATOR .'MockStream.php ' ) {
976
- $ this ->markTestSkipped ('Unable to load mock:// stream. ' );
977
- }
978
-
979
- stream_wrapper_register ('mock ' , 'MockStream\MockStream ' );
971
+ stream_wrapper_register ('mock ' , 'Symfony\Component\Filesystem\Tests\Fixtures\MockStream\MockStream ' );
980
972
981
973
$ scheme = 'mock:// ' ;
982
974
$ dirname = $ scheme .$ this ->workspace ;
983
975
984
976
$ filename = $ this ->filesystem ->tempnam ($ dirname , 'foo ' );
985
977
986
- $ this ->assertNotFalse ($ filename );
987
978
$ this ->assertStringStartsWith ($ scheme , $ filename );
988
979
$ this ->assertFileExists ($ filename );
989
980
}
990
981
982
+ /**
983
+ * @expectedException \Symfony\Component\Filesystem\Exception\IOException
984
+ */
991
985
public function testTempnamWithZlibSchemeFails ()
992
986
{
993
987
$ scheme = 'compress.zlib:// ' ;
994
988
$ dirname = $ scheme .$ this ->workspace ;
995
989
996
- $ filename = $ this ->filesystem ->tempnam ($ dirname , 'bar ' );
997
-
998
990
// The compress.zlib:// stream does not support mode x: creates the file, errors "failed to open stream: operation failed" and returns false
999
- $ this ->assertFalse ($ filename );
991
+ $ this ->filesystem ->tempnam ($ dirname , 'bar ' );
992
+
1000
993
}
1001
994
1002
995
public function testTempnamWithPHPTempSchemeFails ()
@@ -1006,40 +999,41 @@ public function testTempnamWithPHPTempSchemeFails()
1006
999
1007
1000
$ filename = $ this ->filesystem ->tempnam ($ dirname , 'bar ' );
1008
1001
1009
- $ this ->assertNotFalse ($ filename );
1010
1002
$ this ->assertStringStartsWith ($ scheme , $ filename );
1011
1003
1012
1004
// The php://temp stream deletes the file after close
1013
1005
$ this ->assertFileNotExists ($ filename );
1014
1006
}
1015
1007
1008
+ /**
1009
+ * @expectedException \Symfony\Component\Filesystem\Exception\IOException
1010
+ */
1016
1011
public function testTempnamWithPharSchemeFails ()
1017
1012
{
1018
1013
// Skip test if Phar disabled phar.readonly must be 0 in php.ini
1019
- if (!Phar::canWrite ()) {
1014
+ if (!\ Phar::canWrite ()) {
1020
1015
$ this ->markTestSkipped ('This test cannot run when phar.readonly is 1. ' );
1021
1016
}
1022
1017
1023
1018
$ scheme = 'phar:// ' ;
1024
1019
$ dirname = $ scheme .$ this ->workspace ;
1025
1020
$ pharname = 'foo.phar ' ;
1026
1021
1027
- $ p = new Phar ($ this ->workspace .'/ ' .$ pharname , 0 , $ pharname );
1028
- $ filename = $ this ->filesystem ->tempnam ($ dirname , $ pharname .'/bar ' );
1029
-
1022
+ new \Phar ($ this ->workspace .'/ ' .$ pharname , 0 , $ pharname );
1030
1023
// The phar:// stream does not support mode x: fails to create file, errors "failed to open stream: phar error: "$filename" is not a file in phar "$pharname"" and returns false
1031
- $ this ->assertFalse ( $ filename );
1024
+ $ this ->filesystem -> tempnam ( $ dirname , $ pharname . ' /bar ' );
1032
1025
}
1033
1026
1027
+ /**
1028
+ * @expectedException \Symfony\Component\Filesystem\Exception\IOException
1029
+ */
1034
1030
public function testTempnamWithHTTPSchemeFails ()
1035
1031
{
1036
1032
$ scheme = 'http:// ' ;
1037
1033
$ dirname = $ scheme .$ this ->workspace ;
1038
1034
1039
- $ filename = $ this ->filesystem ->tempnam ($ dirname , 'bar ' );
1040
-
1041
1035
// The http:// scheme is read-only
1042
- $ this ->assertFalse ( $ filename );
1036
+ $ this ->filesystem -> tempnam ( $ dirname , ' bar ' );
1043
1037
}
1044
1038
1045
1039
public function testTempnamOnUnwritableFallsBackToSysTmp ()
@@ -1049,7 +1043,6 @@ public function testTempnamOnUnwritableFallsBackToSysTmp()
1049
1043
1050
1044
$ filename = $ this ->filesystem ->tempnam ($ dirname , 'bar ' );
1051
1045
1052
- $ this ->assertNotFalse ($ filename );
1053
1046
$ this ->assertStringStartsWith (rtrim ($ scheme .sys_get_temp_dir (), DIRECTORY_SEPARATOR ), $ filename );
1054
1047
$ this ->assertFileExists ($ filename );
1055
1048
0 commit comments