Make WordPress Core


Ignore:
Timestamp:
10/16/2015 09:04:12 PM (11 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/link/getPostCommentsFeedLink.php

    r34810 r35225  
    66
    77    public function test_post_link() {
    8         $post_id = $this->factory->post->create();
     8        $post_id = self::$factory->post->create();
    99
    1010        $link = get_post_comments_feed_link( $post_id );
     
    2020        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    2121
    22         $post_id = $this->factory->post->create();
     22        $post_id = self::$factory->post->create();
    2323
    2424        $link = get_post_comments_feed_link( $post_id );
     
    2929
    3030    public function test_attachment_link() {
    31         $post_id = $this->factory->post->create();
    32         $attachment_id = $this->factory->attachment->create_object( 'image.jpg', $post_id, array(
     31        $post_id = self::$factory->post->create();
     32        $attachment_id = self::$factory->attachment->create_object( 'image.jpg', $post_id, array(
    3333            'post_mime_type' => 'image/jpeg',
    3434            'post_type' => 'attachment'
     
    4747        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    4848
    49         $post_id = $this->factory->post->create( array(
     49        $post_id = self::$factory->post->create( array(
    5050            'post_status' => 'publish'
    5151        ) );
    52         $attachment_id = $this->factory->attachment->create_object( 'image.jpg', $post_id, array(
     52        $attachment_id = self::$factory->attachment->create_object( 'image.jpg', $post_id, array(
    5353            'post_mime_type' => 'image/jpeg',
    5454            'post_type' => 'attachment',
     
    6767        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    6868
    69         $post_id = $this->factory->post->create();
    70         $attachment_id = $this->factory->attachment->create_object( 'image.jpg', $post_id, array(
     69        $post_id = self::$factory->post->create();
     70        $attachment_id = self::$factory->attachment->create_object( 'image.jpg', $post_id, array(
    7171            'post_mime_type' => 'image/jpeg',
    7272            'post_type' => 'attachment'
     
    8080
    8181    public function test_unattached_link() {
    82         $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array(
     82        $attachment_id = self::$factory->attachment->create_object( 'image.jpg', 0, array(
    8383            'post_mime_type' => 'image/jpeg',
    8484            'post_type' => 'attachment'
     
    9797        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    9898
    99         $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array(
     99        $attachment_id = self::$factory->attachment->create_object( 'image.jpg', 0, array(
    100100            'post_mime_type' => 'image/jpeg',
    101101            'post_type' => 'attachment'
Note: See TracChangeset for help on using the changeset viewer.