Make WordPress Core


Ignore:
Timestamp:
07/19/2021 02:00:11 PM (4 years 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/comment/query.php

    r51367 r51462  
    24852485            )
    24862486        );
    2487         $this->assertNotContains( 'comment_author LIKE', $q->request );
     2487        $this->assertStringNotContainsString( 'comment_author LIKE', $q->request );
    24882488    }
    24892489
     
    24982498            )
    24992499        );
    2500         $this->assertNotContains( 'comment_author LIKE', $q->request );
     2500        $this->assertStringNotContainsString( 'comment_author LIKE', $q->request );
    25012501    }
    25022502
     
    25112511            )
    25122512        );
    2513         $this->assertNotContains( 'comment_author LIKE', $q->request );
     2513        $this->assertStringNotContainsString( 'comment_author LIKE', $q->request );
    25142514    }
    25152515
     
    25252525            )
    25262526        );
    2527         $this->assertContains( "comment_author LIKE '%0%'", $wpdb->remove_placeholder_escape( $q->request ) );
     2527        $this->assertStringContainsString( "comment_author LIKE '%0%'", $wpdb->remove_placeholder_escape( $q->request ) );
    25282528    }
    25292529
     
    25392539            )
    25402540        );
    2541         $this->assertContains( "comment_author LIKE '%0%'", $wpdb->remove_placeholder_escape( $q->request ) );
     2541        $this->assertStringContainsString( "comment_author LIKE '%0%'", $wpdb->remove_placeholder_escape( $q->request ) );
    25422542    }
    25432543
     
    25482548        $q->query( array() );
    25492549
    2550         $this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
     2550        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
    25512551    }
    25522552
     
    25612561        );
    25622562
    2563         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent", $q->request );
     2563        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent", $q->request );
    25642564    }
    25652565
     
    25742574        );
    25752575
    2576         $this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
     2576        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
    25772577    }
    25782578
     
    25872587        );
    25882588
    2589         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
     2589        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
    25902590    }
    25912591
     
    26002600        );
    26012601
    2602         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
     2602        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
    26032603    }
    26042604
     
    26132613        );
    26142614
    2615         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
     2615        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
    26162616    }
    26172617
     
    26262626        );
    26272627
    2628         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
     2628        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
    26292629    }
    26302630
     
    26392639        );
    26402640
    2641         $this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
     2641        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
    26422642    }
    26432643
     
    26532653        );
    26542654
    2655         $this->assertNotContains( 'ORDER BY', $q->request );
     2655        $this->assertStringNotContainsString( 'ORDER BY', $q->request );
    26562656    }
    26572657
     
    26672667        );
    26682668
    2669         $this->assertNotContains( 'ORDER BY', $q->request );
     2669        $this->assertStringNotContainsString( 'ORDER BY', $q->request );
    26702670    }
    26712671
     
    26812681        );
    26822682
    2683         $this->assertNotContains( 'ORDER BY', $q->request );
     2683        $this->assertStringNotContainsString( 'ORDER BY', $q->request );
    26842684    }
    26852685
     
    27022702        );
    27032703
    2704         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID DESC", $q->request );
     2704        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID DESC", $q->request );
    27052705    }
    27062706
     
    27232723        );
    27242724
    2725         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_ID DESC", $q->request );
     2725        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_ID DESC", $q->request );
    27262726    }
    27272727
     
    27442744        );
    27452745
    2746         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt DESC, $wpdb->comments.comment_ID DESC", $q->request );
     2746        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt DESC, $wpdb->comments.comment_ID DESC", $q->request );
    27472747    }
    27482748
     
    27642764        );
    27652765
    2766         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID ASC", $q->request );
     2766        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID ASC", $q->request );
    27672767    }
    27682768
     
    27842784        );
    27852785
    2786         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date ASC, $wpdb->comments.comment_ID ASC", $q->request );
     2786        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date ASC, $wpdb->comments.comment_ID ASC", $q->request );
    27872787    }
    27882788
     
    28032803        );
    28042804
    2805         $this->assertContains( "ORDER BY $wpdb->comments.comment_agent ASC, $wpdb->comments.comment_ID DESC", $q->request );
     2805        $this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent ASC, $wpdb->comments.comment_ID DESC", $q->request );
    28062806    }
    28072807
Note: See TracChangeset for help on using the changeset viewer.