7
7
use League \Flysystem \Filesystem ;
8
8
use League \Flysystem \FilesystemAdapter ;
9
9
use League \Flysystem \FilesystemException ;
10
+ use League \Flysystem \UnableToCopyFile ;
11
+ use League \Flysystem \UnableToMoveFile ;
10
12
use League \Flysystem \UnableToRetrieveMetadata ;
11
13
use League \Flysystem \Visibility ;
12
14
use PlatformCommunity \Flysystem \BunnyCDN \BunnyCDNAdapter ;
16
18
17
19
class FlysystemTest extends FilesystemAdapterTestCase
18
20
{
19
- /**
20
- * Storage Zone
21
- */
22
- const STORAGE_ZONE = 'test_storage_zone ' ;
21
+ public const DEMOURL = 'https://example.org.local ' ;
22
+
23
+ protected static bool $ isLive = false ;
24
+
25
+ protected static string $ publicUrl = self ::DEMOURL ;
26
+
27
+ public static function setUpBeforeClass (): void
28
+ {
29
+ global $ public_url ;
30
+ if (isset ($ public_url )) {
31
+ static ::$ publicUrl = $ public_url ;
32
+ }
33
+
34
+ static ::$ publicUrl = rtrim (static ::$ publicUrl , '/ ' );
35
+ }
23
36
24
37
private static function bunnyCDNClient (): BunnyCDNClient
25
38
{
@@ -28,15 +41,17 @@ private static function bunnyCDNClient(): BunnyCDNClient
28
41
global $ region ;
29
42
30
43
if ($ storage_zone !== null && $ api_key !== null ) {
44
+ static ::$ isLive = true ;
45
+
31
46
return new BunnyCDNClient ($ storage_zone , $ api_key , $ region ?? BunnyCDNRegion::DEFAULT );
32
- } else {
33
- return new MockClient (self ::STORAGE_ZONE , '123 ' );
34
47
}
48
+
49
+ return new MockClient ('test_storage_zone ' , '123 ' );
35
50
}
36
51
37
52
public static function createFilesystemAdapter (): FilesystemAdapter
38
53
{
39
- return new BunnyCDNAdapter (self ::bunnyCDNClient (), ' https://example.org.local/assets/ ' );
54
+ return new BunnyCDNAdapter (self ::bunnyCDNClient (), static :: $ publicUrl );
40
55
}
41
56
42
57
/**
@@ -52,22 +67,132 @@ public function generating_a_temporary_url(): void
52
67
$ this ->markTestSkipped ('No temporary URL support is provided for BunnyCDN ' );
53
68
}
54
69
70
+ /**
71
+ * @test
72
+ */
73
+ public function moving_a_folder (): void
74
+ {
75
+ $ this ->runScenario (function () {
76
+ $ adapter = $ this ->adapter ();
77
+ $ adapter ->write (
78
+ 'test/text.txt ' ,
79
+ 'contents to be copied ' ,
80
+ new Config ([Config::OPTION_VISIBILITY => Visibility::PUBLIC ])
81
+ );
82
+ $ adapter ->write (
83
+ 'test/2/text.txt ' ,
84
+ 'contents to be copied ' ,
85
+ new Config ([Config::OPTION_VISIBILITY => Visibility::PUBLIC ])
86
+ );
87
+ $ adapter ->move ('test ' , 'destination ' , new Config ());
88
+ $ this ->assertFalse (
89
+ $ adapter ->fileExists ('test/text.txt ' ),
90
+ 'After moving a file should no longer exist in the original location. '
91
+ );
92
+ $ this ->assertFalse (
93
+ $ adapter ->fileExists ('test/2/text.txt ' ),
94
+ 'After moving a file should no longer exist in the original location. '
95
+ );
96
+ $ this ->assertTrue (
97
+ $ adapter ->fileExists ('destination/text.txt ' ),
98
+ 'After moving, a file should be present at the new location. '
99
+ );
100
+ $ this ->assertTrue (
101
+ $ adapter ->fileExists ('destination/2/text.txt ' ),
102
+ 'After moving, a file should be present at the new location. '
103
+ );
104
+ $ this ->assertEquals ('contents to be copied ' , $ adapter ->read ('destination/text.txt ' ));
105
+ $ this ->assertEquals ('contents to be copied ' , $ adapter ->read ('destination/2/text.txt ' ));
106
+ });
107
+ }
108
+
109
+ /**
110
+ * @test
111
+ */
112
+ public function moving_a_not_existing_folder (): void
113
+ {
114
+ $ this ->runScenario (function () {
115
+ $ adapter = $ this ->adapter ();
116
+
117
+ $ this ->expectException (UnableToMoveFile::class);
118
+ $ adapter ->move ('not_existing_file ' , 'destination ' , new Config ());
119
+ });
120
+ }
121
+
122
+ /**
123
+ * @test
124
+ */
125
+ public function copying_a_folder (): void
126
+ {
127
+ $ this ->runScenario (function () {
128
+ $ adapter = $ this ->adapter ();
129
+ $ adapter ->write (
130
+ 'test/text.txt ' ,
131
+ 'contents to be copied ' ,
132
+ new Config ([Config::OPTION_VISIBILITY => Visibility::PUBLIC ])
133
+ );
134
+ $ adapter ->write (
135
+ 'test/2/text.txt ' ,
136
+ 'contents to be copied ' ,
137
+ new Config ([Config::OPTION_VISIBILITY => Visibility::PUBLIC ])
138
+ );
139
+ $ adapter ->copy ('test ' , 'destination ' , new Config ());
140
+ $ this ->assertTrue (
141
+ $ adapter ->fileExists ('test/text.txt ' ),
142
+ 'After copying a file should exist in the original location. '
143
+ );
144
+ $ this ->assertTrue (
145
+ $ adapter ->fileExists ('test/2/text.txt ' ),
146
+ 'After copying a file should exist in the original location. '
147
+ );
148
+ $ this ->assertTrue (
149
+ $ adapter ->fileExists ('destination/text.txt ' ),
150
+ 'After copying, a file should be present at the new location. '
151
+ );
152
+ $ this ->assertTrue (
153
+ $ adapter ->fileExists ('destination/2/text.txt ' ),
154
+ 'After copying, a file should be present at the new location. '
155
+ );
156
+ $ this ->assertEquals ('contents to be copied ' , $ adapter ->read ('destination/text.txt ' ));
157
+ $ this ->assertEquals ('contents to be copied ' , $ adapter ->read ('destination/2/text.txt ' ));
158
+ });
159
+ }
160
+
161
+ /**
162
+ * @test
163
+ */
164
+ public function copying_a_not_existing_folder (): void
165
+ {
166
+ $ this ->runScenario (function () {
167
+ $ adapter = $ this ->adapter ();
168
+
169
+ $ this ->expectException (UnableToCopyFile::class);
170
+ $ adapter ->copy ('not_existing_file ' , 'destination ' , new Config ());
171
+ });
172
+ }
173
+
55
174
/**
56
175
* We overwrite the test, because the original tries accessing the url
57
176
*
58
177
* @test
59
178
*/
60
179
public function generating_a_public_url (): void
61
180
{
181
+ if (self ::$ isLive && ! \str_starts_with (static ::$ publicUrl , self ::DEMOURL )) {
182
+ parent ::generating_a_public_url ();
183
+
184
+ return ;
185
+ }
186
+
62
187
$ url = $ this ->adapter ()->publicUrl ('/path.txt ' , new Config ());
63
188
64
- self ::assertEquals (' https://example.org.local/assets /path.txt ' , $ url );
189
+ self ::assertEquals (static :: $ publicUrl . ' /path.txt ' , $ url );
65
190
}
66
191
67
192
public function test_without_pullzone_url_error_thrown_accessing_url (): void
68
193
{
69
- self :: expectException (\RuntimeException::class);
70
- self :: expectExceptionMessage ('In order to get a visible URL for a BunnyCDN object, you must pass the "pullzone_url" parameter to the BunnyCDNAdapter. ' );
194
+ $ this -> expectException (\RuntimeException::class);
195
+ $ this -> expectExceptionMessage ('In order to get a visible URL for a BunnyCDN object, you must pass the "pullzone_url" parameter to the BunnyCDNAdapter. ' );
71
196
$ myAdapter = new BunnyCDNAdapter (static ::bunnyCDNClient ());
72
197
$ myAdapter ->publicUrl ('/path.txt ' , new Config ());
73
198
}
@@ -144,7 +269,7 @@ public function test_regression_pr_20()
144
269
*/
145
270
public function test_regression_issue_29 ()
146
271
{
147
- $ client = new MockClient ( self ::STORAGE_ZONE , ' api-key ' );
272
+ $ client = self ::bunnyCDNClient ( );
148
273
$ client ->make_directory ('/example_folder ' );
149
274
150
275
$ adapter = new Filesystem (new BunnyCDNAdapter ($ client ));
0 commit comments