Make WordPress Core

Changeset 49863


Ignore:
Timestamp:
12/22/2020 07:42:23 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use shared post fixture in comment template tests.

This reinstates [49848], previously reverted in [49849], with the addition of static keyword for the wpSetUpBeforeClass() method, allowing the tests to pass on PHP 8.

Props peterwilsoncc.
See #51802.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/template.php

    r49849 r49863  
    44 */
    55class Tests_Comment_Template extends WP_UnitTestCase {
     6    /**
     7     * Shared post ID.
     8     *
     9     * @var int
     10     */
     11    public static $post_id;
     12
     13    /**
     14     * Set up shared fixtures.
     15     *
     16     * @param WP_UnitTest_Factory $factory Unit test factory.
     17     */
     18    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     19        self::$post_id = self::factory()->post->create();
     20    }
    621
    722    function test_get_comments_number() {
    8         $post_id = self::factory()->post->create();
     23        $post_id = self::$post_id;
    924
    1025        $this->assertSame( 0, get_comments_number( 0 ) );
     
    1934
    2035    function test_get_comments_number_without_arg() {
    21         $post_id   = self::factory()->post->create();
     36        $post_id   = self::$post_id;
    2237        $permalink = get_permalink( $post_id );
    2338        $this->go_to( $permalink );
     
    3550     */
    3651    function test_get_comments_number_text_with_post_id() {
    37         $post_id = $this->factory->post->create();
     52        $post_id = self::$post_id;
    3853        $this->factory->comment->create_post_comments( $post_id, 6 );
    3954
     
    5469     */
    5570    function test_get_comments_number_text_declension_with_default_args() {
    56         $post_id   = $this->factory->post->create();
     71        $post_id   = self::$post_id;
    5772        $permalink = get_permalink( $post_id );
    5873        $this->go_to( $permalink );
     
    7792     */
    7893    function test_get_comments_number_text_declension_with_custom_args( $number, $input, $output ) {
    79         $post_id   = $this->factory->post->create();
     94        $post_id   = self::$post_id;
    8095        $permalink = get_permalink( $post_id );
    8196
Note: See TracChangeset for help on using the changeset viewer.