WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/19/2021 02:00:11 PM (6 months ago)
Author:
SergeyBiryukov
Message:

Tests: Replace assertContains() with assertStringContainsString() when used with strings.

Using the assertContains() and assertNotContains() methods with string haystacks was deprecated in PHPUnit 8 and removed in PHPUnit 9.

While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+.

These methods introduced in PHPUnit 7.5 should be used as an alternative:

  • assertStringContainsString()
  • assertStringContainsStringIgnoringCase
  • assertStringNotContainsString()
  • assertStringNotContainsStringIgnoringCase

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

Follow-up to [51331], [51451], [51461].

Props jrf, dd32, SergeyBiryukov.
See #53363, #46149.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/widgets/media-video-widget.php

    r49117 r51462  
    258258
    259259        // Check default outputs.
    260         $this->assertContains( 'preload="metadata"', $output );
    261         $this->assertContains( 'class="wp-video"', $output );
    262         $this->assertContains( 'width:100%', $output );
    263         $this->assertNotContains( 'height=', $output );
    264         $this->assertNotContains( 'width="', $output );
    265         $this->assertContains( 'small-video.m4v', $output );// Auto parses dimensions.
     260        $this->assertStringContainsString( 'preload="metadata"', $output );
     261        $this->assertStringContainsString( 'class="wp-video"', $output );
     262        $this->assertStringContainsString( 'width:100%', $output );
     263        $this->assertStringNotContainsString( 'height=', $output );
     264        $this->assertStringNotContainsString( 'width="', $output );
     265        $this->assertStringContainsString( 'small-video.m4v', $output );// Auto parses dimensions.
    266266
    267267        ob_start();
     
    277277
    278278        // Custom attributes.
    279         $this->assertContains( 'preload="metadata"', $output );
    280         $this->assertContains( 'loop="1"', $output );
     279        $this->assertStringContainsString( 'preload="metadata"', $output );
     280        $this->assertStringContainsString( 'loop="1"', $output );
    281281
    282282        // Externally hosted video.
     
    294294
    295295        // Custom attributes.
    296         $this->assertContains( 'preload="metadata"', $output );
    297         $this->assertContains( 'src="https://www.youtube.com/watch?v=72xdCU__XCk', $output );
    298         $this->assertContains( $content, $output );
     296        $this->assertStringContainsString( 'preload="metadata"', $output );
     297        $this->assertStringContainsString( 'src="https://www.youtube.com/watch?v=72xdCU__XCk', $output );
     298        $this->assertStringContainsString( $content, $output );
    299299    }
    300300
     
    351351        $output = ob_get_clean();
    352352
    353         $this->assertContains( '<script type="text/html" id="tmpl-wp-media-widget-video-preview">', $output );
     353        $this->assertStringContainsString( '<script type="text/html" id="tmpl-wp-media-widget-video-preview">', $output );
    354354    }
    355355}
Note: See TracChangeset for help on using the changeset viewer.