also looking at this
fix: Folder use UUID
#80
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.
| @@ -34,6 +34,10 @@ jobs: | ||
| 34 | 34 | run: | |
| 35 | 35 | composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction |
| 36 | 36 | |
| 37 | - name: Dump composer | |
| 38 | run: | | |
| 39 | composer dumpautoload | |
| 40 | ||
| 37 | 41 | - name: Make envfile |
| 38 | 42 | uses: SpicyPizza/create-envfile@v1 |
| 39 | 43 | with: |
| @@ -43,4 +47,4 @@ jobs: | ||
| 43 | 47 | file_name: .env |
| 44 | 48 | |
| 45 | 49 | - name: Execute tests |
| 46 | run: vendor/bin/pest | |
| 50 | run: ./vendor/bin/pest | |
| @@ -6,10 +6,11 @@ use Meema\MeemaClient\Client; | ||
| 6 | 6 | use Meema\MeemaClient\Exceptions\InvalidFormatException; |
| 7 | 7 | use Meema\MeemaClient\Response\Response; |
| 8 | 8 | use Meema\MeemaClient\Traits\CollectionsResponse; |
| 9 | use Meema\MeemaClient\Traits\ValidsUuid; | |
| 9 | 10 | |
| 10 | 11 | class Folder |
| 11 | 12 | { |
| 12 | use CollectionsResponse; | |
| 13 | use CollectionsResponse, ValidsUuid; | |
| 13 | 14 | |
| 14 | 15 | /** |
| 15 | 16 | * @var \Meema\MeemaClient\Client |
| @@ -64,8 +65,8 @@ class Folder | ||
| 64 | 65 | $ids = is_array($id) ? $id : func_get_args(); |
| 65 | 66 | |
| 66 | 67 | 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'); | |
| 69 | 70 | } |
| 70 | 71 | } |
| 71 | 72 | |
| @@ -99,8 +100,8 @@ class Folder | ||
| 99 | 100 | */ |
| 100 | 101 | public function find($id) |
| 101 | 102 | { |
| 102 | if (! is_int($id)) { | |
| 103 | throw new InvalidFormatException(); | |
| 103 | if (! $this->isValidUuid($id)) { | |
| 104 | throw new InvalidFormatException('ID is not a valid UUID'); | |
| 104 | 105 | } |
| 105 | 106 | |
| 106 | 107 | $response = $this->client->request('GET', "folders/${id}"); |
| @@ -138,8 +139,8 @@ class Folder | ||
| 138 | 139 | */ |
| 139 | 140 | public function update($id, $name) |
| 140 | 141 | { |
| 141 | if (! is_int($id)) { | |
| 142 | throw new InvalidFormatException(); | |
| 142 | if (! $this->isValidUuid($id)) { | |
| 143 | throw new InvalidFormatException('ID is not a valid UUID'); | |
| 143 | 144 | } |
| 144 | 145 | |
| 145 | 146 | $name = is_array($name) ? $name : compact('name'); |
| @@ -161,8 +162,8 @@ class Folder | ||
| 161 | 162 | $ids = is_array($ids) ? $ids : func_get_args(); |
| 162 | 163 | |
| 163 | 164 | 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'); | |
| 166 | 167 | } |
| 167 | 168 | |
| 168 | 169 | if ($this->model) { |
| @@ -194,8 +195,8 @@ class Folder | ||
| 194 | 195 | $ids = is_array($ids) ? $ids : func_get_args(); |
| 195 | 196 | |
| 196 | 197 | 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'); | |
| 199 | 200 | } |
| 200 | 201 | } |
| 201 | 202 | |
| @@ -223,8 +224,8 @@ class Folder | ||
| 223 | 224 | $ids = is_array($ids) ? $ids : func_get_args(); |
| 224 | 225 | |
| 225 | 226 | 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'); | |
| 228 | 229 | } |
| 229 | 230 | } |
| 230 | 231 | |
| @@ -252,8 +253,8 @@ class Folder | ||
| 252 | 253 | $ids = is_array($ids) ? $ids : func_get_args(); |
| 253 | 254 | |
| 254 | 255 | 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'); | |
| 257 | 258 | } |
| 258 | 259 | } |
| 259 | 260 | |
| @@ -279,8 +280,8 @@ class Folder | ||
| 279 | 280 | */ |
| 280 | 281 | protected function addFolderToMedia($id, $name) |
| 281 | 282 | { |
| 282 | if (! is_int($id)) { | |
| 283 | throw new InvalidFormatException(); | |
| 283 | if (! $this->isValidUuid($id)) { | |
| 284 | throw new InvalidFormatException('ID is not a valid UUID'); | |
| 284 | 285 | } |
| 285 | 286 | |
| 286 | 287 | return $this->client->request('POST', "media/{$id}/folders", $name); |
| @@ -298,8 +299,8 @@ class Folder | ||
| 298 | 299 | */ |
| 299 | 300 | protected function deleteFolderFromMedia($id, $folderId) |
| 300 | 301 | { |
| 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'); | |
| 303 | 304 | } |
| 304 | 305 | |
| 305 | 306 | return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}"); |
| @@ -362,9 +363,9 @@ class Folder | ||
| 362 | 363 | /** |
| 363 | 364 | * Get the protected id. |
| 364 | 365 | * |
| 365 | * @return int | |
| 366 | * @return string | |
| 366 | 367 | */ |
| 367 | public function getId(): int | |
| 368 | public function getId() | |
| 368 | 369 | { |
| 369 | 370 | return $this->id; |
| 370 | 371 | } |
| @@ -17,7 +17,9 @@ it('can fetch all folders', function () { | ||
| 17 | 17 | }); |
| 18 | 18 | |
| 19 | 19 | it('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(); | |
| 21 | 23 | |
| 22 | 24 | $query = $folder['name']; |
| 23 | 25 | |
| @@ -28,7 +30,9 @@ it('can search a folder', function () { | ||
| 28 | 30 | }); |
| 29 | 31 | |
| 30 | 32 | it('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']]; | |
| 32 | 36 | |
| 33 | 37 | $folders = $this->client->folders()->get($ids); |
| 34 | 38 | |
| @@ -37,7 +41,9 @@ it('can fetch specific group of folders', function () { | ||
| 37 | 41 | }); |
| 38 | 42 | |
| 39 | 43 | it('can find a single folder', function () { |
| 40 | $id = 1; | |
| 44 | $folders = $this->client->folders()->get(); | |
| 45 | ||
| 46 | $id = $folders[0]['id']; | |
| 41 | 47 | |
| 42 | 48 | $folders = $this->client->folders()->find($id)->toArray(); |
| 43 | 49 | |
| @@ -55,30 +61,38 @@ it('can create a folder', function () { | ||
| 55 | 61 | }); |
| 56 | 62 | |
| 57 | 63 | it('can update a folder', function () { |
| 64 | $folders = $this->client->folders()->get(); | |
| 65 | ||
| 58 | 66 | $name = 'test folder'; |
| 59 | 67 | |
| 60 | $folders = $this->client->folders()->update(1, $name); | |
| 68 | $folders = $this->client->folders()->update($folders[0]['id'], $name); | |
| 61 | 69 | |
| 62 | 70 | $this->assertTrue(is_array($folders)); |
| 63 | 71 | $this->assertTrue($folders['name'] === $name); |
| 64 | 72 | }); |
| 65 | 73 | |
| 66 | 74 | it('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']); | |
| 68 | 78 | |
| 69 | 79 | $this->assertTrue(is_array($folders)); |
| 70 | 80 | $this->assertTrue((bool) $folders['is_archived']); |
| 71 | 81 | }); |
| 72 | 82 | |
| 73 | 83 | it('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']); | |
| 75 | 87 | |
| 76 | 88 | $this->assertTrue(is_array($folders)); |
| 77 | 89 | $this->assertFalse((bool) $folders['is_archived']); |
| 78 | 90 | }); |
| 79 | 91 | |
| 80 | 92 | it('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']); | |
| 82 | 96 | |
| 83 | 97 | $duplicated = $folders->duplicate(); |
| 84 | 98 | |
| @@ -17,7 +17,9 @@ it('can be fetch all media', function () { | ||
| 17 | 17 | }); |
| 18 | 18 | |
| 19 | 19 | it('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(); | |
| 21 | 23 | $query = $media['name']; |
| 22 | 24 | |
| 23 | 25 | $media = $this->client->media()->search($query); |
| @@ -27,6 +29,7 @@ it('can search a media', function () { formatting only | ||
| 27 | 29 | }); |
| 28 | 30 | |
| 29 | 31 | it('can be fetch all media for a tag', function () { |
| 32 | ||
| 30 | 33 | // 8 is the tag id for images |
| 31 | 34 | $tag = $this->client->tags()->find(8); |
| 32 | 35 | |
| @@ -37,8 +40,10 @@ it('can be fetch all media for a tag', function () { | ||
| 37 | 40 | }); |
| 38 | 41 | |
| 39 | 42 | it('can be fetch all media for a folder', function () { |
| 43 | $allFolders = $this->client->folders()->get(); | |
| 44 | ||
| 40 | 45 | // 8 is the tag id for images |
| 41 | $folder = $this->client->folders()->find(1); | |
| 46 | $folder = $this->client->folders()->find($allFolders[0]['id']); | |
| 42 | 47 | |
| 43 | 48 | $media = $folder->media()->get(); |
| 44 | 49 | |
| @@ -47,7 +52,9 @@ it('can be fetch all media for a folder', function () { | ||
| 47 | 52 | }); |
| 48 | 53 | |
| 49 | 54 | it('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']]; | |
| 51 | 58 | |
| 52 | 59 | $media = $this->client->media()->get($ids); |
| 53 | 60 | |
| @@ -56,7 +63,9 @@ it('can be fetch specific group of media', function () { | ||
| 56 | 63 | }); |
| 57 | 64 | |
| 58 | 65 | it('can find a single media', function () { |
| 59 | $id = 1; | |
| 66 | $allMedia = $this->client->media()->get(); | |
| 67 | ||
| 68 | $id = $allMedia[0]['id']; | |
| 60 | 69 | |
| 61 | 70 | $media = $this->client->media()->find($id)->toArray(); |
| 62 | 71 | |
| @@ -65,46 +74,58 @@ it('can find a single media', function () { | ||
| 65 | 74 | }); |
| 66 | 75 | |
| 67 | 76 | it('can update a media', function () { |
| 77 | $allMedia = $this->client->media()->get(); | |
| 78 | ||
| 68 | 79 | $name = 'test media'; |
| 69 | 80 | |
| 70 | $media = $this->client->media()->update(1, $name); | |
| 81 | $media = $this->client->media()->update($allMedia[0]['id'], $name); | |
| 71 | 82 | |
| 72 | 83 | $this->assertTrue(is_array($media)); |
| 73 | 84 | $this->assertTrue($media['name'] === $name); |
| 74 | 85 | }); |
| 75 | 86 | |
| 76 | 87 | it('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']); | |
| 78 | 91 | |
| 79 | 92 | $this->assertTrue(is_array($media)); |
| 80 | 93 | $this->assertTrue((bool) $media['is_archived']); |
| 81 | 94 | }); |
| 82 | 95 | |
| 83 | 96 | it('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']); | |
| 85 | 100 | |
| 86 | 101 | $this->assertTrue(is_array($media)); |
| 87 | 102 | $this->assertFalse((bool) $media['is_archived']); |
| 88 | 103 | }); |
| 89 | 104 | |
| 90 | 105 | it('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']); | |
| 92 | 109 | |
| 93 | 110 | $this->assertTrue(is_array($media)); |
| 94 | 111 | $this->assertFalse((bool) $media['is_public']); |
| 95 | 112 | }); |
| 96 | 113 | |
| 97 | 114 | it('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']); | |
| 99 | 118 | |
| 100 | 119 | $this->assertTrue(is_array($media)); |
| 101 | 120 | $this->assertTrue((bool) $media['is_public']); |
| 102 | 121 | }); |
| 103 | 122 | |
| 104 | 123 | it('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']); | |
| 106 | 127 | |
| 107 | $duplicated = $this->client->media()->duplicate(1); | |
| 128 | $duplicated = $this->client->media()->duplicate($allMedia[0]['id']); | |
| 108 | 129 | |
| 109 | 130 | $this->assertTrue(is_array($duplicated)); |
| 110 | 131 | $this->assertTrue($duplicated['name'] === $media->toArray()['name']); |
| @@ -114,7 +135,7 @@ it('can delete a media', function () { | ||
| 114 | 135 | $media = $this->client->media()->get(); |
| 115 | 136 | |
| 116 | 137 | $media = array_reverse($media); |
| 117 | $response = $this->client->media()->delete((int) $media[0]['media_id']); | |
| 138 | $response = $this->client->media()->delete($media[0]['id']); | |
| 118 | 139 | |
| 119 | 140 | $this->assertTrue(is_null($response)); |
| 120 | 141 | }); |
| @@ -53,7 +53,10 @@ it('can delete a tag', function () { | ||
| 53 | 53 | }); |
| 54 | 54 | |
| 55 | 55 | it('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 | ||
| 57 | 60 | $tags = $media->tags()->get(); |
| 58 | 61 | |
| 59 | 62 | $this->assertTrue(is_array($tags)); |
| @@ -61,7 +64,9 @@ it('can fetch all media tags', function () { | ||
| 61 | 64 | }); |
| 62 | 65 | |
| 63 | 66 | it('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']); | |
| 65 | 70 | $tags = $folder->tags()->get(); |
| 66 | 71 | |
| 67 | 72 | $this->assertTrue(is_array($tags)); |