Skip to content

Commit

Permalink
Tests: replace assertNotRegExp() with `assertDoesNotMatchRegularExp…
Browse files Browse the repository at this point in the history
…ression()`

The `assertRegExp()` and `assertNotRegExp()` methods were hard deprecated in PHPUnit 9.1 and the functionality will be removed in PHPUnit 10.0.0.

The `assertMatchesRegularExpression()` and `assertDoesNotMatchRegularExpression()` methods were introduced as a replacement in PHPUnit 9.1.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/9.1.5/ChangeLog-9.1.md#910---2020-04-03
* sebastianbergmann/phpunit#4085
* sebastianbergmann/phpunit#4088
  • Loading branch information
jrfnl committed Aug 16, 2020
1 parent 1d47254 commit 81b31a1
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tests/phpunit/tests/category/wpDropdownCategories.php
Expand Up @@ -227,7 +227,7 @@ public function test_required_false_should_omit_required_attribute() {
$dropdown_categories = wp_dropdown_categories( $args );

// Test to see if it contains the "required" attribute.
$this->assertNotRegExp( '/<select[^>]+required/', $dropdown_categories );
$this->assertDoesNotMatchRegularExpression( '/<select[^>]+required/', $dropdown_categories );
}

/**
Expand All @@ -251,6 +251,6 @@ public function test_required_should_default_to_false() {
$dropdown_categories = wp_dropdown_categories( $args );

// Test to see if it contains the "required" attribute.
$this->assertNotRegExp( '/<select[^>]+required/', $dropdown_categories );
$this->assertDoesNotMatchRegularExpression( '/<select[^>]+required/', $dropdown_categories );
}
}
10 changes: 5 additions & 5 deletions tests/phpunit/tests/category/wpListCategories.php
Expand Up @@ -29,7 +29,7 @@ public function test_class_containing_current_cat() {
)
);

$this->assertNotRegExp( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat[^"]*"/', $found );
$this->assertDoesNotMatchRegularExpression( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat[^"]*"/', $found );
$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $c2 . '[^"]*current-cat[^"]*"/', $found );
}

Expand All @@ -50,7 +50,7 @@ public function test_class_containing_current_cat_parent() {
);

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

/**
Expand All @@ -68,7 +68,7 @@ public function test_current_category_should_accept_an_array_of_ids() {
);

$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $cats[0] . '[^"]*current-cat[^"]*"/', $found );
$this->assertNotRegExp( '/class="[^"]*cat-item-' . $cats[1] . '[^"]*current[^"]*"/', $found );
$this->assertDoesNotMatchRegularExpression( '/class="[^"]*cat-item-' . $cats[1] . '[^"]*current[^"]*"/', $found );
$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $cats[2] . '[^"]*current-cat[^"]*"/', $found );
}

Expand Down Expand Up @@ -652,7 +652,7 @@ public function test_class_containing_current_cat_ancestor() {

$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $parent . '[^"]*current-cat-ancestor[^"]*"/', $actual );
$this->assertMatchesRegularExpression( '/class="[^"]*cat-item-' . $child . '[^"]*current-cat-ancestor[^"]*"/', $actual );
$this->assertNotRegExp( '/class="[^"]*cat-item-' . $grandchild . '[^"]*current-cat-ancestor[^"]*"/', $actual );
$this->assertNotRegExp( '/class="[^"]*cat-item-' . $child2 . '[^"]*current-cat-ancestor[^"]*"/', $actual );
$this->assertDoesNotMatchRegularExpression( '/class="[^"]*cat-item-' . $grandchild . '[^"]*current-cat-ancestor[^"]*"/', $actual );
$this->assertDoesNotMatchRegularExpression( '/class="[^"]*cat-item-' . $child2 . '[^"]*current-cat-ancestor[^"]*"/', $actual );
}
}
2 changes: 1 addition & 1 deletion tests/phpunit/tests/menu/walker-nav-menu-edit.php
Expand Up @@ -55,6 +55,6 @@ function test_original_title_prefix_should_not_be_shown_if_empty() {

$this->walker->start_el( $expected, (object) $item );

$this->assertNotRegExp( '#<p class="link-to-original">\s*Original: <a href=""></a>#', $expected );
$this->assertDoesNotMatchRegularExpression( '#<p class="link-to-original">\s*Original: <a href=""></a>#', $expected );
}
}
2 changes: 1 addition & 1 deletion tests/phpunit/tests/post/getPostsByAuthorSql.php
Expand Up @@ -39,7 +39,7 @@ public function test_full_true() {

public function test_full_false() {
$maybe_string = get_posts_by_author_sql( 'post', false );
$this->assertNotRegExp( '/^WHERE /', $maybe_string );
$this->assertDoesNotMatchRegularExpression( '/^WHERE /', $maybe_string );
}

public function test_post_type_clause_should_be_included_when_full_is_true() {
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/post/nav-menu.php
Expand Up @@ -461,7 +461,7 @@ function test_wp_nav_menu_whitespace_options() {

// The markup should include whitespace between <li>'s.
$this->assertMatchesRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
$this->assertNotRegExp( '/<\/li><li.*>/U', $menu );
$this->assertDoesNotMatchRegularExpression( '/<\/li><li.*>/U', $menu );

// Whitespace suppressed.
$menu = wp_nav_menu(
Expand All @@ -473,7 +473,7 @@ function test_wp_nav_menu_whitespace_options() {
);

// The markup should not include whitespace around <li>'s.
$this->assertNotRegExp( '/\s<li.*>|<\/li>\s/U', $menu );
$this->assertDoesNotMatchRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
$this->assertMatchesRegularExpression( '/><li.*>|<\/li></U', $menu );
}

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/tests/post/template.php
Expand Up @@ -319,7 +319,7 @@ public function test_wp_dropdown_pages_should_not_contain_class_attribute_when_n
)
);

$this->assertNotRegExp( '/<select[^>]+class=\'/', $found );
$this->assertDoesNotMatchRegularExpression( '/<select[^>]+class=\'/', $found );
}

/**
Expand Down Expand Up @@ -426,7 +426,7 @@ public function test_wp_page_menu_wp_nav_menu_fallback() {

// After falling back, the markup should include whitespace around <li>'s.
$this->assertMatchesRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
$this->assertNotRegExp( '/><li.*>|<\/li></U', $menu );
$this->assertDoesNotMatchRegularExpression( '/><li.*>|<\/li></U', $menu );

// No menus + wp_nav_menu() falls back to wp_page_menu(), this time without a container.
$menu = wp_nav_menu(
Expand All @@ -448,7 +448,7 @@ public function test_wp_page_menu_wp_nav_menu_fallback() {
);

// After falling back, the markup should not include whitespace around <li>'s.
$this->assertNotRegExp( '/\s<li.*>|<\/li>\s/U', $menu );
$this->assertDoesNotMatchRegularExpression( '/\s<li.*>|<\/li>\s/U', $menu );
$this->assertMatchesRegularExpression( '/><li.*>|<\/li></U', $menu );

}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/query/results.php
Expand Up @@ -804,7 +804,7 @@ function test_exclude_from_search_empty() {
$posts2 = $this->q->query( array( 'post_type' => 'any' ) );

$this->assertNotEmpty( $posts2 );
$this->assertNotRegExp( '#AND 1=0#', $this->q->request );
$this->assertDoesNotMatchRegularExpression( '#AND 1=0#', $this->q->request );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/query/search.php
Expand Up @@ -260,7 +260,7 @@ public function test_search_orderby_should_be_empty_when_search_string_is_longer
)
);

$this->assertNotRegExp( '|ORDER BY \(CASE[^\)]+\)|', $q->request );
$this->assertDoesNotMatchRegularExpression( '|ORDER BY \(CASE[^\)]+\)|', $q->request );
}

/**
Expand Down

0 comments on commit 81b31a1

Please sign in to comment.