Skip to content

Commit 457b7b3

Browse files
Tests: Replace assertRegExp() with assertMatchesRegularExpression().
The `assertRegExp()` and `assertNotRegExp()` methods were hard deprecated in PHPUnit 9.1 and the functionality will be removed in PHPUnit 10.0. The `assertMatchesRegularExpression()` and `assertDoesNotMatchRegularExpression()` methods were introduced as a replacement in PHPUnit 9.1. These new PHPUnit methods are polyfilled by the PHPUnit Polyfills and switching to them will future-proof the tests some more. References: * https://github.com/sebastianbergmann/phpunit/blob/9.1.5/ChangeLog-9.1.md#910---2020-04-03 * sebastianbergmann/phpunit#4085 * sebastianbergmann/phpunit#4088 Follow-up to [51559-51564]. Props jrf. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51565 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 29d678d commit 457b7b3

File tree

16 files changed

+39
-39
lines changed

16 files changed

+39
-39
lines changed

tests/phpunit/tests/ajax/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ public function test_response_charset_in_xml() {
100100

101101
// Check the XML tag.
102102
$contents = ob_get_clean();
103-
$this->assertRegExp( '/<\?xml\s+version=\'1.0\'\s+encoding=\'' . preg_quote( get_option( 'blog_charset' ) ) . '\'\s+standalone=\'yes\'\?>/', $contents );
103+
$this->assertMatchesRegularExpression( '/<\?xml\s+version=\'1.0\'\s+encoding=\'' . preg_quote( get_option( 'blog_charset' ) ) . '\'\s+standalone=\'yes\'\?>/', $contents );
104104
}
105105
}

tests/phpunit/tests/avatar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public function test_get_avatar_data_should_return_gravatar_url_when_input_avata
257257
$actual_data = get_avatar_data( $comment );
258258

259259
$this->assertTrue( is_avatar_comment_type( $comment_type ) );
260-
$this->assertRegexp( '|^http?://[0-9]+.gravatar.com/avatar/[0-9a-f]{32}\?|', $actual_data['url'] );
260+
$this->assertMatchesRegularExpression( '|^http?://[0-9]+.gravatar.com/avatar/[0-9a-f]{32}\?|', $actual_data['url'] );
261261
}
262262

263263
/**

tests/phpunit/tests/category/wpDropdownCategories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function test_required_true_should_add_required_attribute() {
202202
$dropdown_categories = wp_dropdown_categories( $args );
203203

204204
// Test to see if it contains the "required" attribute.
205-
$this->assertRegExp( '/<select[^>]+required/', $dropdown_categories );
205+
$this->assertMatchesRegularExpression( '/<select[^>]+required/', $dropdown_categories );
206206
}
207207

208208
/**

tests/phpunit/tests/category/wpListCategories.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function test_class_containing_current_cat() {
3030
);
3131

3232
$this->assertNotRegExp( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat[^"]*"/', $found );
33-
$this->assertRegExp( '/class="[^"]*cat-item-' . $c2 . '[^"]*current-cat[^"]*"/', $found );
33+
$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $c2 . '[^"]*current-cat[^"]*"/', $found );
3434
}
3535

3636
public function test_class_containing_current_cat_parent() {
@@ -49,7 +49,7 @@ public function test_class_containing_current_cat_parent() {
4949
)
5050
);
5151

52-
$this->assertRegExp( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat-parent[^"]*"/', $found );
52+
$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat-parent[^"]*"/', $found );
5353
$this->assertNotRegExp( '/class="[^"]*cat-item-' . $c2 . '[^"]*current-cat-parent[^"]*"/', $found );
5454
}
5555

@@ -67,9 +67,9 @@ public function test_current_category_should_accept_an_array_of_ids() {
6767
)
6868
);
6969

70-
$this->assertRegExp( '/class="[^"]*cat-item-' . $cats[0] . '[^"]*current-cat[^"]*"/', $found );
70+
$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $cats[0] . '[^"]*current-cat[^"]*"/', $found );
7171
$this->assertNotRegExp( '/class="[^"]*cat-item-' . $cats[1] . '[^"]*current[^"]*"/', $found );
72-
$this->assertRegExp( '/class="[^"]*cat-item-' . $cats[2] . '[^"]*current-cat[^"]*"/', $found );
72+
$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $cats[2] . '[^"]*current-cat[^"]*"/', $found );
7373
}
7474

7575
/**
@@ -650,8 +650,8 @@ public function test_class_containing_current_cat_ancestor() {
650650
)
651651
);
652652

653-
$this->assertRegExp( '/class="[^"]*cat-item-' . $parent . '[^"]*current-cat-ancestor[^"]*"/', $actual );
654-
$this->assertRegExp( '/class="[^"]*cat-item-' . $child . '[^"]*current-cat-ancestor[^"]*"/', $actual );
653+
$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $parent . '[^"]*current-cat-ancestor[^"]*"/', $actual );
654+
$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $child . '[^"]*current-cat-ancestor[^"]*"/', $actual );
655655
$this->assertNotRegExp( '/class="[^"]*cat-item-' . $grandchild . '[^"]*current-cat-ancestor[^"]*"/', $actual );
656656
$this->assertNotRegExp( '/class="[^"]*cat-item-' . $child2 . '[^"]*current-cat-ancestor[^"]*"/', $actual );
657657
}

tests/phpunit/tests/comment/commentForm.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function test_default_markup_for_submit_button_and_wrapper() {
1818

1919
$button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
2020
$hidden = get_comment_id_fields( $p );
21-
$this->assertRegExp( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
21+
$this->assertMatchesRegularExpression( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
2222
}
2323

2424
public function test_custom_submit_button() {
@@ -53,7 +53,7 @@ public function test_custom_submit_field() {
5353

5454
$button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
5555
$hidden = get_comment_id_fields( $p );
56-
$this->assertRegExp( '|<p class="my\-custom\-submit\-field">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
56+
$this->assertMatchesRegularExpression( '|<p class="my\-custom\-submit\-field">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
5757
}
5858

5959
/**
@@ -75,7 +75,7 @@ public function test_submit_button_and_submit_field_should_fall_back_on_defaults
7575

7676
$button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
7777
$hidden = get_comment_id_fields( $p );
78-
$this->assertRegExp( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
78+
$this->assertMatchesRegularExpression( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
7979
}
8080

8181
public function filter_comment_form_defaults( $defaults ) {
@@ -102,7 +102,7 @@ public function test_fields_should_include_cookies_consent() {
102102

103103
remove_filter( 'option_show_comments_cookies_opt_in', '__return_true' );
104104

105-
$this->assertRegExp( '|<p class="comment\-form\-cookies\-consent">.*?</p>|', $form );
105+
$this->assertMatchesRegularExpression( '|<p class="comment\-form\-cookies\-consent">.*?</p>|', $form );
106106
}
107107

108108
/**

tests/phpunit/tests/customize/nav-menus.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ function test_available_items_template() {
770770
if ( $post_types ) {
771771
foreach ( $post_types as $type ) {
772772
$this->assertStringContainsString( 'available-menu-items-post_type-' . esc_attr( $type->name ), $template );
773-
$this->assertRegExp( '#<h4 class="accordion-section-title".*>\s*' . esc_html( $type->labels->name ) . '#', $template );
773+
$this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*' . esc_html( $type->labels->name ) . '#', $template );
774774
$this->assertStringContainsString( 'data-type="post_type"', $template );
775775
$this->assertStringContainsString( 'data-object="' . esc_attr( $type->name ) . '"', $template );
776776
$this->assertStringContainsString( 'data-type_label="' . esc_attr( $type->labels->singular_name ) . '"', $template );
@@ -781,15 +781,15 @@ function test_available_items_template() {
781781
if ( $taxonomies ) {
782782
foreach ( $taxonomies as $tax ) {
783783
$this->assertStringContainsString( 'available-menu-items-taxonomy-' . esc_attr( $tax->name ), $template );
784-
$this->assertRegExp( '#<h4 class="accordion-section-title".*>\s*' . esc_html( $tax->labels->name ) . '#', $template );
784+
$this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*' . esc_html( $tax->labels->name ) . '#', $template );
785785
$this->assertStringContainsString( 'data-type="taxonomy"', $template );
786786
$this->assertStringContainsString( 'data-object="' . esc_attr( $tax->name ) . '"', $template );
787787
$this->assertStringContainsString( 'data-type_label="' . esc_attr( $tax->labels->singular_name ) . '"', $template );
788788
}
789789
}
790790

791791
$this->assertStringContainsString( 'available-menu-items-custom_type', $template );
792-
$this->assertRegExp( '#<h4 class="accordion-section-title".*>\s*Custom#', $template );
792+
$this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*Custom#', $template );
793793
$this->assertStringContainsString( 'data-type="custom_type"', $template );
794794
$this->assertStringContainsString( 'data-object="custom_object"', $template );
795795
$this->assertStringContainsString( 'data-type_label="Custom Type"', $template );
@@ -1013,7 +1013,7 @@ function test_save_nav_menus_created_posts() {
10131013
$this->assertSame( $save_action_count + 1, did_action( 'customize_save_nav_menus_created_posts' ) );
10141014
foreach ( $drafted_post_ids as $post_id ) {
10151015
$this->assertSame( 'publish', get_post_status( $post_id ) );
1016-
$this->assertRegExp( '/^auto-draft-\d+$/', get_post( $post_id )->post_name );
1016+
$this->assertMatchesRegularExpression( '/^auto-draft-\d+$/', get_post( $post_id )->post_name );
10171017
$this->assertEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) );
10181018
}
10191019

tests/phpunit/tests/customize/widgets.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ function test_wp_widget_form_customize_control_json() {
610610
$params = $control->json();
611611

612612
$this->assertSame( 'widget_form', $params['type'] );
613-
$this->assertRegExp( '#^<li[^>]+>\s*</li>$#', $params['content'] );
614-
$this->assertRegExp( '#^<div[^>]*class=\'widget\'[^>]*#s', $params['widget_control'] );
613+
$this->assertMatchesRegularExpression( '#^<li[^>]+>\s*</li>$#', $params['content'] );
614+
$this->assertMatchesRegularExpression( '#^<div[^>]*class=\'widget\'[^>]*#s', $params['widget_control'] );
615615
$this->assertStringContainsString( '<div class="widget-content"></div>', $params['widget_control'] );
616616
$this->assertStringNotContainsString( '<input class="widefat"', $params['widget_control'] );
617617
$this->assertStringContainsString( '<input class="widefat"', $params['widget_content'] );

tests/phpunit/tests/date/query.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ public function test_build_time_query_hour_minute() {
713713

714714
// $compare value is floating point - use regex to account for
715715
// varying precision on different PHP installations.
716-
$this->assertRegExp( "/DATE_FORMAT\( post_date, '%H\.%i' \) = 5\.150*/", $wpdb->remove_placeholder_escape( $found ) );
716+
$this->assertMatchesRegularExpression( "/DATE_FORMAT\( post_date, '%H\.%i' \) = 5\.150*/", $wpdb->remove_placeholder_escape( $found ) );
717717
}
718718

719719
public function test_build_time_query_hour_minute_second() {
@@ -724,7 +724,7 @@ public function test_build_time_query_hour_minute_second() {
724724

725725
// $compare value is floating point - use regex to account for
726726
// varying precision on different PHP installations.
727-
$this->assertRegExp( "/DATE_FORMAT\( post_date, '%H\.%i%s' \) = 5\.15350*/", $wpdb->remove_placeholder_escape( $found ) );
727+
$this->assertMatchesRegularExpression( "/DATE_FORMAT\( post_date, '%H\.%i%s' \) = 5\.15350*/", $wpdb->remove_placeholder_escape( $found ) );
728728
}
729729

730730
public function test_build_time_query_minute_second() {
@@ -735,7 +735,7 @@ public function test_build_time_query_minute_second() {
735735

736736
// $compare value is floating point - use regex to account for
737737
// varying precision on different PHP installations.
738-
$this->assertRegExp( "/DATE_FORMAT\( post_date, '0\.%i%s' \) = 0\.15350*/", $wpdb->remove_placeholder_escape( $found ) );
738+
$this->assertMatchesRegularExpression( "/DATE_FORMAT\( post_date, '0\.%i%s' \) = 0\.15350*/", $wpdb->remove_placeholder_escape( $found ) );
739739
}
740740

741741
/**

tests/phpunit/tests/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ function test_wp_unique_id() {
12071207
$ids = array();
12081208
for ( $i = 0; $i < 20; $i += 1 ) {
12091209
$id = wp_unique_id( 'foo-' );
1210-
$this->assertRegExp( '/^foo-\d+$/', $id );
1210+
$this->assertMatchesRegularExpression( '/^foo-\d+$/', $id );
12111211
$ids[] = $id;
12121212
}
12131213
$this->assertSame( $ids, array_unique( $ids ) );

tests/phpunit/tests/meta/query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ public function test_empty_compare() {
925925
$sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
926926

927927
// Use regex because we don't care about the whitespace before OR.
928-
$this->assertRegExp( "/{$wpdb->postmeta}\.meta_key = \'exclude\'\s+OR/", $sql['where'] );
928+
$this->assertMatchesRegularExpression( "/{$wpdb->postmeta}\.meta_key = \'exclude\'\s+OR/", $sql['where'] );
929929
$this->assertStringNotContainsString( "{$wpdb->postmeta}.post_id IS NULL", $sql['where'] );
930930
}
931931

0 commit comments

Comments
 (0)