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/privacy/wpPrivacySendPersonalDataExportEmail.php

    r50969 r51462  
    115115        $this->assertSame( 'request-confirmed', get_post_status( self::$request_id ) );
    116116        $this->assertSame( self::$requester_email, $mailer->get_recipient( 'to' )->address );
    117         $this->assertContains( 'Personal Data Export', $mailer->get_sent()->subject );
    118         $this->assertContains( $export_file_url, $mailer->get_sent()->body );
    119         $this->assertContains( 'please download it', $mailer->get_sent()->body );
     117        $this->assertStringContainsString( 'Personal Data Export', $mailer->get_sent()->subject );
     118        $this->assertStringContainsString( $export_file_url, $mailer->get_sent()->body );
     119        $this->assertStringContainsString( 'please download it', $mailer->get_sent()->body );
    120120        $this->assertTrue( $email_sent );
    121121    }
     
    161161
    162162        $mailer = tests_retrieve_phpmailer_instance();
    163         $this->assertContains( 'we will automatically delete the file on December 18, 2017,', $mailer->get_sent()->body );
     163        $this->assertStringContainsString( 'we will automatically delete the file on December 18, 2017,', $mailer->get_sent()->body );
    164164    }
    165165
     
    239239
    240240        $mailer = tests_retrieve_phpmailer_instance();
    241         $this->assertContains( 'Custom content for request ID: ' . self::$request_id, $mailer->get_sent()->body );
     241        $this->assertStringContainsString( 'Custom content for request ID: ' . self::$request_id, $mailer->get_sent()->body );
    242242    }
    243243
     
    268268        $mailer = tests_retrieve_phpmailer_instance();
    269269
    270         $this->assertContains( 'From: Tester <tester@example.com>', $mailer->get_sent()->header );
     270        $this->assertStringContainsString( 'From: Tester <tester@example.com>', $mailer->get_sent()->header );
    271271    }
    272272
     
    298298        $site_url = home_url();
    299299        $mailer   = tests_retrieve_phpmailer_instance();
    300         $this->assertContains( 'Custom content using the $site_url of $email_data: ' . $site_url, $mailer->get_sent()->body );
     300        $this->assertStringContainsString( 'Custom content using the $site_url of $email_data: ' . $site_url, $mailer->get_sent()->body );
    301301    }
    302302
     
    342342        $mailer = tests_retrieve_phpmailer_instance();
    343343
    344         $this->assertContains( 'Exportación de datos personales', $mailer->get_sent()->subject );
     344        $this->assertStringContainsString( 'Exportación de datos personales', $mailer->get_sent()->subject );
    345345    }
    346346
     
    364364        $mailer = tests_retrieve_phpmailer_instance();
    365365
    366         $this->assertContains( 'Export personenbezogener Daten', $mailer->get_sent()->subject );
     366        $this->assertStringContainsString( 'Export personenbezogener Daten', $mailer->get_sent()->subject );
    367367    }
    368368
     
    386386        $mailer = tests_retrieve_phpmailer_instance();
    387387
    388         $this->assertContains( 'Exportación de datos personales', $mailer->get_sent()->subject );
     388        $this->assertStringContainsString( 'Exportación de datos personales', $mailer->get_sent()->subject );
    389389    }
    390390
     
    410410        $mailer = tests_retrieve_phpmailer_instance();
    411411
    412         $this->assertContains( 'Export personenbezogener Daten', $mailer->get_sent()->subject );
     412        $this->assertStringContainsString( 'Export personenbezogener Daten', $mailer->get_sent()->subject );
    413413    }
    414414
     
    432432        $mailer = tests_retrieve_phpmailer_instance();
    433433
    434         $this->assertContains( 'Personal Data Export', $mailer->get_sent()->subject );
     434        $this->assertStringContainsString( 'Personal Data Export', $mailer->get_sent()->subject );
    435435    }
    436436
     
    457457        $mailer = tests_retrieve_phpmailer_instance();
    458458
    459         $this->assertContains( 'Exportación de datos personales', $mailer->get_sent()->subject );
     459        $this->assertStringContainsString( 'Exportación de datos personales', $mailer->get_sent()->subject );
    460460    }
    461461}
Note: See TracChangeset for help on using the changeset viewer.