Skip to content

Commit f33ceeb

Browse files
committed
Merge branch 'feature/phpunit-6-compatibility' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents a739358 + 33a89f1 commit f33ceeb

15 files changed

+91
-82
lines changed

.travis.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@ matrix:
1919
- php: nightly
2020
- php: hhvm
2121

22+
before_install:
23+
# Circumvent a bug in the travis HHVM image - ships with incompatible PHPUnit.
24+
- if [[ $TRAVIS_PHP_VERSION == hhv* ]]; then composer self-update; fi
25+
- if [[ $TRAVIS_PHP_VERSION == hhv* ]]; then composer require phpunit/phpunit:~4.0; fi
26+
- if [[ $TRAVIS_PHP_VERSION == hhv* ]]; then composer install; fi
27+
2228
before_script:
2329
- if [[ $CUSTOM_INI == "1" && ${TRAVIS_PHP_VERSION:0:1} == "5" ]]; then phpenv config-add php5-testingConfig.ini; fi
2430
- if [[ $CUSTOM_INI == "1" ]] && [[ ${TRAVIS_PHP_VERSION:0:1} == "7" || $TRAVIS_PHP_VERSION == "nightly" ]]; then phpenv config-add php7-testingConfig.ini; fi
2531

2632
script:
27-
- composer install
2833
- if [[ $TRAVIS_PHP_VERSION != hhv* ]]; then php bin/phpcs --config-set php_path php; fi
29-
- vendor/bin/phpunit tests/AllTests.php
34+
- if [[ $TRAVIS_PHP_VERSION != hhv* ]]; then phpunit tests/AllTests.php; fi
35+
- if [[ $TRAVIS_PHP_VERSION == hhv* ]]; then vendor/bin/phpunit tests/AllTests.php; fi
3036
- if [[ $CUSTOM_INI != "1" ]]; then php bin/phpcs --no-cache --parallel=1; fi
3137
- if [[ $CUSTOM_INI != "1" && $TRAVIS_PHP_VERSION != hhv* && $TRAVIS_PHP_VERSION != "nightly" ]]; then pear package-validate package.xml; fi
3238
- if [[ $CUSTOM_INI != "1" && $TRAVIS_PHP_VERSION != hhv* ]]; then php scripts/build-phar.php; fi

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"ext-simplexml": "*"
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": "~4.0"
34+
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0"
3535
},
3636
"bin": [
3737
"bin/phpcs",

package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
132132
<file baseinstalldir="" name="AbstractSniffUnitTest.php" role="test" />
133133
<file baseinstalldir="" name="AllSniffs.php" role="test" />
134134
</dir>
135+
<file baseinstalldir="" name="bootstrap.php" role="test" />
135136
<file baseinstalldir="" name="AllTests.php" role="test" />
136137
<file baseinstalldir="" name="TestSuite.php" role="test" />
137138
</dir>

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit>
2+
<phpunit backupGlobals="true" bootstrap="tests/bootstrap.php">
33
<testsuites>
44
<testsuite name="PHP_CodeSniffer Test Suite">
55
<file>tests/AllTests.php</file>

tests/AllTests.php

+4-19
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,19 @@
99

1010
namespace PHP_CodeSniffer\Tests;
1111

12-
use PHP_CodeSniffer\Util\Tokens;
13-
14-
if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
15-
define('PHP_CODESNIFFER_IN_TESTS', true);
16-
}
17-
18-
if (defined('PHP_CODESNIFFER_CBF') === false) {
19-
define('PHP_CODESNIFFER_CBF', false);
20-
}
21-
22-
if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
23-
define('PHP_CODESNIFFER_VERBOSITY', 0);
24-
}
12+
use PHP_CodeSniffer\Tests\TestSuite;
13+
use PHPUnit\TextUI\TestRunner;
2514

2615
if (is_file(__DIR__.'/../autoload.php') === true) {
27-
include_once __DIR__.'/../autoload.php';
2816
include_once 'Core/AllTests.php';
2917
include_once 'Standards/AllSniffs.php';
3018
} else {
31-
include_once 'PHP/CodeSniffer/autoload.php';
3219
include_once 'CodeSniffer/Core/AllTests.php';
3320
include_once 'CodeSniffer/Standards/AllSniffs.php';
3421
}
3522

3623
require_once 'TestSuite.php';
3724

38-
$tokens = new Tokens();
39-
4025
class PHP_CodeSniffer_AllTests
4126
{
4227

@@ -48,15 +33,15 @@ class PHP_CodeSniffer_AllTests
4833
*/
4934
public static function main()
5035
{
51-
\PHPUnit_TextUI_TestRunner::run(self::suite());
36+
TestRunner::run(self::suite());
5237

5338
}//end main()
5439

5540

5641
/**
5742
* Add all PHP_CodeSniffer test suites into a single test suite.
5843
*
59-
* @return \PHPUnit_Framework_TestSuite
44+
* @return \PHPUnit\Framework\TestSuite
6045
*/
6146
public static function suite()
6247
{

tests/Core/AllTests.php

+5-24
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,8 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core;
1111

12-
use PHP_CodeSniffer\Util\Tokens;
13-
14-
if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
15-
define('PHP_CODESNIFFER_IN_TESTS', true);
16-
}
17-
18-
if (defined('PHP_CODESNIFFER_CBF') === false) {
19-
define('PHP_CODESNIFFER_CBF', false);
20-
}
21-
22-
if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
23-
define('PHP_CODESNIFFER_VERBOSITY', 0);
24-
}
25-
26-
if (is_file(__DIR__.'/../../autoload.php') === true) {
27-
include_once __DIR__.'/../../autoload.php';
28-
} else {
29-
include_once 'PHP/CodeSniffer/autoload.php';
30-
}
31-
32-
$tokens = new Tokens();
12+
use PHPUnit\TextUI\TestRunner;
13+
use PHPUnit\Framework\TestSuite;
3314

3415
require_once 'IsCamelCapsTest.php';
3516
require_once 'ErrorSuppressionTest.php';
@@ -48,19 +29,19 @@ class AllTests
4829
*/
4930
public static function main()
5031
{
51-
\PHPUnit2_TextUI_TestRunner::run(self::suite());
32+
TestRunner::run(self::suite());
5233

5334
}//end main()
5435

5536

5637
/**
5738
* Add all core unit tests into a test suite.
5839
*
59-
* @return \PHPUnit_Framework_TestSuite
40+
* @return \PHPUnit\Framework\TestSuite
6041
*/
6142
public static function suite()
6243
{
63-
$suite = new \PHPUnit_Framework_TestSuite('PHP CodeSniffer Core');
44+
$suite = new TestSuite('PHP CodeSniffer Core');
6445
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\IsCamelCapsTest');
6546
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\ErrorSuppressionTest');
6647
$suite->addTestSuite('PHP_CodeSniffer\Tests\Core\File\GetMethodParametersTest');

tests/Core/ErrorSuppressionTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
use PHP_CodeSniffer\Config;
1313
use PHP_CodeSniffer\Ruleset;
1414
use PHP_CodeSniffer\Files\DummyFile;
15+
use PHPUnit\Framework\TestCase;
1516

16-
class ErrorSuppressionTest extends \PHPUnit_Framework_TestCase
17+
class ErrorSuppressionTest extends TestCase
1718
{
1819

1920

tests/Core/File/FindExtendedClassNameTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
use PHP_CodeSniffer\Config;
1313
use PHP_CodeSniffer\Ruleset;
1414
use PHP_CodeSniffer\Files\DummyFile;
15+
use PHPUnit\Framework\TestCase;
1516

16-
class FindExtendedClassNameTest extends \PHPUnit_Framework_TestCase
17+
class FindExtendedClassNameTest extends TestCase
1718
{
1819

1920
/**

tests/Core/File/FindImplementedInterfaceNamesTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
use PHP_CodeSniffer\Config;
1313
use PHP_CodeSniffer\Ruleset;
1414
use PHP_CodeSniffer\Files\DummyFile;
15+
use PHPUnit\Framework\TestCase;
1516

16-
class FindImplementedInterfaceNamesTest extends \PHPUnit_Framework_TestCase
17+
class FindImplementedInterfaceNamesTest extends TestCase
1718
{
1819

1920
/**

tests/Core/File/GetMethodParametersTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
use PHP_CodeSniffer\Config;
1313
use PHP_CodeSniffer\Ruleset;
1414
use PHP_CodeSniffer\Files\DummyFile;
15+
use PHPUnit\Framework\TestCase;
1516

16-
class GetMethodParametersTest extends \PHPUnit_Framework_TestCase
17+
class GetMethodParametersTest extends TestCase
1718
{
1819

1920
/**

tests/Core/IsCamelCapsTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
namespace PHP_CodeSniffer\Tests\Core;
1111

1212
use PHP_CodeSniffer\Util\Common;
13+
use PHPUnit\Framework\TestCase;
1314

14-
class IsCamelCapsTest extends \PHPUnit_Framework_TestCase
15+
class IsCamelCapsTest extends TestCase
1516
{
1617

1718

tests/Standards/AbstractSniffUnitTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
use PHP_CodeSniffer\Ruleset;
1919
use PHP_CodeSniffer\Files\LocalFile;
2020
use PHP_CodeSniffer\Util\Common;
21+
use PHPUnit\Framework\TestCase;
2122

22-
abstract class AbstractSniffUnitTest extends \PHPUnit_Framework_TestCase
23+
abstract class AbstractSniffUnitTest extends TestCase
2324
{
2425

2526
/**
@@ -110,7 +111,7 @@ protected function shouldSkipTest()
110111
* Tests the extending classes Sniff class.
111112
*
112113
* @return void
113-
* @throws \PHPUnit_Framework_Error
114+
* @throws \PHPUnit\Framework\Exception
114115
*/
115116
final public function testSniff()
116117
{

tests/Standards/AllSniffs.php

+5-24
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,11 @@
99

1010
namespace PHP_CodeSniffer\Tests\Standards;
1111

12-
use PHP_CodeSniffer\Util\Tokens;
1312
use PHP_CodeSniffer\Util\Standards;
1413
use PHP_CodeSniffer\Autoload;
1514
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
16-
17-
if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
18-
define('PHP_CODESNIFFER_IN_TESTS', true);
19-
}
20-
21-
if (defined('PHP_CODESNIFFER_CBF') === false) {
22-
define('PHP_CODESNIFFER_CBF', false);
23-
}
24-
25-
if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
26-
define('PHP_CODESNIFFER_VERBOSITY', 0);
27-
}
28-
29-
if (is_file(__DIR__.'/../../autoload.php') === true) {
30-
include_once __DIR__.'/../../autoload.php';
31-
} else {
32-
include_once 'PHP/CodeSniffer/autoload.php';
33-
}
34-
35-
$tokens = new Tokens();
15+
use PHPUnit\TextUI\TestRunner;
16+
use PHPUnit\Framework\TestSuite;
3617

3718
class AllSniffs
3819
{
@@ -45,7 +26,7 @@ class AllSniffs
4526
*/
4627
public static function main()
4728
{
48-
\PHPUnit_TextUI_TestRunner::run(self::suite());
29+
TestRunner::run(self::suite());
4930

5031
}//end main()
5132

@@ -56,14 +37,14 @@ public static function main()
5637
* Sniff unit tests are found by recursing through the 'Tests' directory
5738
* of each installed coding standard.
5839
*
59-
* @return \PHPUnit_Framework_TestSuite
40+
* @return \PHPUnit\Framework\TestSuite
6041
*/
6142
public static function suite()
6243
{
6344
$GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'] = array();
6445
$GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'] = array();
6546

66-
$suite = new \PHPUnit_Framework_TestSuite('PHP CodeSniffer Standards');
47+
$suite = new TestSuite('PHP CodeSniffer Standards');
6748

6849
$isInstalled = !is_file(__DIR__.'/../../autoload.php');
6950

tests/TestSuite.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99

1010
namespace PHP_CodeSniffer\Tests;
1111

12-
class TestSuite extends \PHPUnit_Framework_TestSuite
12+
use PHPUnit\Framework\TestSuite as PHPUnit_TestSuite;
13+
use PHPUnit\Framework\TestResult;
14+
15+
class TestSuite extends PHPUnit_TestSuite
1316
{
1417

1518

1619
/**
1720
* Runs the tests and collects their result in a TestResult.
1821
*
19-
* @param \PHPUnit_Framework_TestResult $result A test result.
22+
* @param \PHPUnit\Framework\TestResult $result A test result.
2023
* @param mixed $filter The filter passed to each test.
2124
*
22-
* @return \PHPUnit_Framework_TestResult
25+
* @return \PHPUnit\Framework\TestResult
2326
*/
24-
public function run(\PHPUnit_Framework_TestResult $result=null, $filter=false)
27+
public function run(TestResult $result=null, $filter=false)
2528
{
2629
$result = parent::run($result, $filter);
2730

tests/bootstrap.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Bootstrap file for PHP_CodeSniffer unit tests.
4+
*
5+
* @author Greg Sherwood <[email protected]>
6+
* @copyright 2006-2017 Squiz Pty Ltd (ABN 77 084 670 600)
7+
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8+
*/
9+
10+
if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
11+
define('PHP_CODESNIFFER_IN_TESTS', true);
12+
}
13+
14+
if (defined('PHP_CODESNIFFER_CBF') === false) {
15+
define('PHP_CODESNIFFER_CBF', false);
16+
}
17+
18+
if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
19+
define('PHP_CODESNIFFER_VERBOSITY', 0);
20+
}
21+
22+
if (is_file(__DIR__.'/../autoload.php') === true) {
23+
include_once __DIR__.'/../autoload.php';
24+
} else {
25+
include_once 'PHP/CodeSniffer/autoload.php';
26+
}
27+
28+
$tokens = new \PHP_CodeSniffer\Util\Tokens();
29+
30+
31+
// Compatibility for PHPUnit < 6 and PHPUnit 6+.
32+
if (class_exists('PHPUnit_Framework_TestSuite') === true && class_exists('PHPUnit\Framework\TestSuite') === false) {
33+
class_alias('PHPUnit_Framework_TestSuite', 'PHPUnit\Framework\TestSuite');
34+
}
35+
36+
if (class_exists('PHPUnit_Framework_TestCase') === true && class_exists('PHPUnit\Framework\TestCase') === false) {
37+
class_alias('PHPUnit_Framework_TestCase', 'PHPUnit\Framework\TestCase');
38+
}
39+
40+
if (class_exists('PHPUnit_TextUI_TestRunner') === true && class_exists('PHPUnit\TextUI\TestRunner') === false) {
41+
class_alias('PHPUnit_TextUI_TestRunner', 'PHPUnit\TextUI\TestRunner');
42+
}
43+
44+
if (class_exists('PHPUnit_Framework_TestResult') === true && class_exists('PHPUnit\Framework\TestResult') === false) {
45+
class_alias('PHPUnit_Framework_TestResult', 'PHPUnit\Framework\TestResult');
46+
}

0 commit comments

Comments
 (0)