diff --git a/tests/phpunit/tests/comment/template.php b/tests/phpunit/tests/comment/template.php index 68f98b5c8b..22283a5c2e 100644 --- a/tests/phpunit/tests/comment/template.php +++ b/tests/phpunit/tests/comment/template.php @@ -3,9 +3,24 @@ * @group comment */ class Tests_Comment_Template extends WP_UnitTestCase { + /** + * Shared post ID. + * + * @var int + */ + public static $post_id; + + /** + * Set up shared fixtures. + * + * @param WP_UnitTest_Factory $factory Unit test factory. + */ + function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$post_id = self::factory()->post->create(); + } function test_get_comments_number() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; $this->assertSame( 0, get_comments_number( 0 ) ); $this->assertSame( '0', get_comments_number( $post_id ) ); @@ -18,7 +33,7 @@ class Tests_Comment_Template extends WP_UnitTestCase { } function test_get_comments_number_without_arg() { - $post_id = self::factory()->post->create(); + $post_id = self::$post_id; $permalink = get_permalink( $post_id ); $this->go_to( $permalink ); @@ -34,7 +49,7 @@ class Tests_Comment_Template extends WP_UnitTestCase { * @ticket 48772 */ function test_get_comments_number_text_with_post_id() { - $post_id = $this->factory->post->create(); + $post_id = self::$post_id; $this->factory->comment->create_post_comments( $post_id, 6 ); $comments_number_text = get_comments_number_text( false, false, false, $post_id ); @@ -53,7 +68,7 @@ class Tests_Comment_Template extends WP_UnitTestCase { * @ticket 13651 */ function test_get_comments_number_text_declension_with_default_args() { - $post_id = $this->factory->post->create(); + $post_id = self::$post_id; $permalink = get_permalink( $post_id ); $this->go_to( $permalink ); @@ -76,7 +91,7 @@ class Tests_Comment_Template extends WP_UnitTestCase { * @dataProvider data_get_comments_number_text_declension */ function test_get_comments_number_text_declension_with_custom_args( $number, $input, $output ) { - $post_id = $this->factory->post->create(); + $post_id = self::$post_id; $permalink = get_permalink( $post_id ); $this->factory->comment->create_post_comments( $post_id, $number );