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

    r51419 r51462  
    110110        $this->assertTrue( $result );
    111111        $this->assertSame( self::$test_user->user_email, $mailer->get_recipient( 'to' )->address );
    112         $this->assertContains( 'Confirm Action: Export Personal Data', $mailer->get_sent()->subject );
    113         $this->assertContains( 'action=confirmaction&request_id=', $mailer->get_sent()->body );
    114         $this->assertContains( 'Export Personal Data', $mailer->get_sent()->body );
     112        $this->assertStringContainsString( 'Confirm Action: Export Personal Data', $mailer->get_sent()->subject );
     113        $this->assertStringContainsString( 'action=confirmaction&request_id=', $mailer->get_sent()->body );
     114        $this->assertStringContainsString( 'Export Personal Data', $mailer->get_sent()->body );
    115115    }
    116116
     
    128128        $this->assertTrue( $result );
    129129        $this->assertSame( self::$test_user->user_email, $mailer->get_recipient( 'to' )->address );
    130         $this->assertContains( 'Confirm Action: Erase Personal Data', $mailer->get_sent()->subject );
    131         $this->assertContains( 'action=confirmaction&request_id=', $mailer->get_sent()->body );
    132         $this->assertContains( 'Erase Personal Data', $mailer->get_sent()->body );
     130        $this->assertStringContainsString( 'Confirm Action: Erase Personal Data', $mailer->get_sent()->subject );
     131        $this->assertStringContainsString( 'action=confirmaction&request_id=', $mailer->get_sent()->body );
     132        $this->assertStringContainsString( 'Erase Personal Data', $mailer->get_sent()->body );
    133133    }
    134134
     
    146146        $this->assertTrue( $result );
    147147        $this->assertSame( self::$test_user->user_email, $mailer->get_recipient( 'to' )->address );
    148         $this->assertContains( 'Confirm Action: Export Personal Data', $mailer->get_sent()->subject );
    149         $this->assertContains( 'action=confirmaction&request_id=', $mailer->get_sent()->body );
    150         $this->assertContains( 'Export Personal Data', $mailer->get_sent()->body );
     148        $this->assertStringContainsString( 'Confirm Action: Export Personal Data', $mailer->get_sent()->subject );
     149        $this->assertStringContainsString( 'action=confirmaction&request_id=', $mailer->get_sent()->body );
     150        $this->assertStringContainsString( 'Export Personal Data', $mailer->get_sent()->body );
    151151    }
    152152
     
    164164        $this->assertTrue( $result );
    165165        $this->assertSame( self::$test_user->user_email, $mailer->get_recipient( 'to' )->address );
    166         $this->assertContains( 'Confirm Action: Erase Personal Data', $mailer->get_sent()->subject );
    167         $this->assertContains( 'action=confirmaction&request_id=', $mailer->get_sent()->body );
    168         $this->assertContains( 'Erase Personal Data', $mailer->get_sent()->body );
     166        $this->assertStringContainsString( 'Confirm Action: Erase Personal Data', $mailer->get_sent()->subject );
     167        $this->assertStringContainsString( 'action=confirmaction&request_id=', $mailer->get_sent()->body );
     168        $this->assertStringContainsString( 'Erase Personal Data', $mailer->get_sent()->body );
    169169    }
    170170
     
    210210
    211211        $this->assertTrue( $result );
    212         $this->assertContains( 'Custom Email Content.', $mailer->get_sent()->body );
     212        $this->assertStringContainsString( 'Custom Email Content.', $mailer->get_sent()->body );
    213213    }
    214214
     
    240240        $mailer = tests_retrieve_phpmailer_instance();
    241241
    242         $this->assertContains( 'From: Tester <tester@example.com>', $mailer->get_sent()->header );
     242        $this->assertStringContainsString( 'From: Tester <tester@example.com>', $mailer->get_sent()->header );
    243243    }
    244244
     
    289289        $mailer = tests_retrieve_phpmailer_instance();
    290290
    291         $this->assertContains( 'Confirmar la', $mailer->get_sent()->subject );
     291        $this->assertStringContainsString( 'Confirmar la', $mailer->get_sent()->subject );
    292292    }
    293293
     
    311311        $mailer = tests_retrieve_phpmailer_instance();
    312312
    313         $this->assertContains( 'Aktion bestätigen', $mailer->get_sent()->subject );
     313        $this->assertStringContainsString( 'Aktion bestätigen', $mailer->get_sent()->subject );
    314314    }
    315315
     
    333333        $mailer = tests_retrieve_phpmailer_instance();
    334334
    335         $this->assertContains( 'Confirmar la', $mailer->get_sent()->subject );
     335        $this->assertStringContainsString( 'Confirmar la', $mailer->get_sent()->subject );
    336336    }
    337337
     
    357357        $mailer = tests_retrieve_phpmailer_instance();
    358358
    359         $this->assertContains( 'Confirm Action', $mailer->get_sent()->subject );
     359        $this->assertStringContainsString( 'Confirm Action', $mailer->get_sent()->subject );
    360360    }
    361361
     
    376376        $mailer = tests_retrieve_phpmailer_instance();
    377377
    378         $this->assertContains( 'Confirm Action', $mailer->get_sent()->subject );
     378        $this->assertStringContainsString( 'Confirm Action', $mailer->get_sent()->subject );
    379379    }
    380380
     
    398398        $mailer = tests_retrieve_phpmailer_instance();
    399399
    400         $this->assertContains( 'Confirmar la', $mailer->get_sent()->subject );
     400        $this->assertStringContainsString( 'Confirmar la', $mailer->get_sent()->subject );
    401401    }
    402402}
Note: See TracChangeset for help on using the changeset viewer.