问题
I try to test my app with codeception, but all LoginCept.php breaks on this aciton
class SiteController extends Controller {
public function actionIndex() {
$this->redirect('journal');
}
}
As I can see in the php-buildin-server's logs, after in-app redirect it comes to actual entry point index.php instead of index-test.php
[Thu Jun 9 20:54:00 2016] 127.0.0.1:40472 [302]: /index-test.php/login
[Thu Jun 9 20:54:00 2016] 127.0.0.1:40496 [302]: /index-test.php << in-app redirect
[Thu Jun 9 20:54:00 2016] 127.0.0.1:40506 [500]: /journal
So test fails due to this unexpected behavior. How to enforce application's redirects to work at the same entry point script?
回答1:
Need to wrap URI into Url::to() to add all stuff, that yii2 uses. So funciton call should looks like this
$this->redirect(Url::to('to/something'));
来源:https://stackoverflow.com/questions/37727689/testing-action-with-redirect-gives-uexpectable-behavior-in-yii2