From a7814c8129022b536ec04dbb8ab70ca8804e4623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 31 Oct 2024 17:49:44 +0100 Subject: [PATCH] Fixed phpstan --- src/Controller/Api/EntryRestController.php | 7 +++++-- tests/Controller/Api/EntryRestControllerTest.php | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Controller/Api/EntryRestController.php b/src/Controller/Api/EntryRestController.php index b043449a5..001afe00b 100644 --- a/src/Controller/Api/EntryRestController.php +++ b/src/Controller/Api/EntryRestController.php @@ -798,9 +798,12 @@ class EntryRestController extends WallabagRestController $errors = $validator->validate($entry); if (\count($errors) > 0) { - $errorsString = (string) $errors; + $errorsString = ''; + foreach ($errors as $error) { + $errorsString .= $error->getMessage() . "\n"; + } - return $this->sendResponse($errorsString); + throw new BadRequestHttpException($errorsString); } $this->entityManager->persist($entry); diff --git a/tests/Controller/Api/EntryRestControllerTest.php b/tests/Controller/Api/EntryRestControllerTest.php index df9a6927f..e148d0c08 100644 --- a/tests/Controller/Api/EntryRestControllerTest.php +++ b/tests/Controller/Api/EntryRestControllerTest.php @@ -614,10 +614,10 @@ class EntryRestControllerTest extends WallabagApiTestCase 'public' => 1, ]); - $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(400, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertStringContainsString('The url \'"wallabagIsAwesome"\' is not a valid url', $content); + $this->assertStringContainsString('The url \'"wallabagIsAwesome"\' is not a valid url', $content['message']); } public function testPostEntry()