WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/16/2015 09:04:12 PM (6 years ago)
Author:
wonderboymusic
Message:

Unit Tests: one $factory to rule them all, and it shall be static.

Using more than one instance of WP_UnitTest_Factory causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use setUpBeforeClass, we were creating ad hoc instances. To avoid that, we were injecting one static instance via Dependency Injection in wpSetUpBeforeClass. All tests should really use the static instance, so we will remove the instance prop $factory.

Replace $this->factory with self::$factory over 2000 times.
Rewrite all of the tests that were hard-coding dynamic values.

#YOLOFriday

File:
1 edited

Legend:

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

    r34454 r35225  
    66class Tests_Comment_GetCommentClass extends WP_UnitTestCase {
    77    public function test_should_accept_comment_id() {
    8         $post_id    = $this->factory->post->create();
    9         $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id ) );
     8        $post_id    = self::$factory->post->create();
     9        $comment_id = self::$factory->comment->create( array( 'comment_post_ID' => $post_id ) );
    1010
    1111        $classes = get_comment_class( '', $comment_id );
     
    1414
    1515    public function test_should_accept_comment_object() {
    16         $post_id = $this->factory->post->create();
    17         $comment = $this->factory->comment->create_and_get( array( 'comment_post_ID' => $post_id ) );
     16        $post_id = self::$factory->post->create();
     17        $comment = self::$factory->comment->create_and_get( array( 'comment_post_ID' => $post_id ) );
    1818
    1919        $classes = get_comment_class( '', $comment );
     
    2222
    2323    public function test_should_append_single_class() {
    24         $post_id    = $this->factory->post->create();
    25         $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id ) );
     24        $post_id    = self::$factory->post->create();
     25        $comment_id = self::$factory->comment->create( array( 'comment_post_ID' => $post_id ) );
    2626
    2727        $classes = get_comment_class( 'foo', $comment_id );
     
    3030
    3131    public function test_should_append_array_of_classes() {
    32         $post_id    = $this->factory->post->create();
    33         $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id ) );
     32        $post_id    = self::$factory->post->create();
     33        $comment_id = self::$factory->comment->create( array( 'comment_post_ID' => $post_id ) );
    3434
    3535        $classes = get_comment_class( array( 'foo', 'bar' ), $comment_id );
Note: See TracChangeset for help on using the changeset viewer.