Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

saltdg
Copy link

@saltdg saltdg commented Sep 25, 2024

No description provided.

Copy link
Member

@Arhell Arhell left a 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) {
Copy link
Member

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?

Copy link
Collaborator

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()
Copy link
Collaborator

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!

Comment on lines 36 to 42
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 &apos;Exception&apos; with message &apos;This is not an HttpException&apos;", $content);
}
Copy link
Collaborator

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!

Comment on lines +44 to 50
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 &apos;TypeError&apos; with message &apos;Cannot assign string to property', $content);
}
Copy link
Collaborator

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 &apos;TypeError&apos; with message &apos;Cannot assign string to property', $content);
Copy link
Collaborator

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) {
Copy link
Collaborator

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.

@SamMousa SamMousa added the do-not-merge Do not merge label Sep 26, 2024
@saltdg saltdg closed this by deleting the head repository Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge Do not merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants