Fake $_SERVER variables in phpUnit

B. Rentrug

I'm still new to phpUnit and I can't make my (very simple) test work.


use PHPUnit\Framework\TestCase;

class userTest extends TestCase {
    public function testTrue() {

        //  This line wont work without autloader.php
        $user = new User();

The problem is that I need to load all my classes from autoloader.php:

<?xml version="1.0" encoding="UTF-8"?>
    <phpunit bootstrap="inc/autoload.php"></phpunit>

But I'n those classes I have a lot of $SERVER variables, like


This is the error I get:

Notice: Undefined index: REMOTE_ADDR in /Applications/MAMP/htdocs/sakkadentrainer/classes/App.php on line 674

How can I make those variables work? I would prefer to kind of "fake" them as env.variables from the phpunit.xml file, but I don't know if that's possible.

Thanks for you help!

My Setup: php 7.1.2, phpUnit 6.1.1, macOs Mojave, MAMP

SOLUTION: https://phpunit.de/manual/6.5/en/appendixes.configuration.html#appendixes.configuration.php-ini-constants-variables


Referring to the Doc, you can Setting PHP INI settings, Constants and Global Variables, as example:

  <server name="REMOTE_ADDR" value=""/>

Hope this help

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em

deixe-me dizer algumas palavras

loginDepois de participar da revisão

Artigos relacionados

TOP lista