Make WordPress Core


Ignore:
Timestamp:
07/19/2021 02:00:11 PM (4 years 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/custom-html-widget.php

    r49215 r51462  
    112112        $this->assertNotEmpty( $this->widget_custom_html_content_args );
    113113        $this->assertNotEmpty( $this->widget_text_args );
    114         $this->assertContains( '[filter:widget_text][filter:widget_custom_html_content]', $output );
    115         $this->assertContains( '<section id="custom_html-5" class="widget_text widget widget_custom_html">', $output );
    116         $this->assertContains( '<div class="textwidget custom-html-widget">', $output );
    117         $this->assertNotContains( '<p>', $output );
    118         $this->assertNotContains( '<br>', $output );
    119         $this->assertNotContains( '</u>', $output );
     114        $this->assertStringContainsString( '[filter:widget_text][filter:widget_custom_html_content]', $output );
     115        $this->assertStringContainsString( '<section id="custom_html-5" class="widget_text widget widget_custom_html">', $output );
     116        $this->assertStringContainsString( '<div class="textwidget custom-html-widget">', $output );
     117        $this->assertStringNotContainsString( '<p>', $output );
     118        $this->assertStringNotContainsString( '<br>', $output );
     119        $this->assertStringNotContainsString( '</u>', $output );
    120120        $this->assertSame( $text_widget_instance, $this->widget_text_args[1] );
    121121        $this->assertSame( $instance, $this->widget_custom_html_content_args[1] );
     
    129129        $widget->widget( $args, $instance );
    130130        $output = ob_get_clean();
    131         $this->assertContains( '</u>', $output );
     131        $this->assertStringContainsString( '</u>', $output );
    132132    }
    133133
     
    288288        $output = ob_get_clean();
    289289
    290         $this->assertContains( '<script type="text/html" id="tmpl-widget-custom-html-control-fields">', $output );
     290        $this->assertStringContainsString( '<script type="text/html" id="tmpl-widget-custom-html-control-fields">', $output );
    291291    }
    292292
     
    301301        $help_tab = get_current_screen()->get_help_tab( 'custom_html_widget' );
    302302
    303         $this->assertContains( 'Use the Custom HTML widget to add arbitrary HTML code to your widget areas.', $help_tab['content'] );
     303        $this->assertStringContainsString( 'Use the Custom HTML widget to add arbitrary HTML code to your widget areas.', $help_tab['content'] );
    304304    }
    305305
     
    327327
    328328        $output = get_echo( array( $widget, 'widget' ), array( $args, $instance ) );
    329         $this->assertContains( 'rel="noopener"', $output );
     329        $this->assertStringContainsString( 'rel="noopener"', $output );
    330330    }
    331331
     
    353353
    354354        $output = get_echo( array( $widget, 'widget' ), array( $args, $instance ) );
    355         $this->assertNotContains( 'rel="noopener"', $output );
     355        $this->assertStringNotContainsString( 'rel="noopener"', $output );
    356356    }
    357357
Note: See TracChangeset for help on using the changeset viewer.