This commit is contained in:
41
tests/Unit/ResponseTest.php
Normal file
41
tests/Unit/ResponseTest.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use QdbHttpResponse;
|
||||
|
||||
final class ResponseTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
require_once dirname(__DIR__, 2) . '/lib/response.php';
|
||||
}
|
||||
|
||||
public function testJsonSuccessEnvelope(): void
|
||||
{
|
||||
try {
|
||||
json_success(['token' => 'abc'], 201);
|
||||
$this->fail('Expected QdbHttpResponse');
|
||||
} catch (QdbHttpResponse $e) {
|
||||
$this->assertSame(201, $e->status);
|
||||
$this->assertTrue($e->body['ok']);
|
||||
$this->assertSame(['token' => 'abc'], $e->body['data']);
|
||||
}
|
||||
}
|
||||
|
||||
public function testJsonErrorEnvelope(): void
|
||||
{
|
||||
try {
|
||||
json_error('INVALID_CREDENTIALS', 'Bad login', 401);
|
||||
$this->fail('Expected QdbHttpResponse');
|
||||
} catch (QdbHttpResponse $e) {
|
||||
$this->assertSame(401, $e->status);
|
||||
$this->assertFalse($e->body['ok']);
|
||||
$this->assertSame('INVALID_CREDENTIALS', $e->body['error']['code']);
|
||||
$this->assertSame('Bad login', $e->body['error']['message']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user