lundi 5 octobre 2020

Set global variable in the class I am running unit tests on - phpunit

I have a function that is utilising a global variable, of which I am unsure where it is being set, that is the basis of a conditional. For example:

function myFunction($myLocalVariable) {
    $toReturn = '';

    if (isset($myGlobalVariable) && $myGlobalVariable == 'some-string') {
       $toReturn = 'Global var is set & equal to some-string';
    }

    return $toReturn;
}

Since I don't know how/where $myGlobalVariable is being set due to legacy/obfuscated code, is there any way I can force it to be seen as a specific value in my unit test?

Aucun commentaire:

Enregistrer un commentaire