From ee2770bda5098b1fac78cab630b923f0011b9a1d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 6 Aug 2021 21:55:31 +0000 Subject: [PATCH] Tests: Replace `assertNotRegExp()` with `assertDoesNotMatchRegularExpression()`. 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 * https://github.com/sebastianbergmann/phpunit/issues/4085 * https://github.com/sebastianbergmann/phpunit/issues/4088 Follow-up to [51559-51565]. Props jrf. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51566 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/category/wpDropdownCategories.php | 4 ++-- tests/phpunit/tests/category/wpListCategories.php | 10 +++++----- tests/phpunit/tests/menu/walker-nav-menu-edit.php | 2 +- tests/phpunit/tests/post/getPostsByAuthorSql.php | 2 +- tests/phpunit/tests/post/nav-menu.php | 4 ++-- tests/phpunit/tests/post/template.php | 6 +++--- tests/phpunit/tests/query/results.php | 2 +- tests/phpunit/tests/query/search.php | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/phpunit/tests/category/wpDropdownCategories.php b/tests/phpunit/tests/category/wpDropdownCategories.php index d7e5af31b3..c40bd3b490 100644 --- a/tests/phpunit/tests/category/wpDropdownCategories.php +++ b/tests/phpunit/tests/category/wpDropdownCategories.php @@ -227,7 +227,7 @@ class Tests_Category_WpDropdownCategories extends WP_UnitTestCase { $dropdown_categories = wp_dropdown_categories( $args ); // Test to see if it contains the "required" attribute. - $this->assertNotRegExp( '/]+required/', $dropdown_categories ); + $this->assertDoesNotMatchRegularExpression( '/]+required/', $dropdown_categories ); } /** @@ -251,6 +251,6 @@ class Tests_Category_WpDropdownCategories extends WP_UnitTestCase { $dropdown_categories = wp_dropdown_categories( $args ); // Test to see if it contains the "required" attribute. - $this->assertNotRegExp( '/]+required/', $dropdown_categories ); + $this->assertDoesNotMatchRegularExpression( '/]+required/', $dropdown_categories ); } } diff --git a/tests/phpunit/tests/category/wpListCategories.php b/tests/phpunit/tests/category/wpListCategories.php index 7bcc6e263e..eb21fbd484 100644 --- a/tests/phpunit/tests/category/wpListCategories.php +++ b/tests/phpunit/tests/category/wpListCategories.php @@ -29,7 +29,7 @@ class Tests_Category_WpListCategories extends WP_UnitTestCase { ) ); - $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 ); } @@ -50,7 +50,7 @@ class Tests_Category_WpListCategories extends WP_UnitTestCase { ); $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 ); } /** @@ -68,7 +68,7 @@ class Tests_Category_WpListCategories extends WP_UnitTestCase { ); $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 ); } @@ -652,7 +652,7 @@ class Tests_Category_WpListCategories extends WP_UnitTestCase { $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 ); } } diff --git a/tests/phpunit/tests/menu/walker-nav-menu-edit.php b/tests/phpunit/tests/menu/walker-nav-menu-edit.php index 0a8936bb40..5b6d594885 100644 --- a/tests/phpunit/tests/menu/walker-nav-menu-edit.php +++ b/tests/phpunit/tests/menu/walker-nav-menu-edit.php @@ -55,6 +55,6 @@ class Tests_Menu_Walker_Nav_Menu_Edit extends WP_UnitTestCase { $this->walker->start_el( $expected, (object) $item ); - $this->assertNotRegExp( '#
  • 's. $this->assertMatchesRegularExpression( '/\s|<\/li>\s/U', $menu ); - $this->assertNotRegExp( '/<\/li>/U', $menu ); + $this->assertDoesNotMatchRegularExpression( '/<\/li>/U', $menu ); // Whitespace suppressed. $menu = wp_nav_menu( @@ -473,7 +473,7 @@ class Tests_Post_Nav_Menu extends WP_UnitTestCase { ); // The markup should not include whitespace around
  • 's. - $this->assertNotRegExp( '/\s|<\/li>\s/U', $menu ); + $this->assertDoesNotMatchRegularExpression( '/\s|<\/li>\s/U', $menu ); $this->assertMatchesRegularExpression( '/>|<\/li>assertNotRegExp( '/]+class=\'/', $found ); + $this->assertDoesNotMatchRegularExpression( '/]+class=\'/', $found ); } /** @@ -426,7 +426,7 @@ NO; // After falling back, the markup should include whitespace around
  • 's. $this->assertMatchesRegularExpression( '/\s|<\/li>\s/U', $menu ); - $this->assertNotRegExp( '/>|<\/li>assertDoesNotMatchRegularExpression( '/>|<\/li>'s. - $this->assertNotRegExp( '/\s|<\/li>\s/U', $menu ); + $this->assertDoesNotMatchRegularExpression( '/\s|<\/li>\s/U', $menu ); $this->assertMatchesRegularExpression( '/>|<\/li>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 ); } /** diff --git a/tests/phpunit/tests/query/search.php b/tests/phpunit/tests/query/search.php index 2f54f18724..e42053d850 100644 --- a/tests/phpunit/tests/query/search.php +++ b/tests/phpunit/tests/query/search.php @@ -259,7 +259,7 @@ class Tests_Query_Search extends WP_UnitTestCase { ) ); - $this->assertNotRegExp( '|ORDER BY \(CASE[^\)]+\)|', $q->request ); + $this->assertDoesNotMatchRegularExpression( '|ORDER BY \(CASE[^\)]+\)|', $q->request ); } /**