Skip to content

Commit

Permalink
minor #5613 DX: UtilsTest - add missing teardown (keradus)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.19-dev branch.

Discussion
----------

DX: UtilsTest - add missing teardown

showing the issue:
```
ker@dus:~/github/PHP-CS-Fixer λ git du
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index 122db36c7..4a0db6acc 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -298,6 +298,7 @@ public function provideCalculateBitmaskCases()
     public function testTriggerDeprecationWhenFutureModeIsOff()
     {
         putenv('PHP_CS_FIXER_FUTURE_MODE=0');
+        var_dump(["method" => __METHOD__, "PHP_CS_FIXER_FUTURE_MODE env var" => getenv('PHP_CS_FIXER_FUTURE_MODE')]);

         $this->expectDeprecation('The message');

@@ -307,6 +308,7 @@ public function testTriggerDeprecationWhenFutureModeIsOff()
     public function testTriggerDeprecationWhenFutureModeIsOn()
     {
         putenv('PHP_CS_FIXER_FUTURE_MODE=1');
+        var_dump(["method" => __METHOD__, "PHP_CS_FIXER_FUTURE_MODE env var" => getenv('PHP_CS_FIXER_FUTURE_MODE')]);

         $this->expectException(\DomainException::class);
         $this->expectExceptionMessage('The message');
@@ -314,6 +316,12 @@ public function testTriggerDeprecationWhenFutureModeIsOn()
         Utils::triggerDeprecation('The message', \DomainException::class);
     }

+    public function testXXX()
+    {
+        var_dump(["method" => __METHOD__, "PHP_CS_FIXER_FUTURE_MODE env var" => getenv('PHP_CS_FIXER_FUTURE_MODE')]);
+        $this->assertTrue(true);
+    }
+
     private function createFixerDouble($name, $priority)
     {
         $fixer = $this->prophesize(FixerInterface::class);

```

execution:
```
ker@dus:~/github/PHP-CS-Fixer λ vendor/bin/phpunit tests/UtilsTest.php
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

Testing PhpCsFixer\Tests\UtilsTest
......................................Rarray(2) {
  ["method"]=>
  string(69) "PhpCsFixer\Tests\UtilsTest::testTriggerDeprecationWhenFutureModeIsOff"
  ["PHP_CS_FIXER_FUTURE_MODE env var"]=>
  string(1) "0"
}
Rarray(2) {
  ["method"]=>
  string(68) "PhpCsFixer\Tests\UtilsTest::testTriggerDeprecationWhenFutureModeIsOn"
  ["PHP_CS_FIXER_FUTURE_MODE env var"]=>
  string(1) "1"
}
R                                                                                                                                                                                                                           41 / 41 (100%)array(2) {
  ["method"]=>
  string(35) "PhpCsFixer\Tests\UtilsTest::testXXX"
  ["PHP_CS_FIXER_FUTURE_MODE env var"]=>
  string(1) "1"
}
```

as we see, the new method `testXXX` is having non-default env-variable, because the previously executed method changed *the global state*

after fix:
```
ker@dus:~/github/PHP-CS-Fixer λ vendor/bin/phpunit tests/UtilsTest.php
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

Testing PhpCsFixer\Tests\UtilsTest
......................................Rarray(2) {
  ["method"]=>
  string(69) "PhpCsFixer\Tests\UtilsTest::testTriggerDeprecationWhenFutureModeIsOff"
  ["PHP_CS_FIXER_FUTURE_MODE env var"]=>
  string(1) "0"
}
Rarray(2) {
  ["method"]=>
  string(68) "PhpCsFixer\Tests\UtilsTest::testTriggerDeprecationWhenFutureModeIsOn"
  ["PHP_CS_FIXER_FUTURE_MODE env var"]=>
  string(1) "1"
}
R                                                                                                                                                                                                                           41 / 41 (100%)array(2) {
  ["method"]=>
  string(35) "PhpCsFixer\Tests\UtilsTest::testXXX"
  ["PHP_CS_FIXER_FUTURE_MODE env var"]=>
  string(0) ""
}
```

Commits
-------

cbd400e DX: UtilsTest - add missing teardown
  • Loading branch information
keradus committed Apr 11, 2021
2 parents 1e73620 + cbd400e commit f4e7211
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/UtilsTest.php
Expand Up @@ -30,6 +30,18 @@ final class UtilsTest extends TestCase
{
use ExpectDeprecationTrait;

private $originalValueOfFutureMode;

protected function doSetUp()
{
$this->originalValueOfFutureMode = getenv('PHP_CS_FIXER_FUTURE_MODE');
}

protected function doTearDown()
{
putenv("PHP_CS_FIXER_FUTURE_MODE={$this->originalValueOfFutureMode}");
}

/**
* @param string $expected Camel case string
* @param string $input Input string
Expand Down

0 comments on commit f4e7211

Please sign in to comment.