@backupGlobals

@backupGlobals

The backup and restore operations for global variables can be completely disabled for all tests of a test case class like this

1
2
3
4
5
6
7
8
9
use PHPUnit\Framework\TestCase;
 
/**
 * @backupGlobals disabled
 */
class MyTest extends TestCase
{
    // ...
}

The @backupGlobals annotation can also be used on the test method level. This allows for a fine-grained configuration of the backup and restore operations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use PHPUnit\Framework\TestCase;
 
/**
 * @backupGlobals disabled
 */
class MyTest extends TestCase
{
    /**
     * @backupGlobals enabled
     */
    public function testThatInteractsWithGlobalVariables()
    {
        // ...
    }
}
doc_PHPUnit
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.