From 92628c4c40c9dfe98e3f632ab4de8ab58bbe3689 Mon Sep 17 00:00:00 2001 From: Artem Lopata Date: Wed, 30 Oct 2024 01:28:48 +0100 Subject: [PATCH] If authentications fails - mark it as such. --- tests/Api/Auth/AbstractAuthTest.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/Api/Auth/AbstractAuthTest.php b/tests/Api/Auth/AbstractAuthTest.php index 48c19e8..f36b9c2 100644 --- a/tests/Api/Auth/AbstractAuthTest.php +++ b/tests/Api/Auth/AbstractAuthTest.php @@ -42,13 +42,21 @@ public function testJsonResponse() { $auth = $this->getMockForAbstractClass(AbstractAuth::class, [new Client()]); try { - $response = $auth->makeRequest($this->config['apiUrl'].'contacts'); - $this->assertTrue(is_array($response)); - $this->assertFalse(empty($response)); + $auth->makeRequest($this->config['apiUrl'].'contacts'); + self::fail('This should not happen, as the API does not have the authentication.'); } catch (UnexpectedResponseFormatException $exception) { - $response = json_decode($exception->getResponse()->getBody(), true); - $this->assertTrue(is_array($response)); - $this->assertFalse(empty($response)); + $body = $exception->getResponse()->getBody(); + try { + $response = json_decode($body, true, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + if ('' === $body) { + $body = '(empty string)'; + } + + self::fail('Mautic returned wrong json response: '.$body.'. JSON exception: '.$e->getMessage()); + } + $this->assertIsArray($response, $body); + $this->assertGreaterThan(0, count($response)); } } }