12
12
13
13
uses (ProphecyTrait::class);
14
14
15
- function createApiResponse (array $ data ): ApiResponse
15
+ function createApiResponse (array $ data, int $ statusCode = 200 ): ApiResponse
16
16
{
17
- return new ApiResponse ($ data , ['headers ' => [], 'statusCode ' => 200 ]);
17
+ return new ApiResponse ($ data , ['headers ' => [], 'statusCode ' => $ statusCode ]);
18
18
}
19
19
20
20
beforeEach (function () {
@@ -25,69 +25,78 @@ function createApiResponse(array $data): ApiResponse
25
25
$ this ->cloudinary ->uploadApi ()->willReturn ($ this ->uploadApi ->reveal ());
26
26
$ this ->cloudinary ->adminApi ()->willReturn ($ this ->adminApi ->reveal ());
27
27
28
- $ this ->adapter = new CloudinaryStorageAdapter ($ this ->cloudinary ->reveal (), ' prefix ' );
28
+ $ this ->adapter = new CloudinaryStorageAdapter ($ this ->cloudinary ->reveal ());
29
29
});
30
30
31
31
it ('can copy a file ' , function () {
32
32
$ this ->uploadApi ->explicit (
33
- Argument::exact ('source ' ),
34
- Argument::that ( fn ( $ args ) => $ args [ ' public_id ' ] === ' destination ' && $ args [ ' type ' ] === ' upload ' )
33
+ Argument::exact ('./ source ' ),
34
+ Argument::any (),
35
35
)->willReturn (createApiResponse (['public_id ' => 'destination ' ]))->shouldBeCalled ();
36
36
37
37
$ this ->adapter ->copy ('source.jpg ' , 'destination.jpg ' , new Config );
38
38
});
39
39
40
40
it ('can delete a file ' , function () {
41
41
$ this ->uploadApi ->destroy (
42
- Argument::exact ('test-file ' ),
43
- Argument::exact ([ ' resource_type ' => ' image ' ] )
42
+ Argument::exact ('Fixtures/ test-file ' ),
43
+ Argument::any ( )
44
44
)->willReturn (createApiResponse (['result ' => 'ok ' ]))->shouldBeCalled ();
45
45
46
- $ this ->adapter ->delete ('test-file.jpg ' );
46
+ $ this ->adapter ->delete ('Fixtures/ test-file.jpg ' );
47
47
});
48
48
49
49
it ('throws exception on delete failure ' , function () {
50
- $ this ->uploadApi ->destroy ('test-file ' , ['resource_type ' => 'image ' ])
51
- ->willReturn (createApiResponse (['result ' => 'error ' , 'error ' => 'Failed ' ]))
52
- ->shouldBeCalled ();
50
+ $ this ->uploadApi ->destroy (
51
+ Argument::exact ('Fixtures/test-file ' ),
52
+ Argument::any ()
53
+ )->willReturn (createApiResponse (['result ' => 'error ' , 'error ' => 'Failed ' ]))->shouldBeCalled ();
53
54
54
- expect (fn () => $ this ->adapter ->delete ('test-file.jpg ' ))
55
+ expect (fn () => $ this ->adapter ->delete ('Fixtures/ test-file.jpg ' ))
55
56
->toThrow (UnableToDeleteFile::class);
56
57
});
57
58
58
59
it ('can delete a directory ' , function () {
59
60
$ this ->adminApi ->deleteAssetsByPrefix (
60
- Argument::exact ('test-dir ' )
61
+ Argument::exact ('Fixtures/ test-dir ' )
61
62
)->willReturn (createApiResponse (['result ' => 'ok ' ]))->shouldBeCalled ();
62
63
63
- $ this ->adapter ->deleteDirectory ('test-dir ' );
64
+ $ this ->adapter ->deleteDirectory ('Fixtures/ test-dir ' );
64
65
});
65
66
66
67
it ('can check if file exists ' , function () {
67
68
$ this ->adminApi ->asset (
68
- Argument::exact ('test-file ' ),
69
- Argument::exact (['resource_type ' => 'image ' ])
70
- )->willReturn (createApiResponse (['public_id ' => 'test-file ' ]))->shouldBeCalled ();
69
+ Argument::exact ('Fixtures/test-file ' ),
70
+ Argument::any ()
71
+ )->willReturn (createApiResponse ([
72
+ 'public_id ' => 'Fixtures/test-file ' ,
73
+ 'bytes ' => 1234 ,
74
+ 'secure_url ' => 'https://example.com/test-file ' ,
75
+ ]))->shouldBeCalled ();
71
76
72
- expect ($ this ->adapter ->fileExists ('test-file.jpg ' ))->toBeTrue ();
77
+ expect ($ this ->adapter ->fileExists ('Fixtures/ test-file.jpg ' ))->toBeTrue ();
73
78
});
74
79
75
80
it ('handles non-existent files ' , function () {
76
81
$ this ->adminApi ->asset (
77
- Argument::exact ('test-file ' ),
78
- Argument::exact ([ ' resource_type ' => ' image ' ] )
82
+ Argument::exact ('Fixtures/ test-file ' ),
83
+ Argument::any ( )
79
84
)->willThrow (new Exception ('Not found ' ))->shouldBeCalled ();
80
85
81
- expect ($ this ->adapter ->fileExists ('test-file.jpg ' ))->toBeFalse ();
86
+ expect ($ this ->adapter ->fileExists ('Fixtures/ test-file.jpg ' ))->toBeFalse ();
82
87
});
83
88
84
89
it ('can get file size ' , function () {
85
90
$ this ->adminApi ->asset (
86
- Argument::exact ('test-file ' ),
87
- Argument::exact (['resource_type ' => 'image ' ])
88
- )->willReturn (createApiResponse (['bytes ' => 1234 ]))->shouldBeCalled ();
91
+ Argument::exact ('Fixtures/test-file ' ),
92
+ Argument::any ()
93
+ )->willReturn (createApiResponse ([
94
+ 'public_id ' => 'Fixtures/test-file ' ,
95
+ 'bytes ' => 1234 ,
96
+ 'secure_url ' => 'https://example.com/test-file ' ,
97
+ ]))->shouldBeCalled ();
89
98
90
- $ size = $ this ->adapter ->fileSize ('test-file.jpg ' );
99
+ $ size = $ this ->adapter ->fileSize ('Fixtures/ test-file.jpg ' );
91
100
expect ($ size ->fileSize ())->toBe (1234 );
92
101
});
93
102
@@ -96,23 +105,23 @@ function createApiResponse(array $data): ApiResponse
96
105
$ expectedTimestamp = strtotime ($ date );
97
106
98
107
$ this ->adminApi ->asset (
99
- Argument::exact ('test-file ' ),
100
- Argument::exact ([ ' resource_type ' => ' image ' ] )
108
+ Argument::exact ('Fixtures/ test-file ' ),
109
+ Argument::any ( )
101
110
)->willReturn (createApiResponse ([
102
- 'public_id ' => 'test-file ' ,
111
+ 'public_id ' => 'Fixtures/ test-file ' ,
103
112
'created_at ' => $ date ,
104
113
'bytes ' => 1234 ,
105
114
]))->shouldBeCalled ();
106
115
107
- $ time = $ this ->adapter ->lastModified ('test-file.jpg ' );
116
+ $ time = $ this ->adapter ->lastModified ('Fixtures/ test-file.jpg ' );
108
117
expect ($ time ->lastModified ())->toBe ($ expectedTimestamp );
109
118
});
110
119
111
120
it ('can list contents ' , function () {
112
121
$ response = createApiResponse ([
113
122
'resources ' => [
114
123
[
115
- 'public_id ' => 'test-file ' ,
124
+ 'public_id ' => 'Fixtures/ test-file ' ,
116
125
'bytes ' => 1234 ,
117
126
'created_at ' => '2023-01-01 ' ,
118
127
],
@@ -131,33 +140,33 @@ function createApiResponse(array $data): ApiResponse
131
140
132
141
it ('can read a file ' , function () {
133
142
$ this ->adminApi ->asset (
134
- Argument::exact ('test-file ' ),
135
- Argument::exact ([ ' resource_type ' => ' image ' ] )
143
+ Argument::exact ('Fixtures/ test-file ' ),
144
+ Argument::any ( )
136
145
)->willReturn (createApiResponse ([
137
146
'secure_url ' => __DIR__ .'/test.jpg ' ,
138
147
]))->shouldBeCalled ();
139
148
140
149
// Create a test file
141
150
file_put_contents (__DIR__ .'/test.jpg ' , 'test content ' );
142
151
143
- $ content = $ this ->adapter ->read ('test-file.jpg ' );
152
+ $ content = $ this ->adapter ->read ('Fixtures/ test-file.jpg ' );
144
153
expect ($ content )->toBe ('test content ' );
145
154
146
155
unlink (__DIR__ .'/test.jpg ' );
147
156
});
148
157
149
158
it ('can read a file as stream ' , function () {
150
159
$ this ->adminApi ->asset (
151
- Argument::exact ('test-file ' ),
152
- Argument::exact ([ ' resource_type ' => ' image ' ] )
160
+ Argument::exact ('Fixtures/ test-file ' ),
161
+ Argument::any ( )
153
162
)->willReturn (createApiResponse ([
154
163
'secure_url ' => __DIR__ .'/test.jpg ' ,
155
164
]))->shouldBeCalled ();
156
165
157
166
// Create a test file
158
167
file_put_contents (__DIR__ .'/test.jpg ' , 'test content ' );
159
168
160
- $ stream = $ this ->adapter ->readStream ('test-file.jpg ' );
169
+ $ stream = $ this ->adapter ->readStream ('Fixtures/ test-file.jpg ' );
161
170
expect ($ stream )->toBeResource ();
162
171
expect (stream_get_contents ($ stream ))->toBe ('test content ' );
163
172
@@ -171,15 +180,16 @@ function createApiResponse(array $data): ApiResponse
171
180
172
181
it ('can move a file ' , function () {
173
182
$ this ->uploadApi ->explicit (
174
- Argument::exact ('source ' ),
175
- Argument::that ( fn ( $ args ) => $ args [ ' public_id ' ] === ' destination ' && $ args [ ' type ' ] === ' upload ' )
183
+ Argument::exact ('Fixtures/ source ' ),
184
+ Argument::any (),
176
185
)->willReturn (createApiResponse (['public_id ' => 'destination ' ]))->shouldBeCalled ();
177
186
178
- $ this ->uploadApi ->destroy ('source ' , ['resource_type ' => 'image ' ])
179
- ->willReturn (createApiResponse (['result ' => 'ok ' ]))
180
- ->shouldBeCalled ();
187
+ $ this ->uploadApi ->destroy (
188
+ Argument::exact ('Fixtures/source ' ),
189
+ Argument::any ()
190
+ )->willReturn (createApiResponse (['result ' => 'ok ' ]))->shouldBeCalled ();
181
191
182
- $ this ->adapter ->move ('source.jpg ' , 'destination.jpg ' , new Config );
192
+ $ this ->adapter ->move ('Fixtures/ source.jpg ' , 'Fixtures/ destination.jpg ' , new Config );
183
193
});
184
194
185
195
it ('can calculate checksum ' , function () {
0 commit comments