Make WordPress Core


Ignore:
Timestamp:
07/19/2021 02:00:11 PM (6 months ago)
Author:
SergeyBiryukov
Message:

Tests: Replace assertContains() with assertStringContainsString() when used with strings.

Using the assertContains() and assertNotContains() methods with string haystacks was deprecated in PHPUnit 8 and removed in PHPUnit 9.

While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+.

These methods introduced in PHPUnit 7.5 should be used as an alternative:

  • assertStringContainsString()
  • assertStringContainsStringIgnoringCase
  • assertStringNotContainsString()
  • assertStringNotContainsStringIgnoringCase

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods were added to the WP_UnitTestCase class for PHPUnit < 7.5.

Follow-up to [51331], [51451], [51461].

Props jrf, dd32, SergeyBiryukov.
See #53363, #46149.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/control.php

    r47198 r51462  
    119119        $page_on_front_control->maybe_render();
    120120        $content = ob_get_clean();
    121         $this->assertNotContains( 'add-new-toggle', $content );
     121        $this->assertStringNotContainsString( 'add-new-toggle', $content );
    122122
    123123        // Ensure the add-new-toggle is absent if allow_addition param is set.
     
    126126        $page_on_front_control->maybe_render();
    127127        $content = ob_get_clean();
    128         $this->assertContains( 'add-new-toggle', $content );
     128        $this->assertStringContainsString( 'add-new-toggle', $content );
    129129
    130130        // Ensure that dropdown-pages delect is rendered even if there are no pages published (yet).
     
    136136        $page_on_front_control->maybe_render();
    137137        $content = ob_get_clean();
    138         $this->assertContains( '<option value="0">', $content, 'Dropdown-pages renders select even without any pages published.' );
     138        $this->assertStringContainsString( '<option value="0">', $content, 'Dropdown-pages renders select even without any pages published.' );
    139139
    140140        // Ensure that auto-draft pages are included if they are among the nav_menus_created_posts.
     
    165165        $page_on_front_control->maybe_render();
    166166        $content = ob_get_clean();
    167         $this->assertContains( sprintf( '<option value="%d">Auto Draft Page</option>', $auto_draft_page_id ), $content );
    168         $this->assertNotContains( 'Auto Draft Post', $content );
    169         $this->assertNotContains( 'Orphan Auto Draft Page', $content );
     167        $this->assertStringContainsString( sprintf( '<option value="%d">Auto Draft Page</option>', $auto_draft_page_id ), $content );
     168        $this->assertStringNotContainsString( 'Auto Draft Post', $content );
     169        $this->assertStringNotContainsString( 'Orphan Auto Draft Page', $content );
    170170    }
    171171
Note: See TracChangeset for help on using the changeset viewer.