views:

155

answers:

1

Hi All,

I am writing some PHP code to parse incoming URLs. It relies heavily on PHP globals such as $_SERVER and $_GET. I am thinking of manually setting these up in PHPUnit unit test setUp() function. Is there a better way of doing this?

thanks,

G

+1  A: 

An idea would be to wrap $_SERVER and $_GET into classes instead of accessing them directly, so that you do not have to rely on them altogether. You see this approach frequently in the common frameworks. This way you can stub or mock the request easily without having to setup the state of the superglobals.

Please also see the chapter on Global State in the PHPUnit Manual

Gordon