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/term/wpGenerateTagCloud.php

    r51331 r51462  
    8484        );
    8585
    86         $this->assertContains( '>' . $tags[0]->name . '<', $found );
     86        $this->assertStringContainsString( '>' . $tags[0]->name . '<', $found );
    8787    }
    8888
     
    108108
    109109        $this->assertIsArray( $found );
    110         $this->assertContains( '>' . $tags[0]->name . '<', $found[0] );
     110        $this->assertStringContainsString( '>' . $tags[0]->name . '<', $found[0] );
    111111    }
    112112
     
    132132        $this->assertRegExp( "|^<ul class='wp-tag-cloud' role='list'>|", $found );
    133133        $this->assertRegExp( "|</ul>\n|", $found );
    134         $this->assertContains( '>' . $tags[0]->name . '<', $found );
     134        $this->assertStringContainsString( '>' . $tags[0]->name . '<', $found );
    135135    }
    136136
     
    158158
    159159        foreach ( $tags as $tag ) {
    160             $this->assertContains( '>' . $tag->name . '<', $found );
     160            $this->assertStringContainsString( '>' . $tag->name . '<', $found );
    161161        }
    162162    }
     
    189189
    190190        foreach ( $tags as $tag ) {
    191             $this->assertContains( '>' . $tag->name . '<', $found );
     191            $this->assertStringContainsString( '>' . $tag->name . '<', $found );
    192192        }
    193193    }
     
    225225        );
    226226
    227         $this->assertContains( 'aria-label="' . $term_objects[0]->name . ' (Term has 1 post)"', $actual[0] );
    228         $this->assertContains( 'aria-label="' . $term_objects[1]->name . ' (Term has 2 posts)"', $actual[1] );
     227        $this->assertStringContainsString( 'aria-label="' . $term_objects[0]->name . ' (Term has 1 post)"', $actual[0] );
     228        $this->assertStringContainsString( 'aria-label="' . $term_objects[1]->name . ' (Term has 2 posts)"', $actual[1] );
    229229    }
    230230
     
    256256        );
    257257
    258         $this->assertContains( 'aria-label="' . $term_objects[0]->name . ' (1 foo)"', $actual[0] );
    259         $this->assertContains( 'aria-label="' . $term_objects[1]->name . ' (2 foo)"', $actual[1] );
     258        $this->assertStringContainsString( 'aria-label="' . $term_objects[0]->name . ' (1 foo)"', $actual[0] );
     259        $this->assertStringContainsString( 'aria-label="' . $term_objects[1]->name . ' (2 foo)"', $actual[1] );
    260260    }
    261261
Note: See TracChangeset for help on using the changeset viewer.