News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sebastian Bergmann's Blog:
Global Variables and PHPUnit
June 17, 2008 @ 08:49:19

Sebastian Bergmann has a new post today about a feature of the PHPUnit unit testing tool that has the possibility of breaking when objects are introduced - backing up the globals.

It is hard to test code that uses singletons. The same is true for code that uses global variables. Typically, the code you want to test is coupled strongly with a global variable and you cannot control its creation. An additional problem is the fact that one test's change to a global variable might break another test.

You can disable the backup option if you'd like by setting the $backupGlobals option in your test to false. This lets PHPUnit know that you want to leave the globals (and superglobals) alone during the run.

0 comments voice your opinion now!
global variable phpunit unittest backup global superglobal test disable


blog comments powered by Disqus

Similar Posts

Lars Tesmer's Blog: How to Unit Test a Class Making Calls to an URL (or the Filesystem) With PHPUnit

Zend Developer Zone: Creating Code Coverage Statistics with xdebug

Michelangelo van Dam's Blog: Quality Assurance on PHP projects - PHPUnit part 4

Zend Developer Zone: Webinar - How Zend Used Adobe Flex & PHP to Build a Software Flight Recorder

Volker Dusch's Blog: Textual code coverage information for PHPUnit


Community Events

Don't see your event here?
Let us know!


community framework configure api composer introduction part2 interview php7 project symfony list language yii2 opinion application series laravel podcast example

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework