Skip to content

Commit 460f2db

Browse files
committed
mock cloudinary
1 parent a117160 commit 460f2db

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

tests/Unit/CloudinaryAdapterTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
<?php
22

33
use Illuminate\Support\Facades\Storage;
4+
use Mockery\MockInterface;
45

56
it('can get url given public id', function () {
6-
expect(Storage::disk('cloudinary')->url(basename(env('TEST_FILE_URL'))))->toEqual(env('TEST_FILE_URL'));
7+
$file = 'baz.jpg';
8+
$url = 'https://res.cloudinary.com/foo/image/upload/bar/' . $file;
9+
10+
$this->mock('overload:' . Cloudinary\Api\Admin\AdminApi::class, function (MockInterface $mock) use ($url) {
11+
$mock->shouldReceive('asset')->once()->andReturn(['secure_url' => $url]);
12+
})->makePartial();
13+
14+
$result = Storage::disk('cloudinary')->url($file);
15+
expect($result)->toEqual($url);
716
});

tests/Unit/MediaAllyTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
<?php
22

33
use Illuminate\Http\UploadedFile;
4+
use Mockery\MockInterface;
45
use Tests\Fixtures\Models\Example;
56

6-
it('can attach media to a model', function () {
7+
beforeEach(function () {
8+
$this->mock('overload:' . Cloudinary\Api\Upload\UploadApi::class, function (MockInterface $mock) {
9+
$mock->shouldReceive('upload')->andReturn([
10+
'public_id' => 'file',
11+
'bytes' => '123',
12+
'secure_url' => 'https://example.com/file.jpg',
13+
'resource_type' => 'image',
14+
]);
15+
16+
$mock->shouldReceive('destroy')->andReturn([
17+
'result' => 'ok',
18+
]);
19+
})->makePartial();
20+
});
721

22+
it('can attach media to a model', function () {
823
$example = Example::create([]);
924

1025
$example->attachMedia(UploadedFile::fake()->image('file.jpg'));
1126

27+
1228
expect($example->fetchAllMedia())->toHaveCount(1);
1329
});
1430

0 commit comments

Comments
 (0)