@@ -25,7 +25,7 @@ class RemotePackageStorageTest extends TestCase
25
25
protected function setUp (): void
26
26
{
27
27
$ this ->filesystem = new Filesystem ();
28
- if (!file_exists (self ::$ writableRoot )) {
28
+ if (!$ this -> filesystem -> exists (self ::$ writableRoot )) {
29
29
$ this ->filesystem ->mkdir (self ::$ writableRoot );
30
30
}
31
31
}
@@ -41,14 +41,30 @@ public function testGetStorageDir()
41
41
$ this ->assertSame (realpath (self ::$ writableRoot .'/assets/vendor ' ), realpath ($ storage ->getStorageDir ()));
42
42
}
43
43
44
+ public function testSaveThrowsWhenVendorDirectoryIsNotWritable ()
45
+ {
46
+ $ this ->filesystem ->mkdir ($ vendorDir = self ::$ writableRoot .'/assets/acme/vendor ' );
47
+ $ this ->filesystem ->chmod ($ vendorDir , 0555 );
48
+
49
+ $ storage = new RemotePackageStorage ($ vendorDir );
50
+ $ entry = ImportMapEntry::createRemote ('foo ' , ImportMapType::JS , '/does/not/matter ' , '1.0.0 ' , 'module_specifier ' , false );
51
+
52
+ $ this ->expectException (\RuntimeException::class);
53
+ $ this ->expectExceptionMessage ('file_put_contents( ' .$ vendorDir .'/module_specifier/module_specifier.index.js): Failed to open stream: No such file or directory ' );
54
+ $ storage ->save ($ entry , 'any content ' );
55
+
56
+ $ this ->filesystem ->remove ($ vendorDir );
57
+ }
58
+
44
59
public function testIsDownloaded ()
45
60
{
46
61
$ storage = new RemotePackageStorage (self ::$ writableRoot .'/assets/vendor ' );
47
62
$ entry = ImportMapEntry::createRemote ('foo ' , ImportMapType::JS , '/does/not/matter ' , '1.0.0 ' , 'module_specifier ' , false );
48
63
$ this ->assertFalse ($ storage ->isDownloaded ($ entry ));
64
+
49
65
$ targetPath = self ::$ writableRoot .'/assets/vendor/module_specifier/module_specifier.index.js ' ;
50
- @ mkdir (\dirname ($ targetPath ), 0777 , true );
51
- file_put_contents ($ targetPath , 'any content ' );
66
+ $ this -> filesystem -> mkdir (\dirname ($ targetPath ));
67
+ $ this -> filesystem -> dumpFile ($ targetPath , 'any content ' );
52
68
$ this ->assertTrue ($ storage ->isDownloaded ($ entry ));
53
69
}
54
70
@@ -57,9 +73,10 @@ public function testIsExtraFileDownloaded()
57
73
$ storage = new RemotePackageStorage (self ::$ writableRoot .'/assets/vendor ' );
58
74
$ entry = ImportMapEntry::createRemote ('foo ' , ImportMapType::JS , '/does/not/matter ' , '1.0.0 ' , 'module_specifier ' , false );
59
75
$ this ->assertFalse ($ storage ->isExtraFileDownloaded ($ entry , '/path/to/extra.woff ' ));
76
+
60
77
$ targetPath = self ::$ writableRoot .'/assets/vendor/module_specifier/path/to/extra.woff ' ;
61
- @ mkdir (\dirname ($ targetPath ), 0777 , true );
62
- file_put_contents ($ targetPath , 'any content ' );
78
+ $ this -> filesystem -> mkdir (\dirname ($ targetPath ));
79
+ $ this -> filesystem -> dumpFile ($ targetPath , 'any content ' );
63
80
$ this ->assertTrue ($ storage ->isExtraFileDownloaded ($ entry , '/path/to/extra.woff ' ));
64
81
}
65
82
@@ -92,7 +109,7 @@ public function testGetDownloadedPath(string $packageModuleSpecifier, ImportMapT
92
109
$ this ->assertSame ($ expectedPath , $ storage ->getDownloadPath ($ packageModuleSpecifier , $ importMapType ));
93
110
}
94
111
95
- public static function getDownloadPathTests ()
112
+ public static function getDownloadPathTests (): iterable
96
113
{
97
114
yield 'javascript bare package ' => [
98
115
'packageModuleSpecifier ' => 'foo ' ,
0 commit comments