Make WordPress Core


Ignore:
Timestamp:
07/19/2021 02:00:11 PM (3 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/robots.php

    r50566 r51462  
    6969
    7070        $output = get_echo( 'wp_robots' );
    71         $this->assertContains( "'{$expected_directives_string}'", $output );
     71        $this->assertStringContainsString( "'{$expected_directives_string}'", $output );
    7272    }
    7373
     
    8484        update_option( 'blog_public', '0' );
    8585        $output = get_echo( 'wp_robots' );
    86         $this->assertContains( "'noindex, nofollow'", $output );
     86        $this->assertStringContainsString( "'noindex, nofollow'", $output );
    8787    }
    8888
     
    9595        update_option( 'blog_public', '1' );
    9696        $output = get_echo( 'wp_robots' );
    97         $this->assertContains( "'noindex, follow'", $output );
     97        $this->assertStringContainsString( "'noindex, follow'", $output );
    9898
    9999        update_option( 'blog_public', '0' );
    100100        $output = get_echo( 'wp_robots' );
    101         $this->assertContains( "'noindex, nofollow'", $output );
     101        $this->assertStringContainsString( "'noindex, nofollow'", $output );
    102102    }
    103103
     
    109109
    110110        $output = get_echo( 'wp_robots' );
    111         $this->assertContains( "'noindex, noarchive'", $output );
     111        $this->assertStringContainsString( "'noindex, noarchive'", $output );
    112112    }
    113113
     
    120120        update_option( 'blog_public', '1' );
    121121        $output = get_echo( 'wp_robots' );
    122         $this->assertContains( "'max-image-preview:large'", $output );
     122        $this->assertStringContainsString( "'max-image-preview:large'", $output );
    123123
    124124        update_option( 'blog_public', '0' );
     
    135135
    136136        $output = get_echo( 'wp_robots' );
    137         $this->assertContains( 'noindex', $output );
     137        $this->assertStringContainsString( 'noindex', $output );
    138138    }
    139139
     
    146146
    147147        $output = get_echo( 'wp_robots' );
    148         $this->assertNotContains( 'noindex', $output );
     148        $this->assertStringNotContainsString( 'noindex', $output );
    149149    }
    150150
Note: See TracChangeset for help on using the changeset viewer.