Make WordPress Core


Ignore:
Timestamp:
07/17/2021 10:36:52 AM (23 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/ajax/Autosave.php

    r51450 r51451  
    8080        // Check that the edit happened.
    8181        $post = get_post( self::$post_id );
    82         $this->assertNotFalse( strpos( $post->post_content, $md5 ) );
     82        $this->assertStringContainsString( $md5, $post->post_content );
    8383    }
    8484
     
    126126        // Check that the original post was NOT edited.
    127127        $post = get_post( self::$post_id );
    128         $this->assertFalse( strpos( $post->post_content, $md5 ) );
     128        $this->assertStringNotContainsString( $md5, $post->post_content );
    129129
    130130        // Check if the autosave post was created.
    131131        $autosave = wp_get_post_autosave( self::$post_id, get_current_user_id() );
    132132        $this->assertNotEmpty( $autosave );
    133         $this->assertNotFalse( strpos( $autosave->post_content, $md5 ) );
     133        $this->assertStringContainsString( $md5, $autosave->post_content );
    134134    }
    135135
Note: See TracChangeset for help on using the changeset viewer.