-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Yii2 ErrorHandler can not process when throw Error (#106) #107
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// to expect error response codes in tests. | ||
$app->errorHandler->discardExistingOutput = false; | ||
$app->errorHandler->handleException($e); | ||
} elseif (!$e instanceof ExitException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it necessary to remove this logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, see my comment in the issue itself. I am currently doubting whether the issue is valid at all.
@@ -44,6 +44,16 @@ public function actionEnd() | |||
\Yii::$app->end(); | |||
} | |||
|
|||
public function actionTypeError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a return type to any function you touch!
public function testException(FunctionalTester $I) | ||
{ | ||
$I->expectThrowable(new \Exception('This is not an HttpException'), function() use ($I) { | ||
$I->amOnRoute('/site/exception'); | ||
}); | ||
$I->assertInstanceOf(Application::class, \Yii::$app); | ||
$I->amOnRoute('/site/exception'); | ||
$I->seeResponseCodeIsServerError(); | ||
$content = $I->grabPageSource(); | ||
$I->assertStringStartsWith("<pre>Exception 'Exception' with message 'This is not an HttpException'", $content); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a return type to any function you touch!
public function testTypeError(FunctionalTester $I) | ||
{ | ||
$e = new \Exception('This is not an HttpException'); | ||
\Yii::$app->params['throw'] = $e; | ||
$I->expectThrowable($e, function() use ($I) { | ||
$I->amOnRoute('/site/exception'); | ||
}); | ||
$I->amOnRoute('/site/type-error'); | ||
$I->seeResponseCodeIsServerError(); | ||
$content = $I->grabPageSource(); | ||
$I->assertStringStartsWith('<pre>Exception 'TypeError' with message 'Cannot assign string to property', $content); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a return type to any function you touch!
$I->amOnRoute('/site/type-error'); | ||
$I->seeResponseCodeIsServerError(); | ||
$content = $I->grabPageSource(); | ||
$I->assertStringStartsWith('<pre>Exception 'TypeError' with message 'Cannot assign string to property', $content); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to check the string contains Cannot assign string to property
. Instead of the full HTML snippet.
// to expect error response codes in tests. | ||
$app->errorHandler->discardExistingOutput = false; | ||
$app->errorHandler->handleException($e); | ||
} elseif (!$e instanceof ExitException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, see my comment in the issue itself. I am currently doubting whether the issue is valid at all.
No description provided.