Skip to content

Commit

Permalink
Tests: stabilize an expected global
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrfnl committed Jul 5, 2020
1 parent a957a73 commit 33af771
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions tests/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 33af771

Please sign in to comment.