ReviewOS

also looking at this

meemalabs/meema-client-php

fix: Folder use UUID

#80
Merged glennmichael123 wants to merge folder-uuid into main
11 files +608 -149

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

.github/workflows/run-tests.ymlmodified+5-1
Changes to .github/workflows/run-tests.yml
@@ -34,6 +34,10 @@ jobs:
3434 run: |
3535 composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
3636
37 - name: Dump composer
38 run: |
39 composer dumpautoload
40
3741 - name: Make envfile
3842 uses: SpicyPizza/create-envfile@v1
3943 with:
@@ -43,4 +47,4 @@ jobs:
4347 file_name: .env
4448
4549 - name: Execute tests
46 run: vendor/bin/pest
50 run: ./vendor/bin/pest
src/Models/Folder.phpmodified+22-21
Changes to src/Models/Folder.php
@@ -6,10 +6,11 @@ use Meema\MeemaClient\Client;
66use Meema\MeemaClient\Exceptions\InvalidFormatException;
77use Meema\MeemaClient\Response\Response;
88use Meema\MeemaClient\Traits\CollectionsResponse;
9use Meema\MeemaClient\Traits\ValidsUuid;
910
1011class Folder
1112{
12 use CollectionsResponse;
13 use CollectionsResponse, ValidsUuid;
1314
1415 /**
1516 * @var \Meema\MeemaClient\Client
@@ -64,8 +65,8 @@ class Folder
6465 $ids = is_array($id) ? $id : func_get_args();
6566
6667 foreach ($ids as $id) {
67 if (! is_int($id)) {
68 throw new InvalidFormatException();
68 if (! $this->isValidUuid($id)) {
69 throw new InvalidFormatException('ID is not a valid UUID');
6970 }
7071 }
7172
@@ -99,8 +100,8 @@ class Folder
99100 */
100101 public function find($id)
101102 {
102 if (! is_int($id)) {
103 throw new InvalidFormatException();
103 if (! $this->isValidUuid($id)) {
104 throw new InvalidFormatException('ID is not a valid UUID');
104105 }
105106
106107 $response = $this->client->request('GET', "folders/${id}");
@@ -138,8 +139,8 @@ class Folder
138139 */
139140 public function update($id, $name)
140141 {
141 if (! is_int($id)) {
142 throw new InvalidFormatException();
142 if (! $this->isValidUuid($id)) {
143 throw new InvalidFormatException('ID is not a valid UUID');
143144 }
144145
145146 $name = is_array($name) ? $name : compact('name');
@@ -161,8 +162,8 @@ class Folder
161162 $ids = is_array($ids) ? $ids : func_get_args();
162163
163164 foreach ($ids as $id) {
164 if (! is_int($id)) {
165 throw new InvalidFormatException();
165 if (! $this->isValidUuid($id)) {
166 throw new InvalidFormatException('ID is not a valid UUID');
166167 }
167168
168169 if ($this->model) {
@@ -194,8 +195,8 @@ class Folder
194195 $ids = is_array($ids) ? $ids : func_get_args();
195196
196197 foreach ($ids as $id) {
197 if (! is_int($id)) {
198 throw new InvalidFormatException();
198 if (! $this->isValidUuid($id)) {
199 throw new InvalidFormatException('ID is not a valid UUID');
199200 }
200201 }
201202
@@ -223,8 +224,8 @@ class Folder
223224 $ids = is_array($ids) ? $ids : func_get_args();
224225
225226 foreach ($ids as $id) {
226 if (! is_int($id)) {
227 throw new InvalidFormatException();
227 if (! $this->isValidUuid($id)) {
228 throw new InvalidFormatException('ID is not a valid UUID');
228229 }
229230 }
230231
@@ -252,8 +253,8 @@ class Folder
252253 $ids = is_array($ids) ? $ids : func_get_args();
253254
254255 foreach ($ids as $id) {
255 if (! is_int($id)) {
256 throw new InvalidFormatException();
256 if (! $this->isValidUuid($id)) {
257 throw new InvalidFormatException('ID is not a valid UUID');
257258 }
258259 }
259260
@@ -279,8 +280,8 @@ class Folder
279280 */
280281 protected function addFolderToMedia($id, $name)
281282 {
282 if (! is_int($id)) {
283 throw new InvalidFormatException();
283 if (! $this->isValidUuid($id)) {
284 throw new InvalidFormatException('ID is not a valid UUID');
284285 }
285286
286287 return $this->client->request('POST', "media/{$id}/folders", $name);
@@ -298,8 +299,8 @@ class Folder
298299 */
299300 protected function deleteFolderFromMedia($id, $folderId)
300301 {
301 if (! is_int($id) || ! is_int($folderId)) {
302 throw new InvalidFormatException();
302 if (! $this->isValidUuid($id) || ! $this->isValidUuid($folderId)) {
303 throw new InvalidFormatException('ID is not a valid UUID');
303304 }
304305
305306 return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}");
@@ -362,9 +363,9 @@ class Folder
362363 /**
363364 * Get the protected id.
364365 *
365 * @return int
366 * @return string
366367 */
367 public function getId(): int
368 public function getId()
368369 {
369370 return $this->id;
370371 }
src/Models/Media.phpmodified+1-1
Changes to src/Models/Media.php
@@ -377,7 +377,7 @@ class Media
377377 /**
378378 * Get the protected id.
379379 *
380 * @return int
380 * @return string
381381 */
382382 public function getId()
383383 {
tests/MeemaFolderTest.phpmodified+21-7
Changes to tests/MeemaFolderTest.php
@@ -17,7 +17,9 @@ it('can fetch all folders', function () {
1717});
1818
1919it('can search a folder', function () {
20 $folder = $this->client->folders()->find(1)->toArray();
20 $folders = $this->client->folders()->get();
21
22 $folder = $this->client->folders()->find($folders[0]['id'])->toArray();
2123
2224 $query = $folder['name'];
2325
@@ -28,7 +30,9 @@ it('can search a folder', function () {
2830});
2931
3032it('can fetch specific group of folders', function () {
31 $ids = [1, 2, 3];
33 $folders = $this->client->folders()->get();
34
35 $ids = [$folders[0]['id'], $folders[1]['id'], $folders[2]['id']];
3236
3337 $folders = $this->client->folders()->get($ids);
3438
@@ -37,7 +41,9 @@ it('can fetch specific group of folders', function () {
3741});
3842
3943it('can find a single folder', function () {
40 $id = 1;
44 $folders = $this->client->folders()->get();
45
46 $id = $folders[0]['id'];
4147
4248 $folders = $this->client->folders()->find($id)->toArray();
4349
@@ -55,30 +61,38 @@ it('can create a folder', function () {
5561});
5662
5763it('can update a folder', function () {
64 $folders = $this->client->folders()->get();
65
5866 $name = 'test folder';
5967
60 $folders = $this->client->folders()->update(1, $name);
68 $folders = $this->client->folders()->update($folders[0]['id'], $name);
6169
6270 $this->assertTrue(is_array($folders));
6371 $this->assertTrue($folders['name'] === $name);
6472});
6573
6674it('can archive a folder', function () {
67 $folders = $this->client->folders()->archive(1);
75 $folders = $this->client->folders()->get();
76
77 $folders = $this->client->folders()->archive($folders[0]['id']);
6878
6979 $this->assertTrue(is_array($folders));
7080 $this->assertTrue((bool) $folders['is_archived']);
7181});
7282
7383it('can unarchive a folder', function () {
74 $folders = $this->client->folders()->unarchive(1);
84 $folders = $this->client->folders()->get();
85
86 $folders = $this->client->folders()->unarchive($folders[0]['id']);
7587
7688 $this->assertTrue(is_array($folders));
7789 $this->assertFalse((bool) $folders['is_archived']);
7890});
7991
8092it('can duplicate a folder', function () {
81 $folders = $this->client->folders()->find(1);
93 $folders = $this->client->folders()->get();
94
95 $folders = $this->client->folders()->find($folders[0]['id']);
8296
8397 $duplicated = $folders->duplicate();
8498
tests/MeemaMediaTest.phpmodified+33-12
Changes to tests/MeemaMediaTest.php
@@ -17,7 +17,9 @@ it('can be fetch all media', function () {
1717});
1818
1919it('can search a media', function () {
20 $media = $this->client->media()->find(1)->toArray();
20 $allMedia = $this->client->media()->get();
21
22 $media = $this->client->media()->find($allMedia[0]['id'])->toArray();
2123 $query = $media['name'];
2224
2325 $media = $this->client->media()->search($query);
@@ -27,6 +29,7 @@ it('can search a media', function () { formatting only
2729});
2830
2931it('can be fetch all media for a tag', function () {
32
3033 // 8 is the tag id for images
3134 $tag = $this->client->tags()->find(8);
3235
@@ -37,8 +40,10 @@ it('can be fetch all media for a tag', function () {
3740});
3841
3942it('can be fetch all media for a folder', function () {
43 $allFolders = $this->client->folders()->get();
44
4045 // 8 is the tag id for images
41 $folder = $this->client->folders()->find(1);
46 $folder = $this->client->folders()->find($allFolders[0]['id']);
4247
4348 $media = $folder->media()->get();
4449
@@ -47,7 +52,9 @@ it('can be fetch all media for a folder', function () {
4752});
4853
4954it('can be fetch specific group of media', function () {
50 $ids = [1, 2, 3];
55 $allMedia = $this->client->media()->get();
56
57 $ids = [$allMedia[0]['id'], $allMedia[1]['id'], $allMedia[2]['id']];
5158
5259 $media = $this->client->media()->get($ids);
5360
@@ -56,7 +63,9 @@ it('can be fetch specific group of media', function () {
5663});
5764
5865it('can find a single media', function () {
59 $id = 1;
66 $allMedia = $this->client->media()->get();
67
68 $id = $allMedia[0]['id'];
6069
6170 $media = $this->client->media()->find($id)->toArray();
6271
@@ -65,46 +74,58 @@ it('can find a single media', function () {
6574});
6675
6776it('can update a media', function () {
77 $allMedia = $this->client->media()->get();
78
6879 $name = 'test media';
6980
70 $media = $this->client->media()->update(1, $name);
81 $media = $this->client->media()->update($allMedia[0]['id'], $name);
7182
7283 $this->assertTrue(is_array($media));
7384 $this->assertTrue($media['name'] === $name);
7485});
7586
7687it('can archive a media', function () {
77 $media = $this->client->media()->archive(1);
88 $allMedia = $this->client->media()->get();
89
90 $media = $this->client->media()->archive($allMedia[0]['id']);
7891
7992 $this->assertTrue(is_array($media));
8093 $this->assertTrue((bool) $media['is_archived']);
8194});
8295
8396it('can unarchive a media', function () {
84 $media = $this->client->media()->unarchive(1);
97 $allMedia = $this->client->media()->get();
98
99 $media = $this->client->media()->unarchive($allMedia[0]['id']);
85100
86101 $this->assertTrue(is_array($media));
87102 $this->assertFalse((bool) $media['is_archived']);
88103});
89104
90105it('can make a media private', function () {
91 $media = $this->client->media()->makePrivate(1);
106 $allMedia = $this->client->media()->get();
107
108 $media = $this->client->media()->makePrivate($allMedia[0]['id']);
92109
93110 $this->assertTrue(is_array($media));
94111 $this->assertFalse((bool) $media['is_public']);
95112});
96113
97114it('can make a media public', function () {
98 $media = $this->client->media()->makePublic(1);
115 $allMedia = $this->client->media()->get();
116
117 $media = $this->client->media()->makePublic($allMedia[0]['id']);
99118
100119 $this->assertTrue(is_array($media));
101120 $this->assertTrue((bool) $media['is_public']);
102121});
103122
104123it('can duplicate a media', function () {
105 $media = $this->client->media()->find(1);
124 $allMedia = $this->client->media()->get();
125
126 $media = $this->client->media()->find($allMedia[0]['id']);
106127
107 $duplicated = $this->client->media()->duplicate(1);
128 $duplicated = $this->client->media()->duplicate($allMedia[0]['id']);
108129
109130 $this->assertTrue(is_array($duplicated));
110131 $this->assertTrue($duplicated['name'] === $media->toArray()['name']);
@@ -114,7 +135,7 @@ it('can delete a media', function () {
114135 $media = $this->client->media()->get();
115136
116137 $media = array_reverse($media);
117 $response = $this->client->media()->delete((int) $media[0]['media_id']);
138 $response = $this->client->media()->delete($media[0]['id']);
118139
119140 $this->assertTrue(is_null($response));
120141});
tests/MeemaTagTest.phpmodified+7-2
Changes to tests/MeemaTagTest.php
@@ -53,7 +53,10 @@ it('can delete a tag', function () {
5353});
5454
5555it('can fetch all media tags', function () {
56 $media = $this->client->media()->find(1);
56 $allMedia = $this->client->media()->get();
57
58 $media = $this->client->media()->find($allMedia[0]['id']);
59
5760 $tags = $media->tags()->get();
5861
5962 $this->assertTrue(is_array($tags));
@@ -61,7 +64,9 @@ it('can fetch all media tags', function () {
6164});
6265
6366it('can fetch all folder tags', function () {
64 $folder = $this->client->folders()->find(1);
67 $folders = $this->client->folders()->get();
68
69 $folder = $this->client->folders()->find($folders[0]['id']);
6570 $tags = $folder->tags()->get();
6671
6772 $this->assertTrue(is_array($tags));