Skip to content

Commit ddb409e

Browse files
Build/Test Tools: Implement use of the void solution.
> PHPUnit 8.0.0 introduced a `void` return type declaration to the "fixture" methods – `setUpBeforeClass()`, `setUp()`, `tearDown()` and `tearDownAfterClass()`. As the `void` return type was not introduced until PHP 7.1, this makes it more difficult to create cross-version compatible tests when using fixtures, due to signature mismatches. > > The `Yoast\PHPUnitPolyfills\TestCases\TestCase` overcomes the signature mismatch by having two versions. The correct one will be loaded depending on the PHPUnit version being used. > > When using this TestCase, if an individual test, or another TestCase which extends this TestCase, needs to overload any of the "fixture" methods, it should do so by using a snake_case variant of the original fixture method name, i.e. `set_up_before_class()`, `set_up()`, `assert_pre_conditions()`, `assert_post_conditions()`, `tear_down()`, and `tear_down_after_class()`. > > The snake_case methods will automatically be called by PHPUnit. > > > IMPORTANT: The snake_case methods should not call the PHPUnit parent, i.e. do not use `parent::setUp()` from within an overloaded `set_up()` method. If necessary, DO call `parent::set_up()`. Reference: https://github.com/Yoast/PHPUnit-Polyfills#testcases This commit renames all declared fixture methods, and calls to parent versions of those fixture methods, from camelCase to snake_case. Follow-up to [51559-51567]. Props jrf, hellofromTonya, johnbillion, netweb, dd32, pputzer, SergeyBiryukov. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51568 602fd350-edb4-49c9-b593-d223f7449a82
1 parent cb6bf02 commit ddb409e

File tree

260 files changed

+726
-726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+726
-726
lines changed

tests/phpunit/includes/abstract-testcase.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public static function get_called_class() {
6060
/**
6161
* Runs the routine before setting up all tests.
6262
*/
63-
public static function setUpBeforeClass() {
63+
public static function set_up_before_class() {
6464
global $wpdb;
6565

6666
$wpdb->suppress_errors = false;
6767
$wpdb->show_errors = true;
6868
$wpdb->db_connect();
6969
ini_set( 'display_errors', 1 );
7070

71-
parent::setUpBeforeClass();
71+
parent::set_up_before_class();
7272

7373
$class = get_called_class();
7474

@@ -82,8 +82,8 @@ public static function setUpBeforeClass() {
8282
/**
8383
* Runs the routine after all tests have been run.
8484
*/
85-
public static function tearDownAfterClass() {
86-
parent::tearDownAfterClass();
85+
public static function tear_down_after_class() {
86+
parent::tear_down_after_class();
8787

8888
_delete_all_data();
8989
self::flush_cache();
@@ -100,7 +100,7 @@ public static function tearDownAfterClass() {
100100
/**
101101
* Runs the routine before each test is executed.
102102
*/
103-
public function setUp() {
103+
public function set_up() {
104104
set_time_limit( 0 );
105105

106106
if ( ! self::$ignore_files ) {
@@ -140,7 +140,7 @@ public function setUp() {
140140
/**
141141
* After a test method runs, resets any state in WordPress the test method might have changed.
142142
*/
143-
public function tearDown() {
143+
public function tear_down() {
144144
global $wpdb, $wp_query, $wp;
145145
$wpdb->query( 'ROLLBACK' );
146146
if ( is_multisite() ) {
@@ -535,7 +535,7 @@ public function expectedDeprecated() {
535535
*
536536
* @since 4.2.0
537537
*/
538-
protected function assertPostConditions() {
538+
protected function assert_post_conditions() {
539539
$this->expectedDeprecated();
540540
}
541541

tests/phpunit/includes/testcase-ajax.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
115115
'wp-privacy-erase-personal-data',
116116
);
117117

118-
public static function setUpBeforeClass() {
119-
parent::setUpBeforeClass();
118+
public static function set_up_before_class() {
119+
parent::set_up_before_class();
120120

121121
remove_action( 'admin_init', '_maybe_update_core' );
122122
remove_action( 'admin_init', '_maybe_update_plugins' );
@@ -135,8 +135,8 @@ public static function setUpBeforeClass() {
135135
*
136136
* Overrides wp_die(), pretends to be Ajax, and suppresses E_WARNINGs.
137137
*/
138-
public function setUp() {
139-
parent::setUp();
138+
public function set_up() {
139+
parent::set_up();
140140

141141
add_filter( 'wp_doing_ajax', '__return_true' );
142142
add_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );
@@ -156,7 +156,7 @@ public function setUp() {
156156
*
157157
* Resets $_POST, removes the wp_die() override, restores error reporting.
158158
*/
159-
public function tearDown() {
159+
public function tear_down() {
160160
$_POST = array();
161161
$_GET = array();
162162
unset( $GLOBALS['post'] );
@@ -165,7 +165,7 @@ public function tearDown() {
165165
remove_action( 'clear_auth_cookie', array( $this, 'logout' ) );
166166
error_reporting( $this->_error_level );
167167
set_current_screen( 'front' );
168-
parent::tearDown();
168+
parent::tear_down();
169169
}
170170

171171
/**

tests/phpunit/includes/testcase-canonical.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public static function wpTearDownAfterClass() {
2323
self::delete_shared_fixtures();
2424
}
2525

26-
public function setUp() {
27-
parent::setUp();
26+
public function set_up() {
27+
parent::set_up();
2828

2929
update_option( 'page_comments', true );
3030
update_option( 'comments_per_page', 5 );

tests/phpunit/includes/testcase-rest-controller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ abstract class WP_Test_REST_Controller_Testcase extends WP_Test_REST_TestCase {
44

55
protected $server;
66

7-
public function setUp() {
8-
parent::setUp();
7+
public function set_up() {
8+
parent::set_up();
99
add_filter( 'rest_url', array( $this, 'filter_rest_url_for_leading_slash' ), 10, 2 );
1010
/** @var WP_REST_Server $wp_rest_server */
1111
global $wp_rest_server;
1212
$wp_rest_server = new Spy_REST_Server;
1313
do_action( 'rest_api_init', $wp_rest_server );
1414
}
1515

16-
public function tearDown() {
16+
public function tear_down() {
1717
remove_filter( 'rest_url', array( $this, 'test_rest_url_for_leading_slash' ), 10, 2 );
1818
/** @var WP_REST_Server $wp_rest_server */
1919
global $wp_rest_server;
2020
$wp_rest_server = null;
21-
parent::tearDown();
21+
parent::tear_down();
2222
}
2323

2424
abstract public function test_register_routes();

tests/phpunit/includes/testcase-xmlrpc.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
class WP_XMLRPC_UnitTestCase extends WP_UnitTestCase {
77
protected $myxmlrpcserver;
88

9-
function setUp() {
10-
parent::setUp();
9+
function set_up() {
10+
parent::set_up();
1111

1212
add_filter( 'pre_option_enable_xmlrpc', '__return_true' );
1313

1414
$this->myxmlrpcserver = new wp_xmlrpc_server();
1515
}
1616

17-
function tearDown() {
17+
function tear_down() {
1818
remove_filter( 'pre_option_enable_xmlrpc', '__return_true' );
1919

2020
$this->remove_added_uploads();
2121

22-
parent::tearDown();
22+
parent::tear_down();
2323
}
2424

2525
protected static function make_user_by_role( $role ) {

tests/phpunit/tests/admin/includesCommunityEvents.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Test_WP_Community_Events extends WP_UnitTestCase {
3131
*
3232
* @since 4.8.0
3333
*/
34-
public function setUp() {
35-
parent::setUp();
34+
public function set_up() {
35+
parent::set_up();
3636

3737
require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php';
3838

tests/phpunit/tests/admin/includesListTable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Tests_Admin_includesListTable extends WP_UnitTestCase {
1414
*/
1515
protected $table;
1616

17-
function setUp() {
18-
parent::setUp();
17+
function set_up() {
18+
parent::set_up();
1919
$this->table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => 'edit-page' ) );
2020
}
2121

tests/phpunit/tests/admin/includesScreen.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
155155
),
156156
);
157157

158-
function tearDown() {
158+
function tear_down() {
159159
unset( $GLOBALS['wp_taxonomies']['old-or-new'] );
160-
parent::tearDown();
160+
parent::tear_down();
161161
}
162162

163163
function test_set_current_screen_with_hook_suffix() {

tests/phpunit/tests/admin/includesTheme.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55
class Tests_Admin_includesTheme extends WP_UnitTestCase {
66

7-
function setUp() {
8-
parent::setUp();
7+
function set_up() {
8+
parent::set_up();
99
$this->theme_root = DIR_TESTDATA . '/themedir1';
1010

1111
$this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
@@ -20,15 +20,15 @@ function setUp() {
2020
unset( $GLOBALS['wp_themes'] );
2121
}
2222

23-
function tearDown() {
23+
function tear_down() {
2424
$GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
2525
remove_filter( 'theme_root', array( $this, '_theme_root' ) );
2626
remove_filter( 'stylesheet_root', array( $this, '_theme_root' ) );
2727
remove_filter( 'template_root', array( $this, '_theme_root' ) );
2828

2929
wp_clean_themes_cache();
3030
unset( $GLOBALS['wp_themes'] );
31-
parent::tearDown();
31+
parent::tear_down();
3232
}
3333

3434
// Replace the normal theme root directory with our premade test directory.

tests/phpunit/tests/adminbar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Tests_AdminBar extends WP_UnitTestCase {
1414

1515
protected static $user_ids = array();
1616

17-
public static function setUpBeforeClass() {
18-
parent::setUpBeforeClass();
17+
public static function set_up_before_class() {
18+
parent::set_up_before_class();
1919

2020
require_once ABSPATH . WPINC . '/class-wp-admin-bar.php';
2121
}

0 commit comments

Comments
 (0)