Anton Terekhov
12 years ago
78 changed files with 797 additions and 404 deletions
-
2Config.php
-
2Load.php
-
2Registry.php
-
2app/Action.php
-
29app/AjaxAction.php
-
10app/CliController.php
-
43app/ErrorAction.php
-
17app/FrontController.php
-
2app/PagerAction.php
-
2app/StaticAction.php
-
3app/router/Route.php
-
21app/router/Router.php
-
5cache/Cache.php
-
5cache/CacheKey.php
-
8cache/Cacher.php
-
11cache/MemcacheCache.php
-
2captcha/Captcha.php
-
2captcha/CaptchaImageAction.php
-
2captcha/CaptchaValidator.php
-
2classes/Env.class.php
-
6classes/Format.class.php
-
3classes/User.class.php
-
9exception/Error404Exception.php
-
39exception/ErrorHTTPException.php
-
3exception/ErrorHandler.php
-
2exception/GeneralException.php
-
34form/Form.php
-
51form/FormField.php
-
2form/FormViewHelper.php
-
5i18n/I18N.php
-
2layout/Error.layout.php
-
8layout/Layout.php
-
3logger/FileLogger.php
-
2mail/Mailer.php
-
2model/Db.php
-
2model/DbDriver.php
-
2model/DbExpr.php
-
2model/DbStatement.php
-
2model/Model.php
-
1model/MongoStatement.php
-
2model/MySQLiDriver.php
-
2model/MySQLiStatement.php
-
2redis/RedisDebug.php
-
5redis/RedisManager.php
-
3redis/redis.php
-
2session/Session.model.php
-
2session/Session.php
-
5tests/LoadTest.php
-
15tests/app/Action_TestCase.php
-
48tests/app/AjaxActionTest.php
-
1tests/app/CliControllerTest.php
-
41tests/app/ErrorActionTest.php
-
66tests/app/FrontControllerTest.php
-
11tests/exception/Error404ExceptionTest.php
-
106tests/exception/ErrorHTTPExceptionTest.php
-
2tests/form/FormFieldTest.php
-
6tests/view/helpers/BreadcrumbVeiwHelperTest.php
-
4tests/view/helpers/GetViewHelperTest.php
-
3tests/view/helpers/HeadViewHelperTest.php
-
32tests/view/helpers/MsgViewHelperTest.php
-
4tests/view/helpers/TitleViewHelperTest.php
-
16util/AutoloadBuilder.php
-
2util/profiler/CommandProfiler.php
-
11util/profiler/Profiler.php
-
2validator/EmailValidator.php
-
2validator/EqualValidator.php
-
2validator/NotEmptyValidator.php
-
2validator/RegexValidator.php
-
2validator/Validator.php
-
2validator/iValidator.php
-
16view/PHPView.php
-
2view/helpers/BreadcrumbViewHelper.php
-
4view/helpers/GetViewHelper.php
-
2view/helpers/HeadViewHelper.php
-
40view/helpers/MsgViewHelper.php
-
2view/helpers/TitleViewHelper.php
-
2view/helpers/ViewHelper.php
-
2view/iView.php
@ -0,0 +1,39 @@ |
|||
<?php |
|||
/** |
|||
* @copyright NetMonsters <team@netmonsters.ru> |
|||
* @link http://netmonsters.ru |
|||
* @package Majestic |
|||
* @subpackage exception |
|||
* @since 2012-11-11 |
|||
*/ |
|||
|
|||
class ErrorHTTPException extends GeneralException |
|||
{ |
|||
protected $http_headers; |
|||
|
|||
public function __construct($message = "", $code = 0, Exception $previous = null) |
|||
{ |
|||
$this->http_headers = array( |
|||
400 => 'HTTP/1.0 400 Bad Request', |
|||
402 => 'HTTP/1.0 402 Payment Required', |
|||
403 => 'HTTP/1.0 403 Forbidden', |
|||
404 => 'HTTP/1.0 404 Not Found', |
|||
410 => 'HTTP/1.0 410 Gone', |
|||
500 => 'HTTP/1.0 500 Internal Server Error', |
|||
501 => 'HTTP/1.0 501 Not Implemented', |
|||
503 => 'HTTP/1.0 503 Service Unavailable', |
|||
); |
|||
|
|||
if ($code === 200) { |
|||
throw new GeneralException('Can\'t send 200 via ErrorHTTPException', 0, $this); |
|||
} elseif (!array_key_exists($code, $this->http_headers)) { |
|||
throw new GeneralException('Incorrect HTTP code ' . $code . '.', 0, $this); |
|||
} |
|||
parent::__construct($message, $code, $previous); |
|||
} |
|||
|
|||
public function getHTTPHeader() |
|||
{ |
|||
return $this->http_headers[$this->code]; |
|||
} |
|||
} |
@ -0,0 +1,106 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* @copyright NetMonsters <team@netmonsters.ru> |
|||
* @link http://netmonsters.ru |
|||
* @package Majestic |
|||
* @subpackage UnitTests |
|||
* @since 2011-10-11 |
|||
* |
|||
* Unit tests for Error404Exception class |
|||
*/ |
|||
|
|||
require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; |
|||
require_once dirname(__FILE__) . '/../../exception/ErrorHTTPException.php'; |
|||
require_once dirname(__FILE__) . '/../../exception/Error404Exception.php'; |
|||
|
|||
class ErrorHTTPExceptionTest extends PHPUnit_Framework_TestCase |
|||
{ |
|||
public function testErrorHTTPException() |
|||
{ |
|||
$this->setExpectedException('ErrorHTTPException', 404); |
|||
throw new ErrorHTTPException('Some error occurred', 400); |
|||
} |
|||
|
|||
public function testErrorHTTPExceptionMessage() |
|||
{ |
|||
$this->setExpectedException('ErrorHTTPException', 'ErrorHTTPException message', 410); |
|||
throw new ErrorHTTPException('ErrorHTTPException message', 410); |
|||
} |
|||
|
|||
public function testErrorHTTPExceptionWithPrevious() |
|||
{ |
|||
$this->setExpectedException('ErrorHTTPException', 'ErrorHTTPException message', 500); |
|||
throw new ErrorHTTPException('ErrorHTTPException message', 500, new ErrorException('Error message')); |
|||
} |
|||
|
|||
/** |
|||
* @dataProvider providerHTTPCode |
|||
*/ |
|||
public function testGetHTTPHeader($message, $code, $header) |
|||
{ |
|||
try { |
|||
throw new ErrorHTTPException($message, $code, new ErrorException('Error message')); |
|||
} |
|||
catch (ErrorHTTPException $e) { |
|||
$this->assertSame($header, $e->getHTTPHeader()); |
|||
$this->assertSame($message, $e->getMessage()); |
|||
$this->assertSame($code, $e->getCode()); |
|||
$this->assertEquals(new ErrorException('Error message'), $e->getPrevious()); |
|||
} |
|||
} |
|||
|
|||
public function providerHTTPCode() |
|||
{ |
|||
return array( |
|||
array('ErrorHTTPException message for 400', 400, 'HTTP/1.0 400 Bad Request'), |
|||
array('ErrorHTTPException message for 402', 402, 'HTTP/1.0 402 Payment Required'), |
|||
array('ErrorHTTPException message for 403', 403, 'HTTP/1.0 403 Forbidden'), |
|||
array('ErrorHTTPException message for 404', 404, 'HTTP/1.0 404 Not Found'), |
|||
array('ErrorHTTPException message for 410', 410, 'HTTP/1.0 410 Gone'), |
|||
array('ErrorHTTPException message for 500', 500, 'HTTP/1.0 500 Internal Server Error'), |
|||
array('ErrorHTTPException message for 501', 501, 'HTTP/1.0 501 Not Implemented'), |
|||
array('ErrorHTTPException message for 503', 503, 'HTTP/1.0 503 Service Unavailable'), |
|||
); |
|||
} |
|||
|
|||
public function testErrorHTTPException200() |
|||
{ |
|||
try { |
|||
throw new ErrorHTTPException('ErrorHTTPException message', 200, new ErrorException('Error message')); |
|||
} |
|||
catch (ErrorHTTPException $e) { |
|||
$this->fail(); |
|||
} |
|||
catch (GeneralException $e) { |
|||
$this->assertSame('Can\'t send 200 via ErrorHTTPException', $e->getMessage()); |
|||
} |
|||
} |
|||
|
|||
public function testErrorHTTPExceptionBadCode() |
|||
{ |
|||
try { |
|||
throw new ErrorHTTPException('ErrorHTTPException message', 100, new ErrorException('Error message')); |
|||
} |
|||
catch (ErrorHTTPException $e) { |
|||
$this->fail(); |
|||
} |
|||
catch (GeneralException $e) { |
|||
$this->assertSame('Incorrect HTTP code 100.', $e->getMessage()); |
|||
} |
|||
} |
|||
|
|||
public function testErrorHTTPExceptionGoodCode() |
|||
{ |
|||
try { |
|||
throw new ErrorHTTPException('ErrorHTTPException message', 400, new ErrorException('Error message')); |
|||
} |
|||
catch (ErrorHTTPException $e) { |
|||
$this->assertSame(400, $e->getCode()); |
|||
} |
|||
catch (GeneralException $e) { |
|||
$this->fail(); |
|||
} |
|||
} |
|||
} |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue