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

    r49256 r51462  
    559559        // This is the main post page, so we don't expect any cpage param.
    560560        foreach ( $matches[1] as $m ) {
    561             $this->assertNotContains( 'cpage', $m );
     561            $this->assertStringNotContainsString( 'cpage', $m );
    562562        }
    563563
     
    579579        // They should all be on page 2.
    580580        foreach ( $matches[1] as $m ) {
    581             $this->assertContains( 'cpage=2', $m );
     581            $this->assertStringContainsString( 'cpage=2', $m );
    582582        }
    583583    }
     
    651651
    652652        foreach ( $matches[1] as $m ) {
    653             $this->assertContains( 'cpage=3', $m );
     653            $this->assertStringContainsString( 'cpage=3', $m );
    654654        }
    655655
     
    671671        // They should all be on page 2.
    672672        foreach ( $matches[1] as $m ) {
    673             $this->assertContains( 'cpage=2', $m );
     673            $this->assertStringContainsString( 'cpage=2', $m );
    674674        }
    675675
     
    692692        // They should all be on page 2.
    693693        foreach ( $matches[1] as $m ) {
    694             $this->assertContains( 'cpage=1', $m );
     694            $this->assertStringContainsString( 'cpage=1', $m );
    695695        }
    696696    }
Note: See TracChangeset for help on using the changeset viewer.