Make WordPress Core


Ignore:
Timestamp:
07/17/2021 10:36:52 AM (3 years 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/image/intermediateSize.php

    r51415 r51451  
    107107        // Test for the expected string because the array will by definition
    108108        // return with the correct height and width attributes.
    109         $this->assertTrue( strpos( $image['file'], '330x220' ) > 0 );
     109        $this->assertStringContainsString( '330x220', $image['file'] );
    110110    }
    111111
     
    129129        // Test for the expected string because the array will by definition
    130130        // return with the correct height and width attributes.
    131         $this->assertTrue( strpos( $image['file'], '330x220' ) > 0 );
     131        $this->assertStringContainsString( '330x220', $image['file'] );
    132132    }
    133133
     
    152152        // Test for the expected string because the array will by definition
    153153        // return with the correct height and width attributes.
    154         $this->assertTrue( strpos( $image['file'], '450x300' ) > 0 );
     154        $this->assertStringContainsString( '450x300', $image['file'] );
    155155    }
    156156
     
    202202        // Test for the expected string because the array will by definition
    203203        // return with the correct height and width attributes.
    204         $this->assertTrue( strpos( $image['file'], $image_w . 'x' . $image_h ) > 0 );
     204        $this->assertStringContainsString( $image_w . 'x' . $image_h, $image['file'] );
    205205    }
    206206
     
    231231        // Test for the expected string because the array will by definition
    232232        // return with the correct height and width attributes.
    233         $this->assertTrue( strpos( $image['file'], $image_w . 'x' . $image_h ) > 0 );
     233        $this->assertStringContainsString( $image_w . 'x' . $image_h, $image['file'] );
    234234    }
    235235
     
    256256        $image = image_get_intermediate_size( $id, array( 0, $height ) );
    257257
    258         $this->assertTrue( strpos( $image['file'], $width . 'x' . $height ) > 0 );
     258        $this->assertStringContainsString( $width . 'x' . $height, $image['file'] );
    259259    }
    260260
     
    274274
    275275        // We should get the 'test-size' file and not the thumbnail.
    276         $this->assertTrue( strpos( $image['file'], '200x100' ) > 0 );
     276        $this->assertStringContainsString( '200x100', $image['file'] );
    277277    }
    278278
Note: See TracChangeset for help on using the changeset viewer.