phpyii2codeception

Fake IP on Codeception functional tests


I´m using Yii2 and Codeception to run tests.

When i run a functional test, the $SERVER['REMOTE_ADDR'] is not defined. How can i mockup the ip to use in those tests.

I have tried $SERVER['REMOTE_ADDR'] = '127.0.0.1', but it does not work.


Solution

    1. Find 2 files (if project built on yii2-app-basic template - remove from path dir common/):
      • common/config/codeception-local.php
      • environments/dev/common/config/codeception-local.php
    2. Add inside of array:
    [
        ...
        'on beforeAction' => static function () {
            $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
        },
        ...
    ]