How can I access global variables inside PHPUnit 3.4.9?

I am trying to write tests for some legacy code with PHPUnit 3.4.9, but it seems that all my global variables are invisible.

How can I access global variables inside PHPUnit 3.4.9?

+4
source share
2 answers

They must be available. However, PHPUnit backs up the global state between tests:

By default, PHPUnit runs your tests in such a way that changes to global and superglobals ($ GLOBALS, $ _ENV, $ _POST, $ _GET, $ _COOKIE, $ _SERVER, $ _FILES, $ _REQUEST) do not affect other tests. Optionally, this isolation can be extended to static class attributes.

so this can be a problem. Also note that

Objects of some classes that are provided by PHP itself, such as PDO, cannot be serialized, and the backup operation is interrupted, for example, when such an object is stored in the $ GLOBALS array.

See the chapter Testing global state in the PHPUnit manual.

+3
source

Use this phpunit --no-globals-backup command phpunit --no-globals-backup

+1
source

Source: https://habr.com/ru/post/1306343/


All Articles