Alexander Makarov
8 years ago
committed by
GitHub
8 changed files with 106 additions and 17 deletions
@ -0,0 +1,12 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @var Exception $exception |
||||
*/ |
||||
|
||||
?> |
||||
Code: <?= Yii::$app->response->statusCode ?> |
||||
|
||||
Message: <?= $exception->getMessage() ?> |
||||
|
||||
Exception: <?= get_class($exception) ?> |
@ -0,0 +1,45 @@
|
||||
<?php |
||||
|
||||
namespace yiiunit\framework\web; |
||||
|
||||
use Yii; |
||||
use yii\web\NotFoundHttpException; |
||||
use yiiunit\TestCase; |
||||
|
||||
class ErrorHandlerTest extends TestCase |
||||
{ |
||||
protected function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
$this->mockWebApplication([ |
||||
'components' => [ |
||||
'errorHandler' => [ |
||||
'class' => 'yiiunit\framework\web\ErrorHandler', |
||||
'errorView' => '@yiiunit/data/views/errorHandler.php', |
||||
], |
||||
], |
||||
]); |
||||
} |
||||
|
||||
public function testCorrectResponseCodeInErrorView() |
||||
{ |
||||
/** @var ErrorHandler $handler */ |
||||
$handler = Yii::$app->getErrorHandler(); |
||||
$this->invokeMethod($handler, 'renderException', [new NotFoundHttpException('This message is displayed to end user')]); |
||||
$out = Yii::$app->response->data; |
||||
$this->assertEquals('Code: 404 |
||||
Message: This message is displayed to end user |
||||
Exception: yii\web\NotFoundHttpException', $out); |
||||
} |
||||
} |
||||
|
||||
class ErrorHandler extends \yii\web\ErrorHandler |
||||
{ |
||||
/** |
||||
* @return bool if simple HTML should be rendered |
||||
*/ |
||||
protected function shouldRenderSimpleHtml() |
||||
{ |
||||
return false; |
||||
} |
||||
} |
Loading…
Reference in new issue