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

Yii2 as dependency of REST module #2562

moicirk opened this issue Nov 20, 2015 · 2 comments

Yii2 as dependency of REST module #2562

moicirk opened this issue Nov 20, 2015 · 2 comments


Copy link

@moicirk moicirk commented Nov 20, 2015

I use REST module to test my Yii2 application rest controllers so my functional tests config looks like this:

      - Yii2
      - REST

            configFile: 'codeception/config/functional.php'
            depends: Yii2

So REST module uses Yii2Connector as a client to send requests. Considering that REST module encodes parameters to JSON string Yii2 client gets only raw body message here:

$yiiRequest = $app->getRequest();
$yiiRequest->setBodyParams($_POST); //$_POST here is an empty array

Now, if we look at the yii\web\Request body parameters parsing we see this:

public function getBodyParams()
    if ($this->_bodyParams === null) {
    return $this->_bodyParams;

and _bodyParams here is an empty array, so I cannot get my payload and parse it as a json. Am I doing everything right?

My test example:

$I->haveHttpHeader('Content-Type', 'application/json');
$I->wantTo('Update one record');
$I->sendPUT('/api/controller', $data);

Record is not updated because raw body was not parsed

Copy link

@Naktibalda Naktibalda commented Nov 20, 2015

You missed the parsing part in getBodyParams:

* Request parameters are determined using the parsers configured in [[parsers]] property. * If no parsers are configured for the current [[contentType]] it uses the PHP functionmb_parse_str() * to parse the [[rawBody|request body]].

Have you configured a parser for application/json?

@Naktibalda Naktibalda added the Yii label Nov 20, 2015
Copy link

@moicirk moicirk commented Nov 21, 2015

My request component config:

'request' => [
    'cookieValidationKey' => 'mycookievalidationkey',
    'parsers' => [
        'application/json' => 'yii\web\JsonParser',

The problem is not in parsing itself. The Request never reached this point because in moment when getBodyParams is called the _bodyParams variable equals an empty array which is not NULL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.