mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-05 23:27:04 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@51451 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -372,4 +372,36 @@ class WP_UnitTestCase extends WP_UnitTestCase_Base {
|
||||
public static function assertIsNotIterable( $actual, $message = '' ) {
|
||||
static::assertFalse( is_iterable( $actual ), $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a string haystack contains a needle.
|
||||
*
|
||||
* This method has been backported from a more recent PHPUnit version,
|
||||
* as tests running on PHP 5.6 use PHPUnit 5.7.x.
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param string $needle The string to search for.
|
||||
* @param string $haystack The string to treat as the haystack.
|
||||
* @param string $message Optional. Message to display when the assertion fails.
|
||||
*/
|
||||
public static function assertStringContainsString( $needle, $haystack, $message = '' ) {
|
||||
static::assertContains( $needle, $haystack, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a string haystack does not contain a needle.
|
||||
*
|
||||
* This method has been backported from a more recent PHPUnit version,
|
||||
* as tests running on PHP 5.6 use PHPUnit 5.7.x.
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param string $needle The string to search for.
|
||||
* @param string $haystack The string to treat as the haystack.
|
||||
* @param string $message Optional. Message to display when the assertion fails.
|
||||
*/
|
||||
public static function assertStringNotContainsString( $needle, $haystack, $message = '' ) {
|
||||
static::assertNotContains( $needle, $haystack, $message );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user