Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable @backupGlobals for method while disabled for class #3142

Closed
Stadly opened this issue May 25, 2018 · 1 comment · Fixed by elecena/nano#2
Closed

Enable @backupGlobals for method while disabled for class #3142

Stadly opened this issue May 25, 2018 · 1 comment · Fixed by elecena/nano#2
Labels
type/bug Something is broken

Comments

@Stadly
Copy link
Contributor

Stadly commented May 25, 2018

Q A
PHPUnit version 7.1.1
PHP version 7.1.11
Installation Method Composer

It seems that @backupGlobals cannot be enabled for methods if it is disabled for the class. Consider the following test class.

/**
 * @backupGlobals disabled
 */
class Test extends \PHPUnit\Framework\TestCase {

    /**
     * @backupGlobals enabled
     */
    public function test1() {
        $GLOBALS['foo'] = 'bar';
        self::assertTrue(true);
    }

    public function test2() {
        self::assertFalse(isset($GLOBALS['foo']));
    }
}

Expected result: Both tests pass.
Actual result:

Test::test2()
Failed asserting that true is false.

If @backupGlobals is not disabled for the class by using the annotation, but just because it is disabled by default, both tests pass.

@Stadly
Copy link
Contributor Author

Stadly commented May 25, 2018

The same issue occurs when @backupGlobals is enabled for the class, but disabled for a method:

/**
* @backupGlobals enabled
*/
class Test extends TestCase {

   /**
    * @backupGlobals disabled
    */
   public function test1() {
       $GLOBALS['foo'] = 'bar';
       self::assertTrue(true);
   }

   public function test2() {
       self::assertTrue(isset($GLOBALS['foo']));
   }
}

Expected result: Both tests pass.
Actual result:

Test::test2()
Failed asserting that false is true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants