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/comment/commentForm.php

    r46586 r51462  
    3636
    3737        $button = '<input name="custom-foo-name" type="submit" id="custom-foo-id" class="custom-foo-class" value="custom-foo-label" />';
    38         $this->assertContains( $button, $form );
     38        $this->assertStringContainsString( $button, $form );
    3939    }
    4040
     
    114114        $form_with_aria = get_echo( 'comment_form', array( array(), $p ) );
    115115
    116         $this->assertContains( 'aria-describedby="email-notes"', $form_with_aria );
     116        $this->assertStringContainsString( 'aria-describedby="email-notes"', $form_with_aria );
    117117
    118118        $args = array(
     
    122122        $form_without_aria = get_echo( 'comment_form', array( $args, $p ) );
    123123
    124         $this->assertNotContains( 'aria-describedby="email-notes"', $form_without_aria );
     124        $this->assertStringNotContainsString( 'aria-describedby="email-notes"', $form_without_aria );
    125125    }
    126126}
Note: See TracChangeset for help on using the changeset viewer.