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/rest-api/rest-posts-controller.php

    r51461 r51462  
    15331533        );
    15341534        $this->assertStringNotContainsString( 'rel="prev"', $headers['Link'] );
    1535         $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
     1535        $this->assertStringContainsString( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    15361536
    15371537        // 3rd page.
     
    15511551            rest_url( '/wp/v2/posts' )
    15521552        );
    1553         $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
     1553        $this->assertStringContainsString( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    15541554        $next_link = add_query_arg(
    15551555            array(
     
    15581558            rest_url( '/wp/v2/posts' )
    15591559        );
    1560         $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
     1560        $this->assertStringContainsString( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    15611561
    15621562        // Last page.
     
    15731573            rest_url( '/wp/v2/posts' )
    15741574        );
    1575         $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
     1575        $this->assertStringContainsString( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    15761576        $this->assertStringNotContainsString( 'rel="next"', $headers['Link'] );
    15771577
     
    16031603            rest_url( '/wp/v2/posts' )
    16041604        );
    1605         $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
     1605        $this->assertStringContainsString( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    16061606        $next_link = add_query_arg(
    16071607            array(
     
    16111611            rest_url( '/wp/v2/posts' )
    16121612        );
    1613         $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
     1613        $this->assertStringContainsString( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    16141614    }
    16151615
     
    18851885        $response = rest_get_server()->dispatch( $request );
    18861886        $data     = $response->get_data();
    1887         $this->assertNotContains( $post_content, $data['content']['rendered'] );
     1887        $this->assertStringNotContainsString( $post_content, $data['content']['rendered'] );
    18881888    }
    18891889
Note: See TracChangeset for help on using the changeset viewer.