Sync to master branch.

This commit is contained in:
Wilmer Arambula
2023-10-31 14:32:05 -03:00
16 changed files with 1112 additions and 130 deletions

View File

@@ -42,7 +42,50 @@ Message: This message is displayed to end user
Exception: yii\web\NotFoundHttpException', $out);
}
public function testClearAssetFilesInErrorView(): void
public function testFormatRaw()
{
Yii::$app->response->format = yii\web\Response::FORMAT_RAW;
/** @var ErrorHandler $handler */
$handler = Yii::$app->getErrorHandler();
ob_start(); // suppress response output
$this->invokeMethod($handler, 'renderException', [new \Exception('Test Exception')]);
$out = ob_get_clean();
$this->assertcontains('Test Exception', $out);
$this->assertTrue(is_string(Yii::$app->response->data));
$this->assertcontains("Exception 'Exception' with message 'Test Exception'", Yii::$app->response->data);
}
public function testFormatXml()
{
Yii::$app->response->format = yii\web\Response::FORMAT_XML;
/** @var ErrorHandler $handler */
$handler = Yii::$app->getErrorHandler();
ob_start(); // suppress response output
$this->invokeMethod($handler, 'renderException', [new \Exception('Test Exception')]);
$out = ob_get_clean();
$this->assertcontains('Test Exception', $out);
$outArray = Yii::$app->response->data;
$this->assertTrue(is_array(Yii::$app->response->data));
$this->assertEquals('Exception', $outArray['name']);
$this->assertEquals('Test Exception', $outArray['message']);
$this->assertArrayHasKey('code', $outArray);
$this->assertEquals('Exception', $outArray['type']);
$this->assertContains('ErrorHandlerTest.php', $outArray['file']);
$this->assertArrayHasKey('stack-trace', $outArray);
$this->assertArrayHasKey('line', $outArray);
}
public function testClearAssetFilesInErrorView()
{
Yii::$app->getView()->registerJsFile('somefile.js');
/** @var ErrorHandler $handler */