Skip to content

Commit 33af771

Browse files
committed
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.
1 parent a957a73 commit 33af771

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

tests/AllTests.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99

1010
namespace PHP_CodeSniffer\Tests;
1111

12-
$GLOBALS['PHP_CODESNIFFER_PEAR'] = false;
13-
14-
if (is_file(__DIR__.'/../autoload.php') === true) {
12+
if ($GLOBALS['PHP_CODESNIFFER_PEAR'] === false) {
1513
include_once 'Core/AllTests.php';
1614
include_once 'Standards/AllSniffs.php';
1715
} else {
1816
include_once 'CodeSniffer/Core/AllTests.php';
1917
include_once 'CodeSniffer/Standards/AllSniffs.php';
2018
include_once 'FileList.php';
21-
$GLOBALS['PHP_CODESNIFFER_PEAR'] = true;
2219
}
2320

2421
// PHPUnit 7 made the TestSuite run() method incompatible with

tests/bootstrap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ class_alias('PHPUnit_TextUI_TestRunner', 'PHPUnit'.'\TextUI\TestRunner');
4444
class_alias('PHPUnit_Framework_TestResult', 'PHPUnit'.'\Framework\TestResult');
4545
}
4646

47+
// Determine whether this is a PEAR install or not.
48+
$GLOBALS['PHP_CODESNIFFER_PEAR'] = false;
49+
50+
if (is_file(__DIR__.'/../autoload.php') === false) {
51+
$GLOBALS['PHP_CODESNIFFER_PEAR'] = true;
52+
}
53+
4754

4855
/**
4956
* A global util function to help print unit test fixing data.

0 commit comments

Comments
 (0)