File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
use Illuminate \Support \Facades \Storage ;
4
+ use Mockery \MockInterface ;
4
5
5
6
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 );
7
16
});
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
use Illuminate \Http \UploadedFile ;
4
+ use Mockery \MockInterface ;
4
5
use Tests \Fixtures \Models \Example ;
5
6
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
+ });
7
21
22
+ it ('can attach media to a model ' , function () {
8
23
$ example = Example::create ([]);
9
24
10
25
$ example ->attachMedia (UploadedFile::fake ()->image ('file.jpg ' ));
11
26
27
+
12
28
expect ($ example ->fetchAllMedia ())->toHaveCount (1 );
13
29
});
14
30
You can’t perform that action at this time.
0 commit comments