Skip to content

Commit e8a9a01

Browse files
author
Felix Arntz
committed
Make PHPUnit compatible in older WordPress versions.
1 parent ae6ca84 commit e8a9a01

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/phpunit/bootstrap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@
2121
$test_root = '../../../../../../../tests/phpunit';
2222
}
2323

24+
// WordPress versions before 4.8 will be incompatible with newer PHPUnit versions.
25+
if ( version_compare( getenv( 'WP_VERSION' ), '4.8', '<' ) ) {
26+
require_once dirname( __FILE__ ) . '/phpunit6-compat.php';
27+
}
28+
2429
require $test_root . '/includes/bootstrap.php';

tests/phpunit/phpunit6-compat.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
if ( class_exists( 'PHPUnit\Runner\Version' ) && version_compare( PHPUnit\Runner\Version::id(), '6.0', '>=' ) ) {
4+
5+
class_alias( 'PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase' );
6+
class_alias( 'PHPUnit\Framework\Exception', 'PHPUnit_Framework_Exception' );
7+
class_alias( 'PHPUnit\Framework\ExpectationFailedException', 'PHPUnit_Framework_ExpectationFailedException' );
8+
class_alias( 'PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice' );
9+
class_alias( 'PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error_Warning' );
10+
class_alias( 'PHPUnit\Framework\Test', 'PHPUnit_Framework_Test' );
11+
class_alias( 'PHPUnit\Framework\Warning', 'PHPUnit_Framework_Warning' );
12+
class_alias( 'PHPUnit\Framework\AssertionFailedError', 'PHPUnit_Framework_AssertionFailedError' );
13+
class_alias( 'PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite' );
14+
class_alias( 'PHPUnit\Framework\TestListener', 'PHPUnit_Framework_TestListener' );
15+
class_alias( 'PHPUnit\Util\GlobalState', 'PHPUnit_Util_GlobalState' );
16+
class_alias( 'PHPUnit\Util\Getopt', 'PHPUnit_Util_Getopt' );
17+
18+
class PHPUnit_Util_Test extends PHPUnit\Util\Test {
19+
20+
public static function getTickets( $className, $methodName ) {
21+
$annotations = self::parseTestMethodAnnotations( $className, $methodName );
22+
23+
$tickets = array();
24+
25+
if ( isset( $annotations['class']['ticket'] ) ) {
26+
$tickets = $annotations['class']['ticket'];
27+
}
28+
29+
if ( isset( $annotations['method']['ticket'] ) ) {
30+
$tickets = array_merge( $tickets, $annotations['method']['ticket'] );
31+
}
32+
33+
return array_unique( $tickets );
34+
}
35+
36+
}
37+
38+
}

0 commit comments

Comments
 (0)