From 7c27cae54411171152a48f168446a88ec2c35308 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Thu, 16 Oct 2025 15:56:00 +0200 Subject: [PATCH 01/11] feat: BEditaClient bulkEdit --- src/BEditaClient.php | 45 +++++++++++++ tests/TestCase/BEditaClientTest.php | 98 +++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) diff --git a/src/BEditaClient.php b/src/BEditaClient.php index 1266115..82e98b8 100644 --- a/src/BEditaClient.php +++ b/src/BEditaClient.php @@ -39,6 +39,51 @@ public function authenticate(string $username, string $password): ?array return $this->post('/auth', $body, ['Content-Type' => 'application/json']); } + /** + * Bulk edit objects using `POST /bulk/edit` endpoint. + * If the endpoint is not available, it fallback to edit one by one (retrocompatible way). + * + * @param array $ids Object ids + * @param array $data Data to modify + * @return array + */ + public function bulkEdit(array $ids, array $data): array + { + $result = []; + try { + $result = (array)$this->post( + '/bulk/edit', + json_encode([ + 'ids' => implode(',', $ids), + 'data' => $data, + ]), + ['Content-Type' => 'application/json'] + ); + } catch (Exception $e) { + $result['saved'] = []; + $result['errors'] = []; + // fallback to edit one by one, to be retrocompatible + foreach ($ids as $id) { + try { + $response = $this->getObject($id); + $type = $response['data']['type']; + $response = $this->save($type, $data + ['id' => $id]); + $result['saved'][] = $response['data']['id']; + } catch (Exception $e) { + $responseBody = $this->getResponseBody(); + $status = $responseBody['error']['status']; + $message = intval($status) === 403 ? '[403] Forbidden' : ($responseBody['error']['message'] ?? $e->getMessage()); + $result['errors'][] = [ + 'id' => $id, + 'message' => $message, + ]; + } + } + } + + return $result; + } + /** * GET a list of resources or objects of a given type * diff --git a/tests/TestCase/BEditaClientTest.php b/tests/TestCase/BEditaClientTest.php index fdc0676..f36d746 100644 --- a/tests/TestCase/BEditaClientTest.php +++ b/tests/TestCase/BEditaClientTest.php @@ -135,6 +135,104 @@ private function authenticate(): void $this->client->setupTokens($response['meta']); } + /** + * Test `bulkEdit` method + * + * @return void + */ + public function testBulkEdit(): void + { + $this->authenticate(); + // create 2 documents with status draft, one locked, one not locked + $response = $this->client->save('documents', [ + 'title' => 'this is a test document 1', + 'status' => 'draft', + ]); + $id1 = $response['data']['id']; + $response = $this->client->save('documents', [ + 'title' => 'this is a test document 2', + 'status' => 'draft', + ]); + $id2 = $response['data']['id']; + // lock the second document + $this->client->patch( + sprintf('/documents/%s', $id2), + json_encode([ + 'data' => [ + 'id' => $id2, + 'type' => 'documents', + 'meta' => [ + 'locked' => true, + ], + ], + ]), + ['Content-Type' => 'application/vnd.api+json'] + ); + $ids = [$id1, $id2]; + $data = ['status' => 'on']; + $response = $this->client->bulkEdit($ids, $data); + static::assertNotEmpty($response); + static::assertArrayHasKey('saved', $response); + static::assertArrayNotHasKey('error', $response); + static::assertEquals([$id1], $response['saved']); + static::assertEquals([['id' => $id2, 'message' => '[403] Forbidden']], $response['errors']); + } + + /** + * Test `bulkEdit` method retrocompatibility mode + * + * @return void + */ + public function testBulkEditRetrocompatibility(): void + { + // mock $this->post('/bulk/edit') to return an exception, to force use retrocompatibility mode + $client = new class ($this->apiBaseUrl, $this->apiKey) extends BEditaClient { + public function post(string $path, ?string $body = null, ?array $headers = null): ?array + { + if ($path === '/bulk/edit') { + throw new BEditaClientException('[404] Not Found', 404); + } + + return parent::post($path, $body, $headers); + } + }; + $response = $client->authenticate($this->adminUser, $this->adminPassword); + $client->setupTokens($response['meta']); + // create 2 documents with status draft, one locked, one not locked + $response = $client->save('documents', [ + 'title' => 'this is a test document 1', + 'status' => 'draft', + ]); + $id1 = $response['data']['id']; + $response = $client->save('documents', [ + 'title' => 'this is a test document 2', + 'status' => 'draft', + ]); + $id2 = $response['data']['id']; + // lock the second document + $client->patch( + sprintf('/documents/%s', $id2), + json_encode([ + 'data' => [ + 'id' => $id2, + 'type' => 'documents', + 'meta' => [ + 'locked' => true, + ], + ], + ]), + ['Content-Type' => 'application/vnd.api+json'] + ); + $ids = [$id1, $id2]; + $data = ['status' => 'on']; + $response = $client->bulkEdit($ids, $data); + static::assertNotEmpty($response); + static::assertArrayHasKey('saved', $response); + static::assertArrayNotHasKey('error', $response); + static::assertEquals([$id1], $response['saved']); + static::assertEquals([['id' => $id2, 'message' => '[403] Forbidden']], $response['errors']); + } + /** * Test `getObjects` method * From d7c1f446c05c082d4c6901308d224bf16bcb94ba Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Thu, 16 Oct 2025 16:16:31 +0200 Subject: [PATCH 02/11] chore phpcs: conf --- phpcs.xml.dist | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index d7b01fa..227d037 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -10,5 +10,7 @@ - + + + From 9510c1d930af254bfd72674f7f21201be35d4e0f Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Thu, 16 Oct 2025 16:23:01 +0200 Subject: [PATCH 03/11] fix: phpcs.xml.dist --- phpcs.xml.dist | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 227d037..d7b01fa 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -10,7 +10,5 @@ - - - + From 0ab6856daa013b78f796d3691be6d2c1960444e3 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Thu, 16 Oct 2025 16:54:43 +0200 Subject: [PATCH 04/11] chore fix: phpcs --- src/BEditaClient.php | 10 +++++----- src/LogTrait.php | 4 ++-- tests/TestCase/BEditaClientTest.php | 26 +++++++++++++------------- tests/TestCase/BaseClientTest.php | 2 +- tests/TestCase/MyBaseClient.php | 4 ++-- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/BEditaClient.php b/src/BEditaClient.php index 82e98b8..2e4211f 100644 --- a/src/BEditaClient.php +++ b/src/BEditaClient.php @@ -57,7 +57,7 @@ public function bulkEdit(array $ids, array $data): array 'ids' => implode(',', $ids), 'data' => $data, ]), - ['Content-Type' => 'application/json'] + ['Content-Type' => 'application/json'], ); } catch (Exception $e) { $result['saved'] = []; @@ -363,7 +363,7 @@ public function addStreamToMedia(string $streamId, string $id, string $type): vo 'id' => $id, 'type' => $type, ], - ]) + ]), ); if (empty($response)) { throw new BEditaClientException('Invalid response from PATCH ' . sprintf('/streams/%s/relationships/object', $id)); @@ -405,7 +405,7 @@ public function schema(string $type): ?array return $this->get( sprintf('/model/schema/%s', $type), null, - ['Accept' => 'application/schema+json'] + ['Accept' => 'application/schema+json'], ); } @@ -419,7 +419,7 @@ public function relationData(string $name): ?array { return $this->get( sprintf('/model/relations/%s', $name), - ['include' => 'left_object_types,right_object_types'] + ['include' => 'left_object_types,right_object_types'], ); } @@ -439,7 +439,7 @@ public function restoreObject(string|int $id, string $type): ?array 'id' => $id, 'type' => $type, ], - ]) + ]), ); } diff --git a/src/LogTrait.php b/src/LogTrait.php index 8886cc6..96694ec 100644 --- a/src/LogTrait.php +++ b/src/LogTrait.php @@ -76,7 +76,7 @@ public function logRequest(RequestInterface $request): void $request->getMethod(), $request->getUri(), $this->requestHeadersCleanup($request), - $this->requestBodyCleanup($request) + $this->requestBodyCleanup($request), ); $this->logger->info($msg); } @@ -155,7 +155,7 @@ public function logResponse(ResponseInterface $response): void $response->getStatusCode(), $response->getReasonPhrase(), json_encode($response->getHeaders()), - $this->responseBodyCleanup($response) + $this->responseBodyCleanup($response), ); $this->logger->info($msg); } diff --git a/tests/TestCase/BEditaClientTest.php b/tests/TestCase/BEditaClientTest.php index f36d746..b18e37b 100644 --- a/tests/TestCase/BEditaClientTest.php +++ b/tests/TestCase/BEditaClientTest.php @@ -166,7 +166,7 @@ public function testBulkEdit(): void ], ], ]), - ['Content-Type' => 'application/vnd.api+json'] + ['Content-Type' => 'application/vnd.api+json'], ); $ids = [$id1, $id2]; $data = ['status' => 'on']; @@ -221,7 +221,7 @@ public function post(string $path, ?string $body = null, ?array $headers = null) ], ], ]), - ['Content-Type' => 'application/vnd.api+json'] + ['Content-Type' => 'application/vnd.api+json'], ); $ids = [$id1, $id2]; $data = ['status' => 'on']; @@ -1260,15 +1260,15 @@ function ($document) { 'type' => $document['data']['type'], ]; }, - $documents - ) + $documents, + ), ); static::assertIsArray($addRelated); static::assertArrayHasKey('links', $addRelated); static::assertArrayHasKey('self', $addRelated['links']); static::assertStringContainsString( sprintf('/folders/%s/relationships/children', $folder['data']['id']), - $addRelated['links']['self'] + $addRelated['links']['self'], ); // get folder children @@ -1289,7 +1289,7 @@ function ($document) { static::assertArrayHasKey('self', $getRelated['links']); static::assertStringContainsString( sprintf('/folders/%s/children', $folder['data']['id']), - $getRelated['links']['self'] + $getRelated['links']['self'], ); // remove 5 documents from folder children @@ -1304,15 +1304,15 @@ function ($document) { 'type' => $document['data']['type'], ]; }, - array_slice($documents, 0, 5) - ) + array_slice($documents, 0, 5), + ), ); static::assertIsArray($removeRelated); static::assertArrayHasKey('links', $removeRelated); static::assertArrayHasKey('self', $removeRelated['links']); static::assertStringContainsString( sprintf('/folders/%s/relationships/children', $folder['data']['id']), - $removeRelated['links']['self'] + $removeRelated['links']['self'], ); // get again folder children: should be 5 @@ -1332,8 +1332,8 @@ function ($document) { 'type' => $document['data']['type'], ]; }, - $documentsReplace - ) + $documentsReplace, + ), ); // get again folder children: should be 2 @@ -1352,8 +1352,8 @@ function ($document) { 'type' => $document['data']['type'], ]; }, - $documentsReplace - ) + $documentsReplace, + ), ); // get again folder children: should be 0 diff --git a/tests/TestCase/BaseClientTest.php b/tests/TestCase/BaseClientTest.php index cda298c..b7750aa 100644 --- a/tests/TestCase/BaseClientTest.php +++ b/tests/TestCase/BaseClientTest.php @@ -436,7 +436,7 @@ public function sendRequest( string $path, ?array $query = null, ?array $headers = null, - $body = null + $body = null, ): ResponseInterface { throw new class extends BEditaClientException { public function __construct() diff --git a/tests/TestCase/MyBaseClient.php b/tests/TestCase/MyBaseClient.php index b5160c8..0123368 100644 --- a/tests/TestCase/MyBaseClient.php +++ b/tests/TestCase/MyBaseClient.php @@ -32,7 +32,7 @@ public function sendRequestRetry( string $path, ?array $query = null, ?array $headers = null, - $body = null + $body = null, ): ResponseInterface { return parent::sendRequestRetry($method, $path, $query, $headers, $body); } @@ -45,7 +45,7 @@ public function sendRequest( string $path, ?array $query = null, ?array $headers = null, - $body = null + $body = null, ): ResponseInterface { return parent::sendRequest($method, $path, $query, $headers, $body); } From 4ce077ba6a5abce21528a885ce00c6410d6dce7e Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Thu, 16 Oct 2025 17:15:27 +0200 Subject: [PATCH 05/11] chore fix: phpcs --- src/BEditaClient.php | 74 +++++++++++++++++++++++++++++++++++--------- src/BaseClient.php | 27 ++++++++++++---- 2 files changed, 80 insertions(+), 21 deletions(-) diff --git a/src/BEditaClient.php b/src/BEditaClient.php index 2e4211f..3fe43d8 100644 --- a/src/BEditaClient.php +++ b/src/BEditaClient.php @@ -72,7 +72,8 @@ public function bulkEdit(array $ids, array $data): array } catch (Exception $e) { $responseBody = $this->getResponseBody(); $status = $responseBody['error']['status']; - $message = intval($status) === 403 ? '[403] Forbidden' : ($responseBody['error']['message'] ?? $e->getMessage()); + $message = $responseBody['error']['message'] ?? $e->getMessage(); + $message = intval($status) === 403 ? '[403] Forbidden' : $message; $result['errors'][] = [ 'id' => $id, 'message' => $message, @@ -106,8 +107,12 @@ public function getObjects(string $type = 'objects', ?array $query = null, ?arra * @param array|null $headers Custom request headers * @return array|null Response in array format */ - public function getObject(string|int $id, string $type = 'objects', ?array $query = null, ?array $headers = null): ?array - { + public function getObject( + string|int $id, + string $type = 'objects', + ?array $query = null, + ?array $headers = null, + ): ?array { return $this->get(sprintf('/%s/%s', $type, $id), $query, $headers); } @@ -121,8 +126,13 @@ public function getObject(string|int $id, string $type = 'objects', ?array $quer * @param array|null $headers Custom request headers * @return array|null Response in array format */ - public function getRelated(string|int $id, string $type, string $relation, ?array $query = null, ?array $headers = null): ?array - { + public function getRelated( + string|int $id, + string $type, + string $relation, + ?array $query = null, + ?array $headers = null, + ): ?array { return $this->get(sprintf('/%s/%s/%s', $type, $id, $relation), $query, $headers); } @@ -136,9 +146,18 @@ public function getRelated(string|int $id, string $type, string $relation, ?arra * @param array|null $headers Custom request headers * @return array|null Response in array format */ - public function addRelated(string|int $id, string $type, string $relation, array $data, ?array $headers = null): ?array - { - return $this->post(sprintf('/%s/%s/relationships/%s', $type, $id, $relation), json_encode(compact('data')), $headers); + public function addRelated( + string|int $id, + string $type, + string $relation, + array $data, + ?array $headers = null, + ): ?array { + return $this->post( + sprintf('/%s/%s/relationships/%s', $type, $id, $relation), + json_encode(compact('data')), + $headers, + ); } /** @@ -151,9 +170,18 @@ public function addRelated(string|int $id, string $type, string $relation, array * @param array|null $headers Custom request headers * @return array|null Response in array format */ - public function removeRelated(string|int $id, string $type, string $relation, array $data, ?array $headers = null): ?array - { - return $this->delete(sprintf('/%s/%s/relationships/%s', $type, $id, $relation), json_encode(compact('data')), $headers); + public function removeRelated( + string|int $id, + string $type, + string $relation, + array $data, + ?array $headers = null, + ): ?array { + return $this->delete( + sprintf('/%s/%s/relationships/%s', $type, $id, $relation), + json_encode(compact('data')), + $headers, + ); } /** @@ -166,9 +194,23 @@ public function removeRelated(string|int $id, string $type, string $relation, ar * @param array|null $headers Custom request headers * @return array|null Response in array format */ - public function replaceRelated(string|int $id, string $type, string $relation, array $data, ?array $headers = null): ?array - { - return $this->patch(sprintf('/%s/%s/relationships/%s', $type, $id, $relation), json_encode(compact('data')), $headers); + public function replaceRelated( + string|int $id, + string $type, + string $relation, + array $data, + ?array $headers = null, + ): ?array { + return $this->patch( + sprintf( + '/%s/%s/relationships/%s', + $type, + $id, + $relation, + ), + json_encode(compact('data')), + $headers, + ); } /** @@ -366,7 +408,9 @@ public function addStreamToMedia(string $streamId, string $id, string $type): vo ]), ); if (empty($response)) { - throw new BEditaClientException('Invalid response from PATCH ' . sprintf('/streams/%s/relationships/object', $id)); + throw new BEditaClientException( + 'Invalid response from PATCH ' . sprintf('/streams/%s/relationships/object', $id), + ); } } diff --git a/src/BaseClient.php b/src/BaseClient.php index 77f9c0a..c535f07 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -245,8 +245,13 @@ public function refreshTokens(): void * @param \Psr\Http\Message\StreamInterface|resource|string|null $body Request body. * @return \Psr\Http\Message\ResponseInterface */ - protected function sendRequestRetry(string $method, string $path, ?array $query = null, ?array $headers = null, $body = null): ResponseInterface - { + protected function sendRequestRetry( + string $method, + string $path, + ?array $query = null, + ?array $headers = null, + $body = null, + ): ResponseInterface { try { return $this->sendRequest($method, $path, $query, $headers, $body); } catch (BEditaClientException $e) { @@ -275,8 +280,13 @@ protected function sendRequestRetry(string $method, string $path, ?array $query * @param \Psr\Http\Message\StreamInterface|resource|string|null $body Request body. * @return \Psr\Http\Message\ResponseInterface */ - protected function refreshAndRetry(string $method, string $path, ?array $query = null, ?array $headers = null, $body = null): ResponseInterface - { + protected function refreshAndRetry( + string $method, + string $path, + ?array $query = null, + ?array $headers = null, + $body = null, + ): ResponseInterface { $this->refreshTokens(); unset($headers['Authorization']); @@ -294,8 +304,13 @@ protected function refreshAndRetry(string $method, string $path, ?array $query = * @return \Psr\Http\Message\ResponseInterface * @throws \BEdita\SDK\BEditaClientException Throws an exception if server response code is not 20x. */ - protected function sendRequest(string $method, string $path, ?array $query = null, ?array $headers = null, $body = null): ResponseInterface - { + protected function sendRequest( + string $method, + string $path, + ?array $query = null, + ?array $headers = null, + $body = null, + ): ResponseInterface { $uri = $this->requestUri($path, $query); $headers = array_merge($this->defaultHeaders, (array)$headers); From 0ed2e665c648ef033d96638f27d11792ceca39fb Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Thu, 16 Oct 2025 17:18:56 +0200 Subject: [PATCH 06/11] feat: use php 8.3.26 in scrutinizer --- .scrutinizer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 0346e0e..5899b26 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -14,7 +14,7 @@ build: analysis: environment: php: - version: 8.3.3 + version: 8.3.26 tests: override: - php-scrutinizer-run From aeb04515fedbaf67ef76e531fdf7df2ed4f3005b Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 17 Oct 2025 08:09:00 +0200 Subject: [PATCH 07/11] fix: ids as integers --- src/BEditaClient.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/BEditaClient.php b/src/BEditaClient.php index 3fe43d8..8fc2080 100644 --- a/src/BEditaClient.php +++ b/src/BEditaClient.php @@ -51,12 +51,10 @@ public function bulkEdit(array $ids, array $data): array { $result = []; try { + $ids = array_map('intval', $ids); $result = (array)$this->post( '/bulk/edit', - json_encode([ - 'ids' => implode(',', $ids), - 'data' => $data, - ]), + json_encode(compact('ids', 'data')), ['Content-Type' => 'application/json'], ); } catch (Exception $e) { From abc4469f7f2711dd8f1a8996b4a71ddd063c6917 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 17 Oct 2025 08:17:05 +0200 Subject: [PATCH 08/11] fix: 409 ids dont match --- src/BEditaClient.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/BEditaClient.php b/src/BEditaClient.php index 8fc2080..04c0fb4 100644 --- a/src/BEditaClient.php +++ b/src/BEditaClient.php @@ -64,8 +64,7 @@ public function bulkEdit(array $ids, array $data): array foreach ($ids as $id) { try { $response = $this->getObject($id); - $type = $response['data']['type']; - $response = $this->save($type, $data + ['id' => $id]); + $response = $this->save($response['data']['type'], $data + ['id' => (string)$id]); $result['saved'][] = $response['data']['id']; } catch (Exception $e) { $responseBody = $this->getResponseBody(); From f27cf0a69718ce702acf1a927570d7e295ab0848 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 17 Oct 2025 13:54:43 +0200 Subject: [PATCH 09/11] feat: adjust payload and response --- src/BEditaClient.php | 55 +++++++++++++++++------------ tests/TestCase/BEditaClientTest.php | 14 ++++---- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/BEditaClient.php b/src/BEditaClient.php index 04c0fb4..f7d22d0 100644 --- a/src/BEditaClient.php +++ b/src/BEditaClient.php @@ -43,38 +43,49 @@ public function authenticate(string $username, string $password): ?array * Bulk edit objects using `POST /bulk/edit` endpoint. * If the endpoint is not available, it fallback to edit one by one (retrocompatible way). * - * @param array $ids Object ids - * @param array $data Data to modify + * $objects is an array of : , e.g.: + * [ + * 'articles' => [1,2,3], + * 'documents' => [4,5,6], + * ] + * + * The $attributes is an array of attributes to modify, e.g.: + * [ + * 'title' => 'New title', + * 'status' => 'off', + * ] + * + * @param array $objects Object data to indentify objects to edit + * @param array $attributes Data to modify * @return array */ - public function bulkEdit(array $ids, array $data): array + public function bulkEdit(array $objects, array $attributes): array { - $result = []; + $result = ['data' => ['saved' => [], 'errors' => []]]; try { - $ids = array_map('intval', $ids); $result = (array)$this->post( '/bulk/edit', - json_encode(compact('ids', 'data')), + json_encode(['data' => compact('attributes', 'objects')]), ['Content-Type' => 'application/json'], ); } catch (Exception $e) { - $result['saved'] = []; - $result['errors'] = []; // fallback to edit one by one, to be retrocompatible - foreach ($ids as $id) { - try { - $response = $this->getObject($id); - $response = $this->save($response['data']['type'], $data + ['id' => (string)$id]); - $result['saved'][] = $response['data']['id']; - } catch (Exception $e) { - $responseBody = $this->getResponseBody(); - $status = $responseBody['error']['status']; - $message = $responseBody['error']['message'] ?? $e->getMessage(); - $message = intval($status) === 403 ? '[403] Forbidden' : $message; - $result['errors'][] = [ - 'id' => $id, - 'message' => $message, - ]; + $types = array_keys($objects); + foreach ($types as $type) { + foreach ($objects[$type] as $id) { + try { + $response = $this->save($type, $attributes + ['id' => (string)$id]); + $result['data']['saved'][] = $response['data']['id']; + } catch (Exception $e) { + $responseBody = $this->getResponseBody(); + $status = $responseBody['error']['status']; + $message = $responseBody['error']['message'] ?? $e->getMessage(); + $message = intval($status) === 403 ? '[403] Forbidden' : $message; + $result['data']['errors'][] = [ + 'id' => $id, + 'message' => $message, + ]; + } } } } diff --git a/tests/TestCase/BEditaClientTest.php b/tests/TestCase/BEditaClientTest.php index b18e37b..d2883bb 100644 --- a/tests/TestCase/BEditaClientTest.php +++ b/tests/TestCase/BEditaClientTest.php @@ -168,9 +168,10 @@ public function testBulkEdit(): void ]), ['Content-Type' => 'application/vnd.api+json'], ); - $ids = [$id1, $id2]; - $data = ['status' => 'on']; - $response = $this->client->bulkEdit($ids, $data); + $objects = ['documents' => [$id1, $id2]]; + $attributes = ['status' => 'on']; + $response = $this->client->bulkEdit($objects, $attributes); + $response = $response['data']; static::assertNotEmpty($response); static::assertArrayHasKey('saved', $response); static::assertArrayNotHasKey('error', $response); @@ -223,9 +224,10 @@ public function post(string $path, ?string $body = null, ?array $headers = null) ]), ['Content-Type' => 'application/vnd.api+json'], ); - $ids = [$id1, $id2]; - $data = ['status' => 'on']; - $response = $client->bulkEdit($ids, $data); + $objects = ['documents' => [$id1, $id2]]; + $attributes = ['status' => 'on']; + $response = $client->bulkEdit($objects, $attributes); + $response = $response['data']; static::assertNotEmpty($response); static::assertArrayHasKey('saved', $response); static::assertArrayNotHasKey('error', $response); From 8148ab8c60d2818682b023669e060d96d56da98c Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Tue, 21 Oct 2025 10:51:16 +0200 Subject: [PATCH 10/11] tests: fix testEdit --- src/BEditaClient.php | 1 - tests/TestCase/BEditaClientTest.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/BEditaClient.php b/src/BEditaClient.php index f7d22d0..3f2358f 100644 --- a/src/BEditaClient.php +++ b/src/BEditaClient.php @@ -80,7 +80,6 @@ public function bulkEdit(array $objects, array $attributes): array $responseBody = $this->getResponseBody(); $status = $responseBody['error']['status']; $message = $responseBody['error']['message'] ?? $e->getMessage(); - $message = intval($status) === 403 ? '[403] Forbidden' : $message; $result['data']['errors'][] = [ 'id' => $id, 'message' => $message, diff --git a/tests/TestCase/BEditaClientTest.php b/tests/TestCase/BEditaClientTest.php index d2883bb..7f54b6e 100644 --- a/tests/TestCase/BEditaClientTest.php +++ b/tests/TestCase/BEditaClientTest.php @@ -176,7 +176,7 @@ public function testBulkEdit(): void static::assertArrayHasKey('saved', $response); static::assertArrayNotHasKey('error', $response); static::assertEquals([$id1], $response['saved']); - static::assertEquals([['id' => $id2, 'message' => '[403] Forbidden']], $response['errors']); + static::assertEquals([['id' => $id2, 'message' => 'Operation not allowed on "locked" objects']], $response['errors']); } /** @@ -232,7 +232,7 @@ public function post(string $path, ?string $body = null, ?array $headers = null) static::assertArrayHasKey('saved', $response); static::assertArrayNotHasKey('error', $response); static::assertEquals([$id1], $response['saved']); - static::assertEquals([['id' => $id2, 'message' => '[403] Forbidden']], $response['errors']); + static::assertEquals([['id' => $id2, 'message' => '[403] Not Found']], $response['errors']); } /** From b6752fd7085de086c7e3d1b4537d70109786a342 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Tue, 21 Oct 2025 10:54:11 +0200 Subject: [PATCH 11/11] chore fix: handle exception message --- src/BEditaClient.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/BEditaClient.php b/src/BEditaClient.php index 3f2358f..b7107c3 100644 --- a/src/BEditaClient.php +++ b/src/BEditaClient.php @@ -77,12 +77,9 @@ public function bulkEdit(array $objects, array $attributes): array $response = $this->save($type, $attributes + ['id' => (string)$id]); $result['data']['saved'][] = $response['data']['id']; } catch (Exception $e) { - $responseBody = $this->getResponseBody(); - $status = $responseBody['error']['status']; - $message = $responseBody['error']['message'] ?? $e->getMessage(); $result['data']['errors'][] = [ 'id' => $id, - 'message' => $message, + 'message' => $e->getMessage(), ]; } }