@@ -47,8 +47,8 @@ public function testUploadFileFromAllowedFolder(): void
47
47
$ fileName = 'text.txt ' ;
48
48
$ tmpDir = 'tmp ' ;
49
49
$ filePath = $ tmpDirectory ->getAbsolutePath ($ fileName );
50
- $ file = fopen ( $ filePath , " wb " );
51
- fwrite ( $ file , 'just a text ' );
50
+
51
+ $ tmpDirectory -> writeFile ( $ fileName , 'just a text ' );
52
52
53
53
$ type = [
54
54
'tmp_name ' => $ filePath ,
@@ -58,7 +58,7 @@ public function testUploadFileFromAllowedFolder(): void
58
58
$ uploader = $ this ->uploaderFactory ->create (['fileId ' => $ type ]);
59
59
$ uploader ->save ($ mediaDirectory ->getAbsolutePath ($ tmpDir ));
60
60
61
- $ this ->assertTrue (is_file ( $ mediaDirectory ->getAbsolutePath ($ tmpDir . DIRECTORY_SEPARATOR . $ fileName) ));
61
+ $ this ->assertTrue ($ mediaDirectory ->isFile ($ tmpDir . DIRECTORY_SEPARATOR . $ fileName ));
62
62
}
63
63
64
64
/**
@@ -72,13 +72,9 @@ public function testUploadFileFromNotAllowedFolder(): void
72
72
$ fileName = 'text.txt ' ;
73
73
$ tmpDir = 'tmp ' ;
74
74
$ tmpDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::LOG );
75
- $ directoryPath = $ tmpDirectory ->getAbsolutePath () . $ tmpDir ;
76
- if (!is_dir ($ directoryPath )) {
77
- mkdir ($ directoryPath , 0777 , true );
78
- }
79
- $ filePath = $ directoryPath . DIRECTORY_SEPARATOR . $ fileName ;
80
- $ file = fopen ($ filePath , "wb " );
81
- fwrite ($ file , 'just a text ' );
75
+ $ filePath = $ tmpDirectory ->getAbsolutePath () . $ tmpDir . DIRECTORY_SEPARATOR . $ fileName ;
76
+
77
+ $ tmpDirectory ->writeFile ($ tmpDir . DIRECTORY_SEPARATOR . $ fileName , 'just a text ' );
82
78
83
79
$ type = [
84
80
'tmp_name ' => $ filePath ,
@@ -91,15 +87,17 @@ public function testUploadFileFromNotAllowedFolder(): void
91
87
/**
92
88
* @inheritdoc
93
89
*/
94
- protected function tearDown ()
90
+ public static function tearDownAfterClass ()
95
91
{
96
- parent ::tearDown ();
92
+ parent ::tearDownAfterClass ();
93
+ $ filesystem = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
94
+ ->get (\Magento \Framework \Filesystem::class);
97
95
98
96
$ tmpDir = 'tmp ' ;
99
- $ mediaDirectory = $ this -> filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
97
+ $ mediaDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
100
98
$ mediaDirectory ->delete ($ tmpDir );
101
99
102
- $ logDirectory = $ this -> filesystem ->getDirectoryWrite (DirectoryList::LOG );
100
+ $ logDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::LOG );
103
101
$ logDirectory ->delete ($ tmpDir );
104
102
}
105
103
}
0 commit comments