Skip to content

Commit 0b2267d

Browse files
jrfnlgrogy
authored andcommitted
PHPUnit: use annotations for fixtures / cross-version compat up to PHPUnit 9.x
As of PHPUnit 8.x, the method signature for the `setUpBeforeClass()`, `setUp()`, `tearDown()` and `tearDownAfterClass()` fixture methods has changed to require the `void` return type. As the `void` return type isn't available until PHP 7.1, this cannot be implemented. Anntations to the rescue. By renaming the `setUpBeforeClass()` methods to another, descriptive name and using the `@beforeClass` annotation, the tests can be made cross-version compatible up to PHPUnit 9.x. With this change, the unit tests can now be run on PHPUnit 4 - 9. As PHPUnit has a caching feature build in as of PHPUnit 8, we need to add the `.phpunit.result.cache` file to `.gitignore`.
1 parent 3e48e13 commit 0b2267d

File tree

10 files changed

+34
-9
lines changed

10 files changed

+34
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor/
22
/composer.lock
33
phpunit.xml
4+
.phpunit.result.cache

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"php-parallel-lint/php-console-highlighter": "For colored console output"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^4.8.36 || ^5.0 || ^6.0 || ^7.0",
21+
"phpunit/phpunit": "^4.8.36 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
2222
"php-parallel-lint/php-parallel-lint": "^1.0"
2323
},
2424
"bin": ["var-dump-check"],

tests/JakubOnderka/PhpVarDumpCheck/CheckTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class CheckTest extends TestCase
88
protected static $uut;
99

1010

11-
public static function setUpBeforeClass()
11+
/**
12+
* @beforeClass
13+
*/
14+
public static function initializeCheckerWithSettings()
1215
{
1316
$settings = new PhpVarDumpCheck\Settings();
1417
self::$uut = new PhpVarDumpCheck\Checker($settings);

tests/JakubOnderka/PhpVarDumpCheck/DoctrineTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class DoctrineTest extends TestCase
88
protected static $uut;
99

1010

11-
public static function setUpBeforeClass()
11+
/**
12+
* @beforeClass
13+
*/
14+
public static function initializeCheckerWithSettings()
1215
{
1316
$settings = new PhpVarDumpCheck\Settings();
1417
$settings->functionsToCheck = array_merge($settings->functionsToCheck, [

tests/JakubOnderka/PhpVarDumpCheck/LadybugTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class LadybugTest extends TestCase
88
protected static $uut;
99

1010

11-
public static function setUpBeforeClass()
11+
/**
12+
* @beforeClass
13+
*/
14+
public static function initializeCheckerWithSettings()
1215
{
1316
$settings = new PhpVarDumpCheck\Settings();
1417
$settings->functionsToCheck = array_merge($settings->functionsToCheck, [

tests/JakubOnderka/PhpVarDumpCheck/LaravelTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class LaravelTest extends TestCase
88
protected static $uut;
99

1010

11-
public static function setUpBeforeClass()
11+
/**
12+
* @beforeClass
13+
*/
14+
public static function initializeCheckerWithSettings()
1215
{
1316
$settings = new PhpVarDumpCheck\Settings();
1417
$settings->functionsToCheck = array_merge($settings->functionsToCheck, [

tests/JakubOnderka/PhpVarDumpCheck/StandardPHPDumpTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class StandardPHPDumpTest extends TestCase
88
protected static $uut;
99

1010

11-
public static function setUpBeforeClass()
11+
/**
12+
* @beforeClass
13+
*/
14+
public static function initializeCheckerWithSettings()
1215
{
1316
$settings = new PhpVarDumpCheck\Settings();
1417
self::$uut = new PhpVarDumpCheck\Checker($settings);

tests/JakubOnderka/PhpVarDumpCheck/SymfonyTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class SymfonyTest extends TestCase
88
protected static $uut;
99

1010

11-
public static function setUpBeforeClass()
11+
/**
12+
* @beforeClass
13+
*/
14+
public static function initializeCheckerWithSettings()
1215
{
1316
$settings = new PhpVarDumpCheck\Settings();
1417
$settings->functionsToCheck = array_merge($settings->functionsToCheck, [

tests/JakubOnderka/PhpVarDumpCheck/TracyTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class TracyTest extends TestCase
88
protected static $uut;
99

1010

11-
public static function setUpBeforeClass()
11+
/**
12+
* @beforeClass
13+
*/
14+
public static function initializeCheckerWithSettings()
1215
{
1316
$settings = new PhpVarDumpCheck\Settings();
1417
$settings->functionsToCheck = array_merge($settings->functionsToCheck, [

tests/JakubOnderka/PhpVarDumpCheck/ZendTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class ZendTest extends TestCase
88
protected static $uut;
99

1010

11-
public static function setUpBeforeClass()
11+
/**
12+
* @beforeClass
13+
*/
14+
public static function initializeCheckerWithSettings()
1215
{
1316
$settings = new PhpVarDumpCheck\Settings();
1417
$settings->functionsToCheck = array_merge($settings->functionsToCheck, [

0 commit comments

Comments
 (0)