7
7
*/
8
8
namespace Magento \Framework \Filesystem \Directory ;
9
9
10
+ use Magento \Framework \Exception \FileSystemException ;
10
11
use Magento \Framework \Exception \ValidatorException ;
11
12
use Magento \Framework \Filesystem \DriverPool ;
12
13
use Magento \TestFramework \Helper \Bootstrap ;
14
+ use PHPUnit \Framework \TestCase ;
13
15
14
16
/**
15
17
* Class ReadTest
16
18
* Test for Magento\Framework\Filesystem\Directory\Read class
17
19
*/
18
- class WriteTest extends \ PHPUnit \ Framework \ TestCase
20
+ class WriteTest extends TestCase
19
21
{
20
22
/**
21
23
* Test data to be cleaned
@@ -41,6 +43,8 @@ public function testInstance()
41
43
* @param string $basePath
42
44
* @param int $permissions
43
45
* @param string $path
46
+ * @throws FileSystemException
47
+ * @throws ValidatorException
44
48
*/
45
49
public function testCreate ($ basePath , $ permissions , $ path )
46
50
{
@@ -64,6 +68,11 @@ public function createProvider()
64
68
];
65
69
}
66
70
71
+ /**
72
+ * Test for create outside
73
+ *
74
+ * @throws FileSystemException
75
+ */
67
76
public function testCreateOutside ()
68
77
{
69
78
$ exceptions = 0 ;
@@ -91,6 +100,8 @@ public function testCreateOutside()
91
100
*
92
101
* @dataProvider deleteProvider
93
102
* @param string $path
103
+ * @throws FileSystemException
104
+ * @throws ValidatorException
94
105
*/
95
106
public function testDelete ($ path )
96
107
{
@@ -111,6 +122,11 @@ public function deleteProvider()
111
122
return [['subdir ' ], ['subdir/subsubdir ' ]];
112
123
}
113
124
125
+ /**
126
+ * Test for delete outside
127
+ *
128
+ * @throws FileSystemException
129
+ */
114
130
public function testDeleteOutside ()
115
131
{
116
132
$ exceptions = 0 ;
@@ -141,6 +157,8 @@ public function testDeleteOutside()
141
157
* @param int $permissions
142
158
* @param string $name
143
159
* @param string $newName
160
+ * @throws FileSystemException
161
+ * @throws ValidatorException
144
162
*/
145
163
public function testRename ($ basePath , $ permissions , $ name , $ newName )
146
164
{
@@ -164,6 +182,11 @@ public function renameProvider()
164
182
return [['newDir1 ' , 0777 , 'first_name.txt ' , 'second_name.txt ' ]];
165
183
}
166
184
185
+ /**
186
+ * Test for rename outside
187
+ *
188
+ * @throws FileSystemException
189
+ */
167
190
public function testRenameOutside ()
168
191
{
169
192
$ exceptions = 0 ;
@@ -198,6 +221,8 @@ public function testRenameOutside()
198
221
* @param int $permission
199
222
* @param string $name
200
223
* @param string $newName
224
+ * @throws FileSystemException
225
+ * @throws ValidatorException
201
226
*/
202
227
public function testRenameTargetDir ($ firstDir , $ secondDir , $ permission , $ name , $ newName )
203
228
{
@@ -231,6 +256,8 @@ public function renameTargetDirProvider()
231
256
* @param int $permissions
232
257
* @param string $name
233
258
* @param string $newName
259
+ * @throws ValidatorException
260
+ * @throws FileSystemException
234
261
*/
235
262
public function testCopy ($ basePath , $ permissions , $ name , $ newName )
236
263
{
@@ -255,6 +282,11 @@ public function copyProvider()
255
282
];
256
283
}
257
284
285
+ /**
286
+ * Test for copy outside
287
+ *
288
+ * @throws FileSystemException|ValidatorException
289
+ */
258
290
public function testCopyOutside ()
259
291
{
260
292
$ exceptions = 0 ;
@@ -298,6 +330,8 @@ public function testCopyOutside()
298
330
* @param int $permission
299
331
* @param string $name
300
332
* @param string $newName
333
+ * @throws FileSystemException
334
+ * @throws ValidatorException
301
335
*/
302
336
public function testCopyTargetDir ($ firstDir , $ secondDir , $ permission , $ name , $ newName )
303
337
{
@@ -327,6 +361,8 @@ public function copyTargetDirProvider()
327
361
328
362
/**
329
363
* Test for changePermissions method
364
+ *
365
+ * @throws FileSystemException|ValidatorException
330
366
*/
331
367
public function testChangePermissions ()
332
368
{
@@ -335,6 +371,11 @@ public function testChangePermissions()
335
371
$ this ->assertTrue ($ directory ->changePermissions ('test_directory ' , 0644 ));
336
372
}
337
373
374
+ /**
375
+ * Test for changePermissions outside
376
+ *
377
+ * @throws FileSystemException
378
+ */
338
379
public function testChangePermissionsOutside ()
339
380
{
340
381
$ exceptions = 0 ;
@@ -359,6 +400,8 @@ public function testChangePermissionsOutside()
359
400
360
401
/**
361
402
* Test for changePermissionsRecursively method
403
+ *
404
+ * @throws FileSystemException|ValidatorException
362
405
*/
363
406
public function testChangePermissionsRecursively ()
364
407
{
@@ -370,6 +413,11 @@ public function testChangePermissionsRecursively()
370
413
$ this ->assertTrue ($ directory ->changePermissionsRecursively ('test_directory ' , 0777 , 0644 ));
371
414
}
372
415
416
+ /**
417
+ * Test for changePermissionsRecursively outside
418
+ *
419
+ * @throws FileSystemException
420
+ */
373
421
public function testChangePermissionsRecursivelyOutside ()
374
422
{
375
423
$ exceptions = 0 ;
@@ -400,6 +448,8 @@ public function testChangePermissionsRecursivelyOutside()
400
448
* @param int $permissions
401
449
* @param string $path
402
450
* @param int $time
451
+ * @throws FileSystemException
452
+ * @throws ValidatorException
403
453
*/
404
454
public function testTouch ($ basePath , $ permissions , $ path , $ time )
405
455
{
@@ -422,6 +472,11 @@ public function touchProvider()
422
472
];
423
473
}
424
474
475
+ /**
476
+ * Test for touch outside
477
+ *
478
+ * @throws FileSystemException
479
+ */
425
480
public function testTouchOutside ()
426
481
{
427
482
$ exceptions = 0 ;
@@ -446,6 +501,8 @@ public function testTouchOutside()
446
501
447
502
/**
448
503
* Test isWritable method
504
+ *
505
+ * @throws FileSystemException|ValidatorException
449
506
*/
450
507
public function testIsWritable ()
451
508
{
@@ -455,6 +512,11 @@ public function testIsWritable()
455
512
$ this ->assertTrue ($ directory ->isWritable ('bar ' ));
456
513
}
457
514
515
+ /**
516
+ * Test isWritable method outside
517
+ *
518
+ * @throws FileSystemException
519
+ */
458
520
public function testIsWritableOutside ()
459
521
{
460
522
$ exceptions = 0 ;
@@ -485,6 +547,8 @@ public function testIsWritableOutside()
485
547
* @param int $permissions
486
548
* @param string $path
487
549
* @param string $mode
550
+ * @throws FileSystemException
551
+ * @throws ValidatorException
488
552
*/
489
553
public function testOpenFile ($ basePath , $ permissions , $ path , $ mode )
490
554
{
@@ -507,6 +571,11 @@ public function openFileProvider()
507
571
];
508
572
}
509
573
574
+ /**
575
+ * Test for openFile outside
576
+ *
577
+ * @throws FileSystemException
578
+ */
510
579
public function testOpenFileOutside ()
511
580
{
512
581
$ exceptions = 0 ;
@@ -536,6 +605,8 @@ public function testOpenFileOutside()
536
605
* @param string $path
537
606
* @param string $content
538
607
* @param string $extraContent
608
+ * @throws FileSystemException
609
+ * @throws ValidatorException
539
610
*/
540
611
public function testWriteFile ($ path , $ content , $ extraContent )
541
612
{
@@ -553,6 +624,8 @@ public function testWriteFile($path, $content, $extraContent)
553
624
* @param string $path
554
625
* @param string $content
555
626
* @param string $extraContent
627
+ * @throws FileSystemException
628
+ * @throws ValidatorException
556
629
*/
557
630
public function testWriteFileAppend ($ path , $ content , $ extraContent )
558
631
{
@@ -573,6 +646,11 @@ public function writeFileProvider()
573
646
return [['file1 ' , '123 ' , '456 ' ], ['folder1/file1 ' , '123 ' , '456 ' ]];
574
647
}
575
648
649
+ /**
650
+ * Test for writeFile outside
651
+ *
652
+ * @throws FileSystemException
653
+ */
576
654
public function testWriteFileOutside ()
577
655
{
578
656
$ exceptions = 0 ;
@@ -595,8 +673,24 @@ public function testWriteFileOutside()
595
673
$ this ->assertEquals (3 , $ exceptions );
596
674
}
597
675
676
+ /**
677
+ * Test for invalidDeletePath
678
+ *
679
+ * @throws ValidatorException
680
+ */
681
+ public function testInvalidDeletePath ()
682
+ {
683
+ $ this ->expectException (FileSystemException::class);
684
+ $ directory = $ this ->getDirectoryInstance ('newDir ' , 0777 );
685
+ $ invalidPath = 'invalidPath/../ ' ;
686
+ $ directory ->create ($ invalidPath );
687
+ $ directory ->delete ($ invalidPath );
688
+ }
689
+
598
690
/**
599
691
* Tear down
692
+ *
693
+ * @throws ValidatorException|FileSystemException
600
694
*/
601
695
protected function tearDown (): void
602
696
{
@@ -620,8 +714,8 @@ private function getDirectoryInstance($path, $permissions)
620
714
{
621
715
$ fullPath = __DIR__ . '/../_files/ ' . $ path ;
622
716
$ objectManager = Bootstrap::getObjectManager ();
623
- /** @var \Magento\Framework\Filesystem\Directory\ WriteFactory $directoryFactory */
624
- $ directoryFactory = $ objectManager ->create (\ Magento \ Framework \ Filesystem \ Directory \ WriteFactory::class);
717
+ /** @var WriteFactory $directoryFactory */
718
+ $ directoryFactory = $ objectManager ->create (WriteFactory::class);
625
719
$ directory = $ directoryFactory ->create ($ fullPath , DriverPool::FILE , $ permissions );
626
720
$ this ->testDirectories [] = $ directory ;
627
721
return $ directory ;
0 commit comments