Skip to content

Commit

Permalink
Remove $GLOBALS clean up from AbstractTestCase
Browse files Browse the repository at this point in the history
There's no need for it anymore.

Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
  • Loading branch information
MauricioFauth committed Jan 11, 2025
1 parent 3e5934e commit ed9dc6c
Showing 1 changed file with 0 additions and 32 deletions.
32 changes: 0 additions & 32 deletions tests/unit/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,18 @@
use ReflectionClass;
use ReflectionProperty;

use function array_keys;
use function in_array;

/**
* Abstract class to hold some usefull methods used in tests
* And make tests clean
*/
abstract class AbstractTestCase extends TestCase
{
/**
* The variables to keep between tests
*
* @var string[]
*/
private array $globalsAllowList = [
'__composer_autoload_files',
'GLOBALS',
'_SERVER',
'__composer_autoload_files',
'__PHPUNIT_CONFIGURATION_FILE',
'__PHPUNIT_BOOTSTRAP',
];

/**
* Prepares environment for the test.
* Clean all variables
*/
protected function setUp(): void
{
foreach (array_keys($GLOBALS) as $key) {
if (in_array($key, $this->globalsAllowList, true)) {
continue;
}

unset($GLOBALS[$key]);
}

$_GET = [];
$_POST = [];
$_SERVER = [
Expand Down Expand Up @@ -153,13 +128,6 @@ protected function tearDown(): void
DatabaseInterface::$instance = null;
Config::$instance = null;
(new ReflectionProperty(Template::class, 'twig'))->setValue(null, null);
foreach (array_keys($GLOBALS) as $key) {
if (in_array($key, $this->globalsAllowList, true)) {
continue;
}

unset($GLOBALS[$key]);
}
}

/**
Expand Down

0 comments on commit ed9dc6c

Please sign in to comment.