0

I'm trying to write some acceptance tests for yii2 application.

I my SiteController I have some action, which include the following piece of code:

if (!Yii::$app->request->isPost) {
        throw new NotFoundHttpException('Unexpected GET method');
    }

When I'm trying to test this action - it's always FAILED, because my POST requests don't passed this check Yii::$app->request->isPost . They always have $_SERVER['REQUEST_METHOD'] = 'GET' instead of POST.

I tried this variants:

$I->sendPOST($url, $options)

$I->sendAjaxPostRequest($url, $options)

Also I tried to make custom actions in Helper like this

public function makePOST($url, $params = []) {
    $this->getModule('PhpBrowser')->_loadPage('POST', $url, $params);
}

And then call it from my test. In all cases I'm getting GET request instead of POST...

Please help me to understand why it happens.

1 Answer 1

-1

Maybe the reason is CSRF?

Yii2 documentation CSRF

Warning: Disabling CSRF will allow any site to send POST requests to your site. It is important to implement extra validation such as checking an IP address or a secret token in this case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.