Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

issue.global

edsonmedina edited this page Dec 11, 2014 · 10 revisions

#Global variables

function foo () 
{
    global $bar;

    // ...
}

##Why is this a testing issue?

  • Global variables can be changed outside of the scope of your function, so its behaviour is unpredictable in a running environment.
  • It would force your test to set globals, which could then affect subsequent tests that depend on the same globals.
  • Unit-tests should only test units in isolation. Having external (global) dependencies breaks that rule.

##Possible solutions

####Pass the variable as an argument to your function.

function foo ($bar)  

####Get the values from some other source

$bar = $this->assets->get('bar');
Clone this wiki locally