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/widgets/media-widget.php

    r51415 r51462  
    342342        $output = ob_get_clean();
    343343
    344         $this->assertContains( '<h2>Foo</h2>', $output );
    345         $this->assertContains( '<section>', $output );
    346         $this->assertContains( '</section>', $output );
     344        $this->assertStringContainsString( '<h2>Foo</h2>', $output );
     345        $this->assertStringContainsString( '<section>', $output );
     346        $this->assertStringContainsString( '</section>', $output );
    347347
    348348        // No title.
     
    353353        $widget->widget( $args, $instance );
    354354        $output = ob_get_clean();
    355         $this->assertNotContains( '<h2>Foo</h2>', $output );
     355        $this->assertStringNotContainsString( '<h2>Foo</h2>', $output );
    356356
    357357        // No attachment_id nor url.
     
    397397        $output = ob_get_clean();
    398398
    399         $this->assertContains( 'name="widget-mocked[][attachment_id]"', $output );
    400         $this->assertContains( 'name="widget-mocked[][title]"', $output );
    401         $this->assertContains( 'name="widget-mocked[][url]"', $output );
     399        $this->assertStringContainsString( 'name="widget-mocked[][attachment_id]"', $output );
     400        $this->assertStringContainsString( 'name="widget-mocked[][title]"', $output );
     401        $this->assertStringContainsString( 'name="widget-mocked[][url]"', $output );
    402402    }
    403403
     
    469469        $output = ob_get_clean();
    470470
    471         $this->assertContains( '<script type="text/html" id="tmpl-widget-media-mocked-control">', $output );
     471        $this->assertStringContainsString( '<script type="text/html" id="tmpl-widget-media-mocked-control">', $output );
    472472    }
    473473
Note: See TracChangeset for help on using the changeset viewer.