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/media.php

    r51415 r51451  
    16551655        // Test to confirm all sources in the array include the same edit hash.
    16561656        foreach ( $sizes as $size ) {
    1657             $this->assertNotFalse( strpos( $size, $hash ) );
     1657            $this->assertStringContainsString( $hash, $size );
    16581658        }
    16591659    }
     
    22312231        $this->assertFalse( wp_calculate_image_srcset( $size_array, $full_src, $image_meta ) );
    22322232        // Intermediate sized GIFs should not include the full size in the srcset.
    2233         $this->assertFalse( strpos( wp_calculate_image_srcset( $size_array, $large_src, $image_meta ), $full_src ) );
     2233        $this->assertStringNotContainsString( $full_src, wp_calculate_image_srcset( $size_array, $large_src, $image_meta ) );
    22342234    }
    22352235
Note: See TracChangeset for help on using the changeset viewer.