R
R
rumasterov2016-04-27 19:19:39
Yii
rumasterov, 2016-04-27 19:19:39

Yii2 and Codeception: why is Stub not working for Request component?

Hello.
I am writing a functional test in Codeception, I want to replace the getUserIP () method of the Request component, for this I create a Stub and register it in the application:

$requestStub = Stub::make(\yii\web\Request::class, ['getUserIP' => function () return '192.168.0.10'; }]);
\Yii::$app->set('request', $requestStub);

I run the test and get the error:
[yii\base\ErrorException] Undefined index: SCRIPT_FILENAME

I start looking in more detail, the error appears in yii2\web\Request.php:
public function getScriptFile()
{
    return isset($this->_scriptFile) ? $this->_scriptFile : $_SERVER['SCRIPT_FILENAME'];
} 

I write an error_log inside this method and log the contents of the $_SERVER variable, run a functional test and see in the log that there is a SCRIPT_FILENAME index.
How can such an error occur if there is an index?
Has anyone come across this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elena Stepanova, 2016-04-27
@Insolita

Do other functional tests work? this looks like a bug with a functional test misconfiguration

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question