@@ -42,6 +42,49 @@ public function testCorrectResponseCodeInErrorView()
42
42
Exception: yii\web\NotFoundHttpException ' , $ out );
43
43
}
44
44
45
+ public function testFormatRaw ()
46
+ {
47
+ Yii::$ app ->response ->format = yii \web \Response::FORMAT_RAW ;
48
+
49
+ /** @var ErrorHandler $handler */
50
+ $ handler = Yii::$ app ->getErrorHandler ();
51
+
52
+ ob_start (); // suppress response output
53
+ $ this ->invokeMethod ($ handler , 'renderException ' , [new \Exception ('Test Exception ' )]);
54
+ $ out = ob_get_clean ();
55
+
56
+ $ this ->assertcontains ('Test Exception ' , $ out );
57
+
58
+ $ this ->assertTrue (is_string (Yii::$ app ->response ->data ));
59
+ $ this ->assertcontains ("Exception 'Exception' with message 'Test Exception' " , Yii::$ app ->response ->data );
60
+ }
61
+
62
+ public function testFormatXml ()
63
+ {
64
+ Yii::$ app ->response ->format = yii \web \Response::FORMAT_XML ;
65
+
66
+ /** @var ErrorHandler $handler */
67
+ $ handler = Yii::$ app ->getErrorHandler ();
68
+
69
+ ob_start (); // suppress response output
70
+ $ this ->invokeMethod ($ handler , 'renderException ' , [new \Exception ('Test Exception ' )]);
71
+ $ out = ob_get_clean ();
72
+
73
+ $ this ->assertcontains ('Test Exception ' , $ out );
74
+
75
+ $ outArray = Yii::$ app ->response ->data ;
76
+
77
+ $ this ->assertTrue (is_array (Yii::$ app ->response ->data ));
78
+
79
+ $ this ->assertEquals ('Exception ' , $ outArray ['name ' ]);
80
+ $ this ->assertEquals ('Test Exception ' , $ outArray ['message ' ]);
81
+ $ this ->assertArrayHasKey ('code ' , $ outArray );
82
+ $ this ->assertEquals ('Exception ' , $ outArray ['type ' ]);
83
+ $ this ->assertContains ('ErrorHandlerTest.php ' , $ outArray ['file ' ]);
84
+ $ this ->assertArrayHasKey ('stack-trace ' , $ outArray );
85
+ $ this ->assertArrayHasKey ('line ' , $ outArray );
86
+ }
87
+
45
88
public function testClearAssetFilesInErrorView ()
46
89
{
47
90
Yii::$ app ->getView ()->registerJsFile ('somefile.js ' );
0 commit comments