Codeception / module-yii2

Codeception module for Yii2 framework
MIT License
16 stars 36 forks source link

Empty $_SERVER['QUERY_STRING'], which is used by \yii\web\Request #15

Closed ebuzzz closed 3 years ago

ebuzzz commented 3 years ago

At the moment, the connector initializes the following $_SERVER properties before doing a request:

$_SERVER['REQUEST_URI'] = $queryString === null ? $pathString : $pathString . '?' . $queryString;
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());

But the \yii\web\Request::getQueryString() method (and other parts of the Request class) searches for the $_SERVER['QUERY_STRING'] value, which is never set during tests. During normal operation of the application through the webserver, this value is available. This is resulting in failed tests for code that works fine during normal operation.

I fixed this issue on my end by adding the line;

$_SERVER['QUERY_STRING'] = $queryString;

But I'm not sure if there are any side-effects to this?

samdark commented 3 years ago

Looks valid and I see no possible side effects. Do you have some time for a pull request?

ebuzzz commented 3 years ago

Yes, I'll make a PR later today!

ebuzzz commented 3 years ago

Created as #16