WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/17/2021 10:36:52 AM (6 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use more appropriate assertions in various tests.

This replaces instances of assertTrue( strpos( ... ) > 0 ) with assertStringContainsString() to use native PHPUnit functionality.

Going forward, these methods introduced in PHPUnit 7.5 should be used for similar assertions:

  • assertStringContainsString()
  • assertStringNotContainsString()

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods are now added to the WP_UnitTestCase class for PHPUnit < 7.5.

Follow-up to [51335], [51337], [51367], [51397], [51403], [51404], [51436], [51438], [51448], [51449].

See #53363.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/mail.php

    r50610 r51451  
    8282        // We need some better assertions here but these catch the failure for now.
    8383        $this->assertSameIgnoreEOL( $body, $mailer->get_sent()->body );
    84         $this->assertTrue( strpos( iconv_mime_decode_headers( ( $mailer->get_sent()->header ) )['Content-Type'][0], 'boundary="----=_Part_4892_25692638.1192452070893"' ) > 0 );
    85         $this->assertTrue( strpos( $mailer->get_sent()->header, 'charset=' ) > 0 );
     84        $this->assertStringContainsString( 'boundary="----=_Part_4892_25692638.1192452070893"', iconv_mime_decode_headers( ( $mailer->get_sent()->header ) )['Content-Type'][0] );
     85        $this->assertStringContainsString( 'charset=', $mailer->get_sent()->header );
    8686    }
    8787
     
    191191
    192192        $mailer = tests_retrieve_phpmailer_instance();
    193         $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
     193        $this->assertStringContainsString( $expected, $mailer->get_sent()->header );
    194194    }
    195195
     
    207207
    208208        $mailer = tests_retrieve_phpmailer_instance();
    209         $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
     209        $this->assertStringContainsString( $expected, $mailer->get_sent()->header );
    210210    }
    211211
     
    223223
    224224        $mailer = tests_retrieve_phpmailer_instance();
    225         $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
     225        $this->assertStringContainsString( $expected, $mailer->get_sent()->header );
    226226    }
    227227
     
    239239
    240240        $mailer = tests_retrieve_phpmailer_instance();
    241         $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
     241        $this->assertStringContainsString( $expected, $mailer->get_sent()->header );
    242242    }
    243243
     
    255255
    256256        $mailer = tests_retrieve_phpmailer_instance();
    257         $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
     257        $this->assertStringContainsString( $expected, $mailer->get_sent()->header );
    258258    }
    259259
     
    271271
    272272        $mailer = tests_retrieve_phpmailer_instance();
    273         $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
     273        $this->assertStringContainsString( $expected, $mailer->get_sent()->header );
    274274    }
    275275
Note: See TracChangeset for help on using the changeset viewer.