From 33af77177be5ae239349d3f8424e6a933f8d710f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 5 Jul 2020 19:59:36 +0200 Subject: [PATCH] Tests: stabilize an expected global The global `$PHP_CODESNIFFER_PEAR` variable is used by the `Core` test and those test don't necessarily need to use the generic `AllTests` file as an entry point. They can also be run using `phpunit ./tests/Core/AllTests.php`. In that case, however, the `$PHP_CODESNIFFER_PEAR` variable is not defined leading to `Undefined index: PHP_CODESNIFFER_PEAR` errors. By setting the global in the bootstrap, which is always loaded, this is avoided. --- tests/AllTests.php | 5 +---- tests/bootstrap.php | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/AllTests.php b/tests/AllTests.php index 4ed001dfed..9d099c1e3d 100644 --- a/tests/AllTests.php +++ b/tests/AllTests.php @@ -9,16 +9,13 @@ namespace PHP_CodeSniffer\Tests; -$GLOBALS['PHP_CODESNIFFER_PEAR'] = false; - -if (is_file(__DIR__.'/../autoload.php') === true) { +if ($GLOBALS['PHP_CODESNIFFER_PEAR'] === false) { include_once 'Core/AllTests.php'; include_once 'Standards/AllSniffs.php'; } else { include_once 'CodeSniffer/Core/AllTests.php'; include_once 'CodeSniffer/Standards/AllSniffs.php'; include_once 'FileList.php'; - $GLOBALS['PHP_CODESNIFFER_PEAR'] = true; } // PHPUnit 7 made the TestSuite run() method incompatible with diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 560253c6a7..47084d1135 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -44,6 +44,13 @@ class_alias('PHPUnit_TextUI_TestRunner', 'PHPUnit'.'\TextUI\TestRunner'); class_alias('PHPUnit_Framework_TestResult', 'PHPUnit'.'\Framework\TestResult'); } +// Determine whether this is a PEAR install or not. +$GLOBALS['PHP_CODESNIFFER_PEAR'] = false; + +if (is_file(__DIR__.'/../autoload.php') === false) { + $GLOBALS['PHP_CODESNIFFER_PEAR'] = true; +} + /** * A global util function to help print unit test fixing data.