Refactored HttpExceptions.

This commit is contained in:
Dmitry Khomutov 2018-03-04 17:14:09 +07:00
commit aadfabd714
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
27 changed files with 54 additions and 57 deletions

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\b8;
namespace Tests\PHPCensor;
use PHPCensor\Config;
use PHPCensor\Database;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\b8;
namespace Tests\PHPCensor;
use PHPCensor\Config;
use PHPCensor\Database;

View file

@ -0,0 +1,86 @@
<?php
namespace Tests\PHPCensor;
use PHPCensor\Exception\HttpException;
class HttpExceptionTest extends \PHPUnit\Framework\TestCase
{
public function testHttpExceptionIsException()
{
$ex = new HttpException();
self::assertTrue($ex instanceof \Exception);
}
public function testHttpException()
{
try {
throw new HttpException('Test');
} catch (HttpException $ex) {
self::assertTrue($ex->getMessage() == 'Test');
self::assertTrue($ex->getErrorCode() == 500);
self::assertTrue($ex->getStatusMessage() == 'Internal Server Error');
self::assertTrue($ex->getHttpHeader() == 'HTTP/1.1 500 Internal Server Error');
}
}
public function testBadRequestException()
{
try {
throw new HttpException\BadRequestException('Test');
} catch (HttpException $ex) {
self::assertTrue($ex->getErrorCode() == 400);
self::assertTrue($ex->getStatusMessage() == 'Bad Request');
}
}
public function testForbiddenException()
{
try {
throw new HttpException\ForbiddenException('Test');
} catch (HttpException $ex) {
self::assertTrue($ex->getErrorCode() == 403);
self::assertTrue($ex->getStatusMessage() == 'Forbidden');
}
}
public function testNotAuthorizedException()
{
try {
throw new HttpException\NotAuthorizedException('Test');
} catch (HttpException $ex) {
self::assertTrue($ex->getErrorCode() == 401);
self::assertTrue($ex->getStatusMessage() == 'Not Authorized');
}
}
public function testNotFoundException()
{
try {
throw new HttpException\NotFoundException('Test');
} catch (HttpException $ex) {
self::assertTrue($ex->getErrorCode() == 404);
self::assertTrue($ex->getStatusMessage() == 'Not Found');
}
}
public function testServerErrorException()
{
try {
throw new HttpException\ServerErrorException('Test');
} catch (HttpException $ex) {
self::assertTrue($ex->getErrorCode() == 500);
self::assertTrue($ex->getStatusMessage() == 'Internal Server Error');
}
}
public function testValidationException()
{
try {
throw new HttpException\ValidationException('Test');
} catch (HttpException $ex) {
self::assertTrue($ex->getErrorCode() == 400);
self::assertTrue($ex->getStatusMessage() == 'Bad Request');
}
}
}

View file

@ -2,9 +2,8 @@
namespace Tests\PHPCensor\Model;
use b8\Exception\HttpException\ValidationException;
use PHPCensor\Exception\HttpException\ValidationException;
use PHPCensor\Model\Build;
use PHPCensor\Model;
/**
* Unit tests for the Build model class.