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

    r34161 r35225  
    1616
    1717    public function test_wp_count_comments_approved() {
    18         $this->factory->comment->create( array(
     18        self::$factory->comment->create( array(
    1919            'comment_approved' => 1
    2020        ) );
     
    3232
    3333    public function test_wp_count_comments_awaiting() {
    34         $this->factory->comment->create( array(
     34        self::$factory->comment->create( array(
    3535            'comment_approved' => 0
    3636        ) );
     
    4848
    4949    public function test_wp_count_comments_spam() {
    50         $this->factory->comment->create( array(
     50        self::$factory->comment->create( array(
    5151            'comment_approved' => 'spam'
    5252        ) );
     
    6464
    6565    public function test_wp_count_comments_trash() {
    66         $this->factory->comment->create( array(
     66        self::$factory->comment->create( array(
    6767            'comment_approved' => 'trash'
    6868        ) );
     
    8080
    8181    public function test_wp_count_comments_post_trashed() {
    82         $this->factory->comment->create( array(
     82        self::$factory->comment->create( array(
    8383            'comment_approved' => 'post-trashed'
    8484        ) );
     
    9696
    9797    public function test_wp_count_comments_cache() {
    98         $post_id = $this->factory->post->create( array(
     98        $post_id = self::$factory->post->create( array(
    9999            'post_status' => 'publish'
    100100        ) );
    101         $comment_id = $this->factory->comment->create( array(
     101        $comment_id = self::$factory->comment->create( array(
    102102            'comment_approved' => '1',
    103103            'comment_post_ID' => $post_id
Note: See TracChangeset for help on using the changeset viewer.