Skip to content

Commit 462b924

Browse files
authored
Merge pull request #62 from codebar-ag/feature/fix-exists
Fix exists method
2 parents c5c02d0 + a1ec793 commit 462b924

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

src/Events/FlysystemCloudinaryResponseLog.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ class FlysystemCloudinaryResponseLog
1515

1616
public function __construct(
1717
public ApiResponse $response,
18-
) {
19-
}
18+
) {}
2019
}

src/FlysystemCloudinaryAdapter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ protected function normalizeResponse(
655655
return [
656656
'contents' => $body,
657657
'etag' => Arr::get($response, 'etag'),
658-
'mimetype' => (new FinfoMimeTypeDetector())->detectMimeType($path, $body) ?? 'text/plain',
658+
'mimetype' => (new FinfoMimeTypeDetector)->detectMimeType($path, $body) ?? 'text/plain',
659659
'path' => $path,
660660
'size' => Arr::get($response, 'bytes'),
661661
'timestamp' => strtotime(Arr::get($response, 'created_at')),
@@ -668,6 +668,8 @@ protected function normalizeResponse(
668668

669669
public function fileExists(string $path): bool
670670
{
671+
$path = $this->ensureFolderIsPrefixed(trim($path, '/'));
672+
671673
try {
672674
$this->cloudinary->adminApi()->asset($path);
673675
} catch (Exception $e) {

tests/Feature/AdapterTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
});
4141
$adapter = new FlysystemCloudinaryAdapter($mock);
4242

43-
$adapter->write($publicId, $contents, new Config());
43+
$adapter->write($publicId, $contents, new Config);
4444

4545
$this->assertSame($contents, $adapter->meta['contents']);
4646
$this->assertSame('::etag::', $adapter->meta['etag']);
@@ -71,7 +71,7 @@
7171
});
7272
$adapter = new FlysystemCloudinaryAdapter($mock);
7373

74-
$adapter->writeStream($publicId, $contents, new Config());
74+
$adapter->writeStream($publicId, $contents, new Config);
7575

7676
$this->assertSame($contents, $adapter->meta['contents']);
7777
$this->assertSame('::etag::', $adapter->meta['etag']);
@@ -102,7 +102,7 @@
102102
});
103103
$adapter = new FlysystemCloudinaryAdapter($mock);
104104

105-
$meta = $adapter->update($publicId, $contents, new Config());
105+
$meta = $adapter->update($publicId, $contents, new Config);
106106

107107
$this->assertSame($contents, $meta['contents']);
108108
$this->assertSame('::etag::', $meta['etag']);
@@ -133,7 +133,7 @@
133133
});
134134
$adapter = new FlysystemCloudinaryAdapter($mock);
135135

136-
$meta = $adapter->updateStream($publicId, $contents, new Config());
136+
$meta = $adapter->updateStream($publicId, $contents, new Config);
137137

138138
$this->assertSame($contents, $meta['contents']);
139139
$this->assertSame('::etag::', $meta['etag']);
@@ -170,7 +170,7 @@
170170
});
171171
$adapter = new FlysystemCloudinaryAdapter($mock);
172172

173-
$adapter->copy('::from-path::', '::to-path::', new Config());
173+
$adapter->copy('::from-path::', '::to-path::', new Config);
174174

175175
$this->assertTrue($adapter->copied);
176176
Event::assertDispatched(FlysystemCloudinaryResponseLog::class, 2);
@@ -214,7 +214,7 @@
214214
});
215215
$adapter = new FlysystemCloudinaryAdapter($mock);
216216

217-
$meta = $adapter->createDir('::path::', new Config());
217+
$meta = $adapter->createDir('::path::', new Config);
218218

219219
$this->assertSame([
220220
'path' => '::path::',

tests/Integration/CloudinaryTest.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
$publicId = 'file-write-'.rand();
2828
$fakeImage = File::image('black.jpg')->getContent();
2929

30-
$this->adapter->write($publicId, $fakeImage, new Config());
30+
$this->adapter->write($publicId, $fakeImage, new Config);
3131

3232
assertUploadResponse($this, $this->adapter->meta, $publicId);
3333
$this->adapter->delete($publicId); // cleanup
@@ -37,7 +37,7 @@
3737
$publicId = 'file-write-stream-'.rand();
3838
$fakeImage = File::image('black.jpg')->getContent();
3939

40-
$this->adapter->writeStream($publicId, $fakeImage, new Config());
40+
$this->adapter->writeStream($publicId, $fakeImage, new Config);
4141

4242
assertUploadResponse($this, $this->adapter->meta, $publicId);
4343
$this->adapter->delete($publicId); // cleanup
@@ -47,7 +47,7 @@
4747
$publicId = 'file-update-'.rand();
4848
$fakeImage = File::image('black.jpg')->getContent();
4949

50-
$meta = $this->adapter->update($publicId, $fakeImage, new Config());
50+
$meta = $this->adapter->update($publicId, $fakeImage, new Config);
5151

5252
assertUploadResponse($this, $meta, $publicId);
5353
$this->adapter->delete($publicId); // cleanup
@@ -57,7 +57,7 @@
5757
$publicId = 'file-update-stream-'.rand();
5858
$fakeImage = File::image('black.jpg')->getContent();
5959

60-
$meta = $this->adapter->updateStream($publicId, $fakeImage, new Config());
60+
$meta = $this->adapter->updateStream($publicId, $fakeImage, new Config);
6161

6262
assertUploadResponse($this, $meta, $publicId);
6363
$this->adapter->delete($publicId); // cleanup
@@ -81,7 +81,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
8181
$path = 'file-old-path-'.rand();
8282
$newPath = 'file-new-path-'.rand();
8383
$fakeImage = File::image('black.jpg')->getContent();
84-
$this->adapter->write($path, $fakeImage, new Config());
84+
$this->adapter->write($path, $fakeImage, new Config);
8585

8686
$bool = $this->adapter->rename($path, $newPath);
8787

@@ -102,8 +102,8 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
102102
$path = 'file-rename-'.rand();
103103
$newPath = 'file-already-exists-'.rand();
104104
$fakeImage = File::image('black.jpg')->getContent();
105-
$this->adapter->write($path, $fakeImage, new Config());
106-
$this->adapter->write($newPath, $fakeImage, new Config());
105+
$this->adapter->write($path, $fakeImage, new Config);
106+
$this->adapter->write($newPath, $fakeImage, new Config);
107107

108108
$bool = $this->adapter->rename($path, $newPath);
109109

@@ -116,9 +116,9 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
116116
$path = 'file-old-copy-'.rand();
117117
$newPath = 'file-new-copy-'.rand();
118118
$fakeImage = File::image('black.jpg')->getContent();
119-
$this->adapter->write($path, $fakeImage, new Config());
119+
$this->adapter->write($path, $fakeImage, new Config);
120120

121-
$this->adapter->copy($path, $newPath, new Config());
121+
$this->adapter->copy($path, $newPath, new Config);
122122

123123
$this->assertTrue($this->adapter->fileExists($newPath));
124124
$this->adapter->delete($path); // cleanup
@@ -129,15 +129,15 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
129129
$path = 'file-does-not-exist';
130130
$newPath = 'file-copied';
131131

132-
$this->adapter->copy($path, $newPath, new Config());
132+
$this->adapter->copy($path, $newPath, new Config);
133133

134134
$this->assertFalse($this->adapter->copied);
135135
});
136136

137137
it('can delete', function () {
138138
$publicId = 'file-delete-'.rand();
139139
$fakeImage = File::image('black.jpg')->getContent();
140-
$this->adapter->write($publicId, $fakeImage, new Config());
140+
$this->adapter->write($publicId, $fakeImage, new Config);
141141

142142
$this->adapter->delete($publicId);
143143

@@ -147,7 +147,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
147147
it('can delete a directory', function () {
148148
$publicId = 'delete_dir/file-'.rand();
149149
$fakeImage = File::image('black.jpg')->getContent();
150-
$this->adapter->write($publicId, $fakeImage, new Config());
150+
$this->adapter->write($publicId, $fakeImage, new Config);
151151

152152
$bool = $this->adapter->deleteDir('delete_dir');
153153

@@ -157,7 +157,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
157157
it('can create a directory', function () {
158158
$directory = 'directory-'.rand();
159159

160-
$meta = $this->adapter->createDir($directory, new Config());
160+
$meta = $this->adapter->createDir($directory, new Config);
161161

162162
$this->assertSame([
163163
'path' => $directory,
@@ -169,7 +169,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
169169
it('can check if file exists', function () {
170170
$publicId = 'file-has-'.rand();
171171
$fakeImage = File::image('black.jpg')->getContent();
172-
$this->adapter->write($publicId, $fakeImage, new Config());
172+
$this->adapter->write($publicId, $fakeImage, new Config);
173173

174174
$bool = $this->adapter->has($publicId);
175175

@@ -188,7 +188,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
188188
it('can read', function () {
189189
$publicId = 'file-read-'.rand();
190190
$fakeImage = File::image('black.jpg')->getContent();
191-
$this->adapter->write($publicId, $fakeImage, new Config());
191+
$this->adapter->write($publicId, $fakeImage, new Config);
192192

193193
$content = $this->adapter->read($publicId);
194194

@@ -199,7 +199,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
199199
it('can read stream', function () {
200200
$publicId = 'file-read-stream-'.rand();
201201
$fakeImage = File::image('black.jpg')->getContent();
202-
$this->adapter->write($publicId, $fakeImage, new Config());
202+
$this->adapter->write($publicId, $fakeImage, new Config);
203203

204204
$meta = $this->adapter->readStream($publicId);
205205

@@ -233,7 +233,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
233233
it('does get size', function () {
234234
$publicId = 'file-get-size-'.rand();
235235
$fakeImage = File::image('black.jpg')->getContent();
236-
$this->adapter->write($publicId, $fakeImage, new Config());
236+
$this->adapter->write($publicId, $fakeImage, new Config);
237237

238238
$size = $this->adapter->getSize($publicId);
239239

@@ -251,7 +251,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
251251
it('does get mimetype', function () {
252252
$publicId = 'file-get-mimetype-'.rand();
253253
$fakeImage = File::image('black.jpg')->getContent();
254-
$this->adapter->write($publicId, $fakeImage, new Config());
254+
$this->adapter->write($publicId, $fakeImage, new Config);
255255

256256
$mimeType = $this->adapter->getMimetype($publicId);
257257

@@ -269,7 +269,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
269269
it('does get timestamp', function () {
270270
$publicId = 'file-get-mimetype-'.rand();
271271
$fakeImage = File::image('black.jpg')->getContent();
272-
$this->adapter->write($publicId, $fakeImage, new Config());
272+
$this->adapter->write($publicId, $fakeImage, new Config);
273273

274274
$timeStamp = $this->adapter->getTimestamp($publicId);
275275

@@ -287,7 +287,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
287287
it('does get visibility', function () {
288288
$publicId = 'file-get-mimetype-'.rand();
289289
$fakeImage = File::image('black.jpg')->getContent();
290-
$this->adapter->write($publicId, $fakeImage, new Config());
290+
$this->adapter->write($publicId, $fakeImage, new Config);
291291

292292
$visibility = $this->adapter->getVisibility($publicId);
293293

@@ -305,7 +305,7 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
305305
it('does get url', function () {
306306
$publicId = 'file-get-url-'.rand();
307307
$fakeImage = File::image('black.jpg')->getContent();
308-
$this->adapter->write($publicId, $fakeImage, new Config());
308+
$this->adapter->write($publicId, $fakeImage, new Config);
309309

310310
$url = $this->adapter->getUrl($publicId);
311311

@@ -321,8 +321,8 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
321321

322322
$this->assertFalse($this->adapter->fileExists($movedToId));
323323

324-
$this->adapter->write($sourceId, $source, new Config());
325-
$this->adapter->move($sourceId, $movedToId, new Config());
324+
$this->adapter->write($sourceId, $source, new Config);
325+
$this->adapter->move($sourceId, $movedToId, new Config);
326326

327327
$this->assertFalse($this->adapter->fileExists($sourceId));
328328
$this->assertTrue($this->adapter->fileExists($movedToId));
@@ -334,12 +334,12 @@ function assertUploadResponse(mixed $test, array $meta, string $publicId): void
334334

335335
$this->assertFalse($this->adapter->fileExists($sourceId));
336336
$this->expectException(UnableToMoveFile::class);
337-
$this->adapter->move($sourceId, $movedToId, new Config());
337+
$this->adapter->move($sourceId, $movedToId, new Config);
338338
});
339339

340340
it('can create and delete directory', function () {
341341
$directory = 'directory_to_create';
342-
$this->adapter->createDirectory($directory, new Config());
342+
$this->adapter->createDirectory($directory, new Config);
343343

344344
$this->assertTrue($this->adapter->directoryExists($directory));
345345

0 commit comments

Comments
 (0)