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/slashes.php

    r34173 r35225  
    1010        parent::setUp();
    1111        // we need an admin user to bypass comment flood protection
    12         $this->author_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     12        $this->author_id = self::$factory->user->create( array( 'role' => 'administrator' ) );
    1313        $this->old_current_user = get_current_user_id();
    1414        wp_set_current_user( $this->author_id );
     
    3535     */
    3636    function test_wp_new_comment() {
    37         $post_id = $this->factory->post->create();
     37        $post_id = self::$factory->post->create();
    3838
    3939        // not testing comment_author_email or comment_author_url
     
    7575     */
    7676    function test_edit_comment() {
    77         $post_id = $this->factory->post->create();
    78         $comment_id = $this->factory->comment->create(array(
     77        $post_id = self::$factory->post->create();
     78        $comment_id = self::$factory->comment->create(array(
    7979            'comment_post_ID' => $post_id
    8080        ));
     
    118118     */
    119119    function test_wp_insert_comment() {
    120         $post_id = $this->factory->post->create();
     120        $post_id = self::$factory->post->create();
    121121
    122122        $comment_id = wp_insert_comment(array(
     
    146146     */
    147147    function test_wp_update_comment() {
    148         $post_id = $this->factory->post->create();
    149         $comment_id = $this->factory->comment->create(array(
     148        $post_id = self::$factory->post->create();
     149        $comment_id = self::$factory->comment->create(array(
    150150            'comment_post_ID' => $post_id
    151151        ));
Note: See TracChangeset for help on using the changeset viewer.