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/user/wpDropdownUsers.php

    r49036 r51462  
    2929        $expected = "<option value='$u'>Foo Person</option>";
    3030
    31         $this->assertContains( $expected, $found );
     31        $this->assertStringContainsString( $expected, $found );
    3232    }
    3333
     
    5555        $expected = "<option value='$u'>Foo Person</option>";
    5656
    57         $this->assertContains( $expected, $found );
     57        $this->assertStringContainsString( $expected, $found );
    5858    }
    5959
     
    8181        $expected = "<option value='$u'>foo</option>";
    8282
    83         $this->assertContains( $expected, $found );
     83        $this->assertStringContainsString( $expected, $found );
    8484    }
    8585
     
    107107        $expected = "<option value='$u'>Foo Person (foo)</option>";
    108108
    109         $this->assertContains( $expected, $found );
     109        $this->assertStringContainsString( $expected, $found );
    110110    }
    111111
     
    127127
    128128        $user1 = get_userdata( $users[1] );
    129         $this->assertContains( $user1->user_login, $found );
     129        $this->assertStringContainsString( $user1->user_login, $found );
    130130    }
    131131
     
    143143        );
    144144
    145         $this->assertNotContains( (string) PHP_INT_MAX, $found );
     145        $this->assertStringNotContainsString( (string) PHP_INT_MAX, $found );
    146146    }
    147147
     
    161161        );
    162162
    163         $this->assertNotContains( $u1->user_login, $found );
    164         $this->assertContains( $u2->user_login, $found );
     163        $this->assertStringNotContainsString( $u1->user_login, $found );
     164        $this->assertStringContainsString( $u2->user_login, $found );
    165165    }
    166166
     
    180180        );
    181181
    182         $this->assertNotContains( $u1->user_login, $found );
    183         $this->assertContains( $u2->user_login, $found );
     182        $this->assertStringNotContainsString( $u1->user_login, $found );
     183        $this->assertStringContainsString( $u2->user_login, $found );
    184184    }
    185185
     
    199199        );
    200200
    201         $this->assertNotContains( $u1->user_login, $found );
    202         $this->assertContains( $u2->user_login, $found );
     201        $this->assertStringNotContainsString( $u1->user_login, $found );
     202        $this->assertStringContainsString( $u2->user_login, $found );
    203203    }
    204204}
Note: See TracChangeset for help on using the changeset viewer.