Skip to content

Commit

Permalink
Merge pull request #331 from biozshock/authentication-deprecations
Browse files Browse the repository at this point in the history
If authentications fails - mark it as such.
  • Loading branch information
escopecz authored Oct 31, 2024
2 parents 9506c09 + 92628c4 commit 7effc2f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tests/Api/Auth/AbstractAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

0 comments on commit 7effc2f

Please sign in to comment.