forked from ems-project/elasticms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ai/common): add CoreApi/Endpoint/Exception/
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/BaseUrlNotDefinedExceptionAiTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EMS\CommonBundle\Tests\Unit\Common\CoreApi\Exception; | ||
|
||
use EMS\CommonBundle\Common\CoreApi\Exception\BaseUrlNotDefinedException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BaseUrlNotDefinedExceptionAiTest extends TestCase | ||
{ | ||
public function testExceptionDefaultMessage(): void | ||
{ | ||
$exception = new BaseUrlNotDefinedException(); | ||
|
||
$expectedMessage = 'Core api base url not defined!'; | ||
$this->assertEquals($expectedMessage, $exception->getMessage()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/NotAuthenticatedExceptionAiTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EMS\CommonBundle\Tests\Unit\Common\CoreApi\Exception; | ||
|
||
use EMS\CommonBundle\Common\CoreApi\Exception\NotAuthenticatedException; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Contracts\HttpClient\ResponseInterface; | ||
|
||
class NotAuthenticatedExceptionAiTest extends TestCase | ||
{ | ||
public function testExceptionMessageAndCode(): void | ||
{ | ||
$httpCode = 401; | ||
$httpMethod = 'GET'; | ||
$url = 'https://example.com/api/resource'; | ||
|
||
$response = $this->createMock(ResponseInterface::class); | ||
$response->method('getInfo') | ||
->willReturn([ | ||
'http_code' => $httpCode, | ||
'http_method' => $httpMethod, | ||
'url' => $url, | ||
]); | ||
$response->method('getStatusCode')->willReturn($httpCode); | ||
|
||
$exception = new NotAuthenticatedException($response); | ||
|
||
$expectedMessage = \sprintf('%s Unauthorized for [%s] %s', $httpCode, $httpMethod, $url); | ||
$this->assertEquals($expectedMessage, $exception->getMessage()); | ||
$this->assertEquals($httpCode, $exception->getCode()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/NotSuccessfulExceptionAiTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EMS\CommonBundle\Tests\Unit\Common\CoreApi\Exception; | ||
|
||
use EMS\CommonBundle\Common\CoreApi\Exception\NotSuccessfulException; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Contracts\HttpClient\ResponseInterface; | ||
|
||
class NotSuccessfulExceptionAiTest extends TestCase | ||
{ | ||
public function testExceptionMessage(): void | ||
{ | ||
$response = $this->createMock(ResponseInterface::class); | ||
$response->method('getInfo') | ||
->willReturn([ | ||
'http_method' => 'GET', | ||
'url' => 'https://example.com/api/test', | ||
]); | ||
$response->method('getStatusCode') | ||
->willReturn(404); | ||
|
||
$exception = new NotSuccessfulException($response); | ||
|
||
$expectedMessage = '[GET] https://example.com/api/test was not successful! (Check logs!)'; | ||
$this->assertEquals($expectedMessage, $exception->getMessage()); | ||
$this->assertEquals(404, $exception->getCode()); | ||
} | ||
} |