php-censor/tests/B8Framework/HttpExceptionTest.php

86 lines
2.6 KiB
PHP
Raw Normal View History

2016-04-12 19:31:39 +02:00
<?php
2016-04-17 08:34:12 +02:00
namespace Tests\b8;
2016-04-12 19:31:39 +02:00
2016-04-17 08:34:12 +02:00
use b8\Exception\HttpException;
2016-04-12 19:31:39 +02:00
class HttpExceptionTest extends \PHPUnit_Framework_TestCase
{
2016-04-21 19:06:58 +02:00
public function testHttpExceptionIsException()
{
$ex = new HttpException();
$this->assertTrue($ex instanceof \Exception);
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testHttpException()
{
try {
throw new HttpException('Test');
} catch (HttpException $ex) {
$this->assertTrue($ex->getMessage() == 'Test');
$this->assertTrue($ex->getErrorCode() == 500);
$this->assertTrue($ex->getStatusMessage() == 'Internal Server Error');
$this->assertTrue($ex->getHttpHeader() == 'HTTP/1.1 500 Internal Server Error');
}
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testBadRequestException()
{
try {
throw new HttpException\BadRequestException('Test');
} catch (HttpException $ex) {
$this->assertTrue($ex->getErrorCode() == 400);
$this->assertTrue($ex->getStatusMessage() == 'Bad Request');
}
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testForbiddenException()
{
try {
throw new HttpException\ForbiddenException('Test');
} catch (HttpException $ex) {
$this->assertTrue($ex->getErrorCode() == 403);
$this->assertTrue($ex->getStatusMessage() == 'Forbidden');
}
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testNotAuthorizedException()
{
try {
throw new HttpException\NotAuthorizedException('Test');
} catch (HttpException $ex) {
$this->assertTrue($ex->getErrorCode() == 401);
$this->assertTrue($ex->getStatusMessage() == 'Not Authorized');
}
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testNotFoundException()
{
try {
throw new HttpException\NotFoundException('Test');
} catch (HttpException $ex) {
$this->assertTrue($ex->getErrorCode() == 404);
$this->assertTrue($ex->getStatusMessage() == 'Not Found');
}
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testServerErrorException()
{
try {
throw new HttpException\ServerErrorException('Test');
} catch (HttpException $ex) {
$this->assertTrue($ex->getErrorCode() == 500);
$this->assertTrue($ex->getStatusMessage() == 'Internal Server Error');
}
}
2016-04-12 19:31:39 +02:00
2016-04-21 19:06:58 +02:00
public function testValidationException()
{
try {
throw new HttpException\ValidationException('Test');
} catch (HttpException $ex) {
$this->assertTrue($ex->getErrorCode() == 400);
$this->assertTrue($ex->getStatusMessage() == 'Bad Request');
}
}
2016-04-12 19:31:39 +02:00
}